+2009-05-15 Alan Modra <amodra@bigpond.net.au>
+
+ * 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.
+
2009-05-14 Ulrich Weigand <uweigand@de.ibm.com>
* emultempl/spuelf.em (PARSE_AND_LIST_ARGS_CASES): Always use
}
/* 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)
{
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 */
{"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},
{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));
}
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;
/* Restore the pointer. */
pop_stat_ptr ();
- if (pe.FileAlignment >
- pe.SectionAlignment)
+ if (pe.FileAlignment > pe.SectionAlignment)
{
einfo (_("%P: warning, file alignment > section alignment.\n"));
}
}
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)
buflen = len + 2;
}
- buf = (char *) xmalloc (buflen);
+ buf = xmalloc (buflen);
for (i = 0; i < pe_def_file->num_exports; i++)
{
#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
)
{
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[] =
{
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
{"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));
}
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
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. */
}
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;
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[] =
{
return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE);
}
+/* Find or create an output_section_statement with the given NAME.
+ If CONSTRAINT is non-zero match one with that constraint, otherwise
+ match any non-negative constraint. If CREATE, always make a
+ new output_section_statement for SPECIAL CONSTRAINT. */
+
lang_output_section_statement_type *
-lang_output_section_statement_lookup (const char *const name,
+lang_output_section_statement_lookup (const char *name,
int constraint,
bfd_boolean create)
{
/* We have a section of this name, but it might not have the correct
constraint. */
struct out_section_hash_entry *last_ent;
- unsigned long hash = entry->root.hash;
+ name = entry->s.output_section_statement.name;
if (create && constraint == SPECIAL)
/* Not traversing to the end reverses the order of the second
and subsequent SPECIAL sections in the hash table chain,
else
do
{
- if (entry->s.output_section_statement.constraint >= 0
- && (constraint == 0
- || (constraint
- == entry->s.output_section_statement.constraint)))
+ if (constraint == entry->s.output_section_statement.constraint
+ || (constraint == 0
+ && entry->s.output_section_statement.constraint >= 0))
return &entry->s.output_section_statement;
last_ent = entry;
entry = (struct out_section_hash_entry *) entry->root.next;
}
while (entry != NULL
- && entry->root.hash == hash
- && strcmp (name, entry->s.output_section_statement.name) == 0);
+ && name == entry->s.output_section_statement.name);
if (!create)
return NULL;
return &entry->s.output_section_statement;
}
+/* Find the next output_section_statement with the same name as OS.
+ If CONSTRAINT is non-zero, find one with that constraint otherwise
+ match any non-negative constraint. */
+
+lang_output_section_statement_type *
+next_matching_output_section_statement (lang_output_section_statement_type *os,
+ int constraint)
+{
+ /* All output_section_statements are actually part of a
+ struct out_section_hash_entry. */
+ struct out_section_hash_entry *entry = (struct out_section_hash_entry *)
+ ((char *) os
+ - offsetof (struct out_section_hash_entry, s.output_section_statement));
+ const char *name = os->name;
+
+ ASSERT (name == entry->root.string);
+ do
+ {
+ entry = (struct out_section_hash_entry *) entry->root.next;
+ if (entry == NULL
+ || name != entry->s.output_section_statement.name)
+ return NULL;
+ }
+ while (constraint != entry->s.output_section_statement.constraint
+ && (constraint != 0
+ || entry->s.output_section_statement.constraint < 0));
+
+ return &entry->s.output_section_statement;
+}
+
/* A variant of lang_output_section_find used by place_orphan.
Returns the output statement that should precede a new output
statement for SEC. If an exact match is found on certain flags,
extern void lang_add_keepsyms_file
(const char *);
extern lang_output_section_statement_type *lang_output_section_statement_lookup
- (const char *const, int, bfd_boolean);
+ (const char *, int, bfd_boolean);
+extern lang_output_section_statement_type *next_matching_output_section_statement
+ (lang_output_section_statement_type *, int);
extern void ldlang_add_undef
(const char *const);
extern void lang_add_output_format
+2009-05-15 Alan Modra <amodra@bigpond.net.au>
+
+ * 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.
+
2009-05-15 Andrew Stubbs <ams@codesourcery.com>
Paul Brook <paul@codesourcery.com>
--- /dev/null
+#source: orphan3a.s
+#source: orphan3b.s
+#source: orphan3c.s
+#source: orphan3d.s
+#source: orphan3e.s
+#source: orphan3f.s
+#ld:
+#readelf: -S --wide
+#xfail: "arc-*-*" "d30v-*-*" "dlx-*-*" "fr30-*-*" "frv-*-*"
+#xfail: "i860-*-*" "i960-*-*" "iq2000-*-*" "mn10200-*-*" "msp430-*-*" "mt-*-*"
+#xfail: "or32-*-*" "pj-*-*"
+#xfail: "cr16-*-*" "crx-*-*" "d10v-*-*" "xstormy16-*-*"
+
+#...
+ \[[ 0-9]+\] \.foo +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +0+ +A +0 +0 +[0-9]+
+#...
+ \[[ 0-9]+\] \.foo +NOBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +0+ +A +0 +0 +[0-9]+
+#...
+ \[[ 0-9]+\] \.foo +PROGBITS +0+ +[0-9a-f]+ +0+8 +0+ +0 +0 +[0-9]+
+ \[[ 0-9]+\] \.[^f].*
+#pass
--- /dev/null
+ .globl main
+ .globl start
+ .globl _start
+ .globl __start
+ .text
+main:
+start:
+_start:
+__start:
+
+ .section .foo,"a",%nobits
+ .space 4
--- /dev/null
+ .section .foo,"a",%progbits
+ .long 1
--- /dev/null
+ .section .foo,"",%progbits
+ .long 2
--- /dev/null
+ .section .foo,"a",%nobits
+ .space 4
--- /dev/null
+ .section .foo,"a",%progbits
+ .long 4
--- /dev/null
+ .section .foo,"",%progbits
+ .long 5
# 7. run the produced executables
# This test can only be run on PE/COFF platforms.
-if { ![istarget *-*-cygwin*]
- && ![istarget *-*-mingw*]
- && ![istarget *-*-pe] } {
+if {![is_pecoff_format]} {
return
}
+++ /dev/null
-# Expect script for COFF long section name tests
-# Copyright 2009
-# Free Software Foundation, Inc.
-#
-# This file is part of the GNU Binutils.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-# MA 02110-1301, USA.
-#
-
-# This test can only be run on PE/COFF platforms.
-if {![is_pecoff_format]} {
- return
-}
-
-run_dump_test "longsecn"
-
-run_dump_test "longsecn-1"
-run_dump_test "longsecn-2"
-run_dump_test "longsecn-3"
-run_dump_test "longsecn-4"
-run_dump_test "longsecn-5"
-
--- /dev/null
+#source: orphana.s
+#source: orphanb.s
+#source: orphand.s
+#source: orphane.s
+#ld: --file-align 1 --section-align 1
+#objdump: -h --wide
+
+#...
+ +0 +\.text .*
+ +1 +\.foo +0+8 .*
+ +2 +\.foo +0+8 .*
+ +3 +\.idata .*
+#pass
--- /dev/null
+ .globl _mainCRTStartup
+ .globl _start
+ .text
+_mainCRTStartup:
+_start:
+
+ .section .foo,"b"
+ .space 4
--- /dev/null
+ .section .foo
+ .long 1
--- /dev/null
+ .section .foo,"b"
+ .space 4
--- /dev/null
+ .section .foo
+ .long 4
-# Expect script for export table in executables tests\r
-# Copyright 2004, 2006, 2007\r
-# Free Software Foundation, Inc.\r
-#\r
-# This file is part of the GNU Binutils.\r
-#\r
-# This program is free software; you can redistribute it and/or modify\r
-# it under the terms of the GNU General Public License as published by\r
-# the Free Software Foundation; either version 3 of the License, or\r
-# (at your option) any later version.\r
-#\r
-# This program is distributed in the hope that it will be useful,\r
-# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-# GNU General Public License for more details.\r
-#\r
-# You should have received a copy of the GNU General Public License\r
-# along with this program; if not, write to the Free Software\r
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\r
-# MA 02110-1301, USA.\r
-#\r
- \r
-# This test can only be run on PE/COFF platforms that support .secrel32.\r
-if { ![istarget i*86-*-cygwin*]\r
- && ![istarget i*86-*-pe]\r
- && ![istarget i*86-*-mingw*]\r
- && ![istarget x86_64-*-mingw*]\r
- && ![istarget arm-wince-pe] } {\r
- return\r
-}\r
-\r
-if {[istarget x86_64-*-mingw*] } {\r
- set pe_tests {\r
- {".secrel32" "" "" {secrel1.s secrel2.s}\r
- {{objdump -s secrel_64.d}} "secrel.x"}\r
- }\r
-} elseif {[istarget i*86-*-cygwin*] } {\r
- set pe_tests {\r
- {".secrel32" "--disable-auto-import" "" {secrel1.s secrel2.s}\r
- {{objdump -s secrel.d}} "secrel.x"}\r
- }\r
-} else {\r
- set pe_tests {\r
- {".secrel32" "" "" {secrel1.s secrel2.s}\r
- {{objdump -s secrel.d}} "secrel.x"}\r
- }\r
-}\r
-\r
-run_ld_link_tests $pe_tests\r
-\r
-run_dump_test "image_size"\r
-run_dump_test "export_dynamic_warning"\r
+# Expect script for export table in executables tests
+# Copyright 2004, 2006, 2007
+# Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# These tests can only be run on PE/COFF platforms.
+if {![is_pecoff_format]} {
+ return
+}
+
+# This test can only be run on PE/COFF platforms that support .secrel32.
+if {[istarget i*86-*-cygwin*]
+ || [istarget i*86-*-pe]
+ || [istarget i*86-*-mingw*]
+ || [istarget x86_64-*-mingw*]
+ || [istarget arm-wince-pe] } {
+
+ if {[istarget x86_64-*-mingw*] } {
+ set pe_tests {
+ {".secrel32" "" "" {secrel1.s secrel2.s}
+ {{objdump -s secrel_64.d}} "secrel.x"}
+ }
+ } elseif {[istarget i*86-*-cygwin*] } {
+ set pe_tests {
+ {".secrel32" "--disable-auto-import" "" {secrel1.s secrel2.s}
+ {{objdump -s secrel.d}} "secrel.x"}
+ }
+ } else {
+ set pe_tests {
+ {".secrel32" "" "" {secrel1.s secrel2.s}
+ {{objdump -s secrel.d}} "secrel.x"}
+ }
+ }
+
+ run_ld_link_tests $pe_tests
+}
+
+run_dump_test "image_size"
+run_dump_test "export_dynamic_warning"
+
+run_dump_test "longsecn"
+run_dump_test "longsecn-1"
+run_dump_test "longsecn-2"
+run_dump_test "longsecn-3"
+run_dump_test "longsecn-4"
+run_dump_test "longsecn-5"
+
+run_dump_test "orphan"