aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2009-05-15 14:22:36 +0000
committerAlan Modra <amodra@gmail.com>2009-05-15 14:22:36 +0000
commitd127ecce68b9052033148696008a8a905f661301 (patch)
treec4b31acc130ee14648913fb99d0a280de36dcb3c /ld/emultempl
parent0643c12ee1f4e258e1efea52d46b4c4e67fc8f78 (diff)
downloadgdb-d127ecce68b9052033148696008a8a905f661301.zip
gdb-d127ecce68b9052033148696008a8a905f661301.tar.gz
gdb-d127ecce68b9052033148696008a8a905f661301.tar.bz2
ld/
* ldlang.c (lang_output_section_statement_lookup): Add function comment. Make "name" non-const. Ensure duplicate entries use the same string, allowing simple comparison in hash bucket loop. Tweak constraint check. (next_matching_output_section_statement): New function. * ldlang.h (lang_output_section_statement_lookup): Update. (next_matching_output_section_statement): Declare. * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Don't combine orphan sections when input sections flags differ in alloc or load. * emultempl/pe.em: Formatting throughout. (gld${EMULATION_NAME}_place_orphan): As for elf32.em. * emultempl/pep.em: Formatting throughout. (gld${EMULATION_NAME}_place_orphan): As for elf32.em. ld/testsuite/ * ld-elf/orphan3.d, * ld-elf/orphan3a.s, * ld-elf/orphan3b.s, * ld-elf/orphan3c.s, * ld-elf/orphan3d.s, * ld-elf/orphan3e.s, * ld-elf/orphan3f.s: New test. * ld-pe/orphan.d, * ld-pe/orphana.s, * ld-pe/orphanb.s, * ld-pe/orphand.s, * ld-pe/orphane.s: New test. * ld-pe/direct.exp: Use is_pecoff_format. * ld-pe/longsecn.exp: Delete. * ld-pe/pe.exp: Run new test and longsecn tests.
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/elf32.em43
-rw-r--r--ld/emultempl/pe.em79
-rw-r--r--ld/emultempl/pep.em62
3 files changed, 113 insertions, 71 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index bb299d9..2d7a88d 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1712,23 +1712,32 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
}
/* Look through the script to see where to place this section. */
- if (constraint == 0
- && (os = lang_output_section_find (secname)) != NULL
- && os->bfd_section != NULL
- && (os->bfd_section->flags == 0
- || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
- os->bfd_section, s->owner, s)
- && ((s->flags ^ os->bfd_section->flags)
- & (SEC_LOAD | SEC_ALLOC)) == 0)))
- {
- /* We already have an output section statement with this
- name, and its bfd section has compatible flags.
- If the section already exists but does not have any flags
- set, then it has been created by the linker, probably as a
- result of a --section-start command line switch. */
- lang_add_section (&os->children, s, os);
- return os;
- }
+ if (constraint == 0)
+ for (os = lang_output_section_find (secname);
+ os != NULL;
+ os = next_matching_output_section_statement (os, 0))
+ {
+ /* If we don't match an existing output section, tell
+ lang_insert_orphan to create a new output section. */
+ constraint = SPECIAL;
+
+ if (os->bfd_section != NULL
+ && (os->bfd_section->flags == 0
+ || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
+ os->bfd_section,
+ s->owner, s)
+ && ((s->flags ^ os->bfd_section->flags)
+ & (SEC_LOAD | SEC_ALLOC)) == 0)))
+ {
+ /* We already have an output section statement with this
+ name, and its bfd section has compatible flags.
+ If the section already exists but does not have any flags
+ set, then it has been created by the linker, probably as a
+ result of a --section-start command line switch. */
+ lang_add_section (&os->children, s, os);
+ return os;
+ }
+ }
if (!orphan_init_done)
{
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 30f8619..2437bfb 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -242,9 +242,12 @@ fragment <<EOF
static void
gld${EMULATION_NAME}_add_options
- (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
- struct option **longopts, int nrl ATTRIBUTE_UNUSED,
- struct option **really_longopts ATTRIBUTE_UNUSED)
+ (int ns ATTRIBUTE_UNUSED,
+ char **shortopts ATTRIBUTE_UNUSED,
+ int nl,
+ struct option **longopts,
+ int nrl ATTRIBUTE_UNUSED,
+ struct option **really_longopts ATTRIBUTE_UNUSED)
{
static const struct option xtra_long[] = {
/* PE options */
@@ -267,8 +270,8 @@ gld${EMULATION_NAME}_add_options
{"use-nul-prefixed-import-tables", no_argument, NULL,
OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
#ifdef DLL_SUPPORT
- /* getopt allows abbreviations, so we do this to stop it from treating -o
- as an abbreviation for this option */
+ /* getopt allows abbreviations, so we do this to stop it
+ from treating -o as an abbreviation for this option. */
{"output-def", required_argument, NULL, OPTION_OUT_DEF},
{"output-def", required_argument, NULL, OPTION_OUT_DEF},
{"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
@@ -311,8 +314,8 @@ gld${EMULATION_NAME}_add_options
{NULL, no_argument, NULL, 0}
};
- *longopts = (struct option *)
- xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+ *longopts
+ = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
}
@@ -819,12 +822,15 @@ gld_${EMULATION_NAME}_set_symbols (void)
if (link_info.relocatable)
init[IMAGEBASEOFF].value = 0;
else if (init[DLLOFF].value || (link_info.shared && !link_info.pie))
+ {
#ifdef DLL_SUPPORT
- init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?
- compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
+ init[IMAGEBASEOFF].value = (pe_enable_auto_image_base
+ ? compute_dll_image_base (output_filename)
+ : NT_DLL_IMAGE_BASE);
#else
- init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
+ init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
#endif
+ }
else
init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
@@ -859,8 +865,7 @@ gld_${EMULATION_NAME}_set_symbols (void)
/* Restore the pointer. */
pop_stat_ptr ();
- if (pe.FileAlignment >
- pe.SectionAlignment)
+ if (pe.FileAlignment > pe.SectionAlignment)
{
einfo (_("%P: warning, file alignment > section alignment.\n"));
}
@@ -1266,7 +1271,7 @@ gld_${EMULATION_NAME}_after_open (void)
}
symbols = bfd_get_outsymbols (is->the_bfd);
- relocs = (arelent **) xmalloc ((size_t) relsize);
+ relocs = xmalloc ((size_t) relsize);
nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
relocs, symbols);
if (nrelocs < 0)
@@ -1581,7 +1586,7 @@ gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIB
buflen = len + 2;
}
- buf = (char *) xmalloc (buflen);
+ buf = xmalloc (buflen);
for (i = 0; i < pe_def_file->num_exports; i++)
{
@@ -1716,7 +1721,7 @@ gld_${EMULATION_NAME}_finish (void)
#ifdef DLL_SUPPORT
if (link_info.shared
#if !defined(TARGET_IS_shpe) && !defined(TARGET_IS_mipspe)
- || (!link_info.relocatable && pe_def_file->num_exports != 0)
+ || (!link_info.relocatable && pe_def_file->num_exports != 0)
#endif
)
{
@@ -1786,21 +1791,32 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
lang_list_init (&add_child);
- if (constraint == 0
- && (os = lang_output_section_find (secname)) != NULL
- && os->bfd_section != NULL
- && (os->bfd_section->flags == 0
- || ((s->flags ^ os->bfd_section->flags)
- & (SEC_LOAD | SEC_ALLOC)) == 0))
- {
- /* We already have an output section statement with this
- name, and its bfd section has compatible flags.
- If the section already exists but does not have any flags set,
- then it has been created by the linker, probably as a result of
- a --section-start command line switch. */
- lang_add_section (&add_child, s, os);
- }
- else
+ os = NULL;
+ if (constraint == 0)
+ for (os = lang_output_section_find (secname);
+ os != NULL;
+ os = next_matching_output_section_statement (os, 0))
+ {
+ /* If we don't match an existing output section, tell
+ lang_insert_orphan to create a new output section. */
+ constraint = SPECIAL;
+
+ if (os->bfd_section != NULL
+ && (os->bfd_section->flags == 0
+ || ((s->flags ^ os->bfd_section->flags)
+ & (SEC_LOAD | SEC_ALLOC)) == 0))
+ {
+ /* We already have an output section statement with this
+ name, and its bfd section has compatible flags.
+ If the section already exists but does not have any flags set,
+ then it has been created by the linker, probably as a result of
+ a --section-start command line switch. */
+ lang_add_section (&add_child, s, os);
+ break;
+ }
+ }
+
+ if (os == NULL)
{
static struct orphan_save hold[] =
{
@@ -1906,7 +1922,8 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
static bfd_boolean
gld_${EMULATION_NAME}_open_dynamic_archive
- (const char *arch ATTRIBUTE_UNUSED, search_dirs_type *search,
+ (const char *arch ATTRIBUTE_UNUSED,
+ search_dirs_type *search,
lang_input_statement_type *entry)
{
static const struct
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index f855618..e4519c5 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -260,10 +260,12 @@ gld${EMULATION_NAME}_add_options
{"no-seh", no_argument, NULL, OPTION_NO_SEH},
{"no-bind", no_argument, NULL, OPTION_NO_BIND},
{"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
- {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE}, {NULL, no_argument, NULL, 0}
+ {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
+ {NULL, no_argument, NULL, 0}
};
- *longopts = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+ *longopts
+ = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
}
@@ -370,7 +372,7 @@ gld_${EMULATION_NAME}_list_options (FILE *file)
fprintf (file, _(" --no-isolation Image understands isolation but do not isolate the image\n"));
fprintf (file, _(" --no-seh Image does not use SEH. No SE handler may\n\
be called in this image\n"));
- fprintf (file, _(" --no-bind Do not bind this image\n"));
+ fprintf (file, _(" --no-bind Do not bind this image\n"));
fprintf (file, _(" --wdmdriver Driver uses the WDM model\n"));
fprintf (file, _(" --tsaware Image is Terminal Server aware\n"));
#endif
@@ -757,15 +759,18 @@ gld_${EMULATION_NAME}_set_symbols (void)
if (link_info.relocatable)
init[IMAGEBASEOFF].value = 0;
else if (init[DLLOFF].value || (link_info.shared && !link_info.pie))
+ {
#ifdef DLL_SUPPORT
- init[IMAGEBASEOFF].value = (pep_enable_auto_image_base) ?
- compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
+ init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
+ ? compute_dll_image_base (output_filename)
+ : NT_DLL_IMAGE_BASE);
#else
- init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
+ init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
#endif
+ }
else
init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
- init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
+ init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
}
/* Don't do any symbol assignments if this is a relocatable link. */
@@ -1057,7 +1062,7 @@ This should work unless it involves constant data structures referencing symbols
}
pep_walk_relocs_of_symbol (&link_info, undef->root.string,
- make_import_fixup);
+ make_import_fixup);
/* Let's differentiate it somehow from defined. */
undef->type = bfd_link_hash_defweak;
@@ -1561,21 +1566,32 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
lang_list_init (&add_child);
- if (constraint == 0
- && (os = lang_output_section_find (secname)) != NULL
- && os->bfd_section != NULL
- && (os->bfd_section->flags == 0
- || ((s->flags ^ os->bfd_section->flags)
- & (SEC_LOAD | SEC_ALLOC)) == 0))
- {
- /* We already have an output section statement with this
- name, and its bfd section has compatible flags.
- If the section already exists but does not have any flags set,
- then it has been created by the linker, probably as a result of
- a --section-start command line switch. */
- lang_add_section (&add_child, s, os);
- }
- else
+ os = NULL;
+ if (constraint == 0)
+ for (os = lang_output_section_find (secname);
+ os != NULL;
+ os = next_matching_output_section_statement (os, 0))
+ {
+ /* If we don't match an existing output section, tell
+ lang_insert_orphan to create a new output section. */
+ constraint = SPECIAL;
+
+ if (os->bfd_section != NULL
+ && (os->bfd_section->flags == 0
+ || ((s->flags ^ os->bfd_section->flags)
+ & (SEC_LOAD | SEC_ALLOC)) == 0))
+ {
+ /* We already have an output section statement with this
+ name, and its bfd section has compatible flags.
+ If the section already exists but does not have any flags set,
+ then it has been created by the linker, probably as a result of
+ a --section-start command line switch. */
+ lang_add_section (&add_child, s, os);
+ break;
+ }
+ }
+
+ if (os == NULL)
{
static struct orphan_save hold[] =
{