+2001-01-14 Alan Modra <alan@linuxcare.com.au>
+
+ * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Don't
+ rummage through the script for sections on the unique list.
+ Correct length of strncmp for ".note".
+ (gld${EMULATION_NAME}_check_needed): Rearrange function.
+
+ * ldlang.c (unique_section_list): New var.
+ (unique_section_p): New function.
+ (walk_wild_section): Don't match sections on unique_section_list.
+ (lang_add_unique): New function.
+
+ * ldlang.h (struct unique_sections): Declare.
+ (unique_section_list): Declare.
+ (unique_section_p): Declare.
+ (lang_add_unique): Declare.
+
+ * lexsup.c (ld_options): Allow --unique to take an optional arg.
+ (parse_args [OPTION_UNIQUE]): Call lang_add_unique.
+
+ * ld.texinfo (--unique): Update.
+
2001-01-13 Nick Clifton <nickc@redhat.com>
* lexsup.c (parse_args): Remove spurious white space.
/* This file is is generated by a shell script. DO NOT EDIT! */
/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
- Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 99, 2000
+ Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
Free Software Foundation, Inc.
Written by Steve Chamberlain <sac@cygnus.com>
ELF support by Ian Lance Taylor <ian@cygnus.com>
if (global_found)
return;
- if (s->filename != NULL
- && strcmp (s->filename, global_needed->name) == 0)
+ if (s->filename != NULL)
{
- global_found = true;
- return;
+ const char *f;
+
+ if (strcmp (s->filename, global_needed->name) == 0)
+ {
+ global_found = true;
+ return;
+ }
+
+ if (s->search_dirs_flag)
+ {
+ f = strrchr (s->filename, '/');
+ if (f != NULL
+ && strcmp (f + 1, global_needed->name) == 0)
+ {
+ global_found = true;
+ return;
+ }
+ }
}
if (s->the_bfd != NULL)
return;
}
}
-
- if (s->search_dirs_flag
- && s->filename != NULL
- && strchr (global_needed->name, '/') == NULL)
- {
- const char *f;
-
- f = strrchr (s->filename, '/');
- if (f != NULL
- && strcmp (f + 1, global_needed->name) == 0)
- {
- global_found = true;
- return;
- }
- }
}
EOF
secname = bfd_get_section_name (s->owner, s);
- if (! config.unique_orphan_sections)
+ if (! config.unique_orphan_sections && ! unique_section_p (secname))
{
/* Look through the script to see where to place this section. */
os = lang_output_section_find (secname);
if ((s->flags & SEC_ALLOC) == 0)
;
else if ((s->flags & SEC_LOAD) != 0
- && strncmp (secname, ".note", 4) == 0
+ && strncmp (secname, ".note", 5) == 0
&& HAVE_SECTION (hold_interp, ".interp"))
place = &hold_interp;
else if ((s->flags & SEC_HAS_CONTENTS) == 0
be added to. Use @samp{-Ur} only for the last partial link, and
@samp{-r} for the others.
-@kindex --unique
-@item --unique
-Creates a separate output section for every orphan input section. This
-option prevents the normal merging of orphan input sections with the same
-name. An orphan section is one not specifically mentioned in a linker
-script, so this option along with a custom linker script allows any
-selection of input sections to be merged while others are kept separate.
+@kindex --unique[=@var{SECTION}]
+@item --unique[=@var{SECTION}]
+Creates a separate output section for every input section matching
+@var{SECTION}, or if the optional wildcard @var{SECTION} argument is
+missing, for every orphan input section. An orphan section is one not
+specifically mentioned in a linker script. You may use this option
+multiple times on the command line; It prevents the normal merging of
+input sections with the same name, overriding output section assignments
+in a linker script.
@kindex -v
@kindex -V
/* Linker command language support.
- Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000
+ Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
Free Software Foundation, Inc.
This file is part of GLD, the Gnu Linker.
boolean lang_float_flag = false;
boolean delete_output_file_on_failure = false;
struct lang_nocrossrefs *nocrossref_list;
+struct unique_sections *unique_section_list;
etree_type *base; /* Relocation base - or null */
return obstack_alloc (&stat_obstack, size);
}
+boolean
+unique_section_p (secnam)
+ const char *secnam;
+{
+ struct unique_sections *unam;
+
+ for (unam = unique_section_list; unam; unam = unam->next)
+ if (wildcardp (unam->name)
+ ? fnmatch (unam->name, secnam, 0) == 0
+ : strcmp (unam->name, secnam) == 0)
+ {
+ return true;
+ }
+
+ return false;
+}
+
/* Generic traversal routines for finding matching sections. */
static void
if (file->just_syms_flag == false)
{
register asection *s;
- boolean wildcard;
+ boolean wildcard = false;
- if (section == NULL)
- wildcard = false;
- else
+ if (section != NULL)
wildcard = wildcardp (section);
for (s = file->the_bfd->sections; s != NULL; s = s->next)
{
boolean match;
+ const char *sname = bfd_get_section_name (file->the_bfd, s);
if (section == NULL)
match = true;
+ else if (wildcard)
+ match = fnmatch (section, sname, 0) == 0 ? true : false;
else
- {
- const char *name;
+ match = strcmp (section, sname) == 0 ? true : false;
- name = bfd_get_section_name (file->the_bfd, s);
- if (wildcard)
- match = fnmatch (section, name, 0) == 0 ? true : false;
- else
- match = strcmp (section, name) == 0 ? true : false;
- }
-
- if (match)
+ /* If this is a wild-card output section statement, exclude
+ sections that match UNIQUE_SECTION_LIST. */
+ if (match && (data == NULL || !unique_section_p (sname)))
(*callback) (ptr, s, file, data);
}
}
if ((flags & SEC_LINK_ONCE) == 0)
return;
- /* FIXME: When doing a relocateable link, we may have trouble
+ /* FIXME: When doing a relocatable link, we may have trouble
copying relocations in other sections that refer to local symbols
in the section being discarded. Those relocations will have to
be converted somehow; as of this writing I'm not sure that any of
the backends handle that correctly.
It is tempting to instead not discard link once sections when
- doing a relocateable link (technically, they should be discarded
+ doing a relocatable link (technically, they should be discarded
whenever we are building constructors). However, that fails,
because the linker winds up combining all the link once sections
into a single large link once section, which defeats the purpose
of having link once sections in the first place.
- Also, not merging link once sections in a relocateable link
+ Also, not merging link once sections in a relocatable link
causes trouble for MIPS ELF, which relies in link once semantics
to handle the .reginfo section correctly. */
lang_register_vers_node (command_line.version_exports_section,
lang_new_vers_node (greg, lreg), NULL);
}
+
+void
+lang_add_unique (name)
+ const char *name;
+{
+ struct unique_sections *ent;
+
+ for (ent = unique_section_list; ent; ent = ent->next)
+ if (strcmp (ent->name, name) == 0)
+ return;
+
+ ent = (struct unique_sections *) xmalloc (sizeof *ent);
+ ent->name = xstrdup (name);
+ ent->next = unique_section_list;
+ unique_section_list = ent;
+}
/* ldlang.h - linker command language support
- Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000
+ Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
Free Software Foundation, Inc.
This file is part of GLD, the Gnu Linker.
extern struct lang_nocrossrefs *nocrossref_list;
+/* This structure is used to hold a list of input section names which
+ will not match an output section in the linker script. */
+
+struct unique_sections {
+ struct unique_sections *next;
+ const char *name;
+};
+
+extern struct unique_sections *unique_section_list;
+
extern lang_output_section_statement_type *abs_output_section;
extern lang_statement_list_type lang_output_section_statement;
extern boolean lang_has_input_file;
extern void lang_register_vers_node
PARAMS ((const char *, struct bfd_elf_version_tree *,
struct bfd_elf_version_deps *));
+boolean unique_section_p PARAMS ((const char *));
+extern void lang_add_unique PARAMS ((const char *));
#endif
'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
{ {"undefined", required_argument, NULL, 'u'},
'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES },
- { {"unique", no_argument, NULL, OPTION_UNIQUE},
- '\0', NULL, N_("Don't merge orphan sections with the same name"), TWO_DASHES },
+ { {"unique", optional_argument, NULL, OPTION_UNIQUE},
+ '\0', N_("[=SECTION]"), N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
{ {"Ur", no_argument, NULL, OPTION_UR},
'\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
{ {"version", no_argument, NULL, OPTION_VERSION},
ldlang_add_undef (optarg);
break;
case OPTION_UNIQUE:
- config.unique_orphan_sections = true;
+ if (optarg != NULL)
+ lang_add_unique (optarg);
+ else
+ config.unique_orphan_sections = true;
break;
case OPTION_VERBOSE:
ldversion (1);