* emultempl/elf32.em (_place_orphan): If an input section doesn't
authorDJ Delorie <dj@redhat.com>
Thu, 14 Jan 2010 04:56:12 +0000 (04:56 +0000)
committerDJ Delorie <dj@redhat.com>
Thu, 14 Jan 2010 04:56:12 +0000 (04:56 +0000)
match an existing output section, but an unused output section
statement does match, use it.
* emultempl/pe.em (_place_orphan): Likewise.
* emultempl/pep.em (_place_orphan): Likewise.

* ld-elf/orphan4.d: New.
* ld-elf/orphan4.ld: New.
* ld-elf/orphan4.s: New.

ld/ChangeLog
ld/emultempl/elf32.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/orphan4.d [new file with mode: 0644]
ld/testsuite/ld-elf/orphan4.ld [new file with mode: 0644]
ld/testsuite/ld-elf/orphan4.s [new file with mode: 0644]

index dcdd4af75c8645ce370db13197d7521a66c8155b..a0094809b4fc24395b63088ada144ecc449fc460 100644 (file)
@@ -1,3 +1,11 @@
+2010-01-13  DJ Delorie  <dj@redhat.com>
+
+       * emultempl/elf32.em (_place_orphan): If an input section doesn't
+       match an existing output section, but an unused output section
+       statement does match, use it.
+       * emultempl/pe.em (_place_orphan): Likewise.
+       * emultempl/pep.em (_place_orphan): Likewise.
+
 2010-01-09  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * configure: Regenerate.
index 7215ff07fa957d17885fe67812944d93ecc8b4b9..4fea6a95b9156cea38caaf379725e10c5f5e5bbd 100644 (file)
@@ -1782,6 +1782,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
   struct orphan_save *place;
   lang_output_section_statement_type *after;
   lang_output_section_statement_type *os;
+  lang_output_section_statement_type *match_by_name = NULL;
   int isdyn = 0;
   int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
   unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
@@ -1837,8 +1838,21 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
            lang_add_section (&os->children, s, os);
            return os;
          }
+
+       /* Save unused output sections in case we can match them
+          against orphans later.  */
+       if (os->bfd_section == NULL)
+         match_by_name = os;
       }
 
+  /* If we didn't match an active output section, see if we matched an
+     unused one and use that.  */
+  if (match_by_name)
+    {
+      lang_add_section (&match_by_name->children, s, match_by_name);
+      return match_by_name;
+    }
+
   if (!orphan_init_done)
     {
       lang_output_section_statement_type *lookup;
index b936199e10722baf5c756eeefd4a8e4cbea7e1b4..79b30d3299628582533fd9501dbf677e97390799 100644 (file)
@@ -1816,6 +1816,7 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
   char *dollar = NULL;
   lang_output_section_statement_type *os;
   lang_statement_list_type add_child;
+  lang_output_section_statement_type *match_by_name = NULL;
   lang_statement_union_type **pl;
 
   /* Look through the script to see where to place this section.  */
@@ -1854,8 +1855,21 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
            lang_add_section (&add_child, s, os);
            break;
          }
+
+       /* Save unused output sections in case we can match them
+          against orphans later.  */
+       if (os->bfd_section == NULL)
+         match_by_name = os;
       }
 
+  /* If we didn't match an active output section, see if we matched an
+     unused one and use that.  */
+  if (os == NULL && match_by_name)
+    {
+      lang_add_section (&match_by_name->children, s, match_by_name);
+      return match_by_name;
+    }
+
   if (os == NULL)
     {
       static struct orphan_save hold[] =
index 753f4252d1690b470315fcc56ecfbee666a2b454..bcc959e95d4954e02e5e269ed858e27642ae9a78 100644 (file)
@@ -1582,6 +1582,7 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
   char *dollar = NULL;
   lang_output_section_statement_type *os;
   lang_statement_list_type add_child;
+  lang_output_section_statement_type *match_by_name = NULL;
   lang_statement_union_type **pl;
 
   /* Look through the script to see where to place this section.  */
@@ -1620,8 +1621,21 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
            lang_add_section (&add_child, s, os);
            break;
          }
+
+       /* Save unused output sections in case we can match them
+          against orphans later.  */
+       if (os->bfd_section == NULL)
+         match_by_name = os;
       }
 
+  /* If we didn't match an active output section, see if we matched an
+     unused one and use that.  */
+  if (os == NULL && match_by_name)
+    {
+      lang_add_section (&match_by_name->children, s, match_by_name);
+      return match_by_name;
+    }
+
   if (os == NULL)
     {
       static struct orphan_save hold[] =
index 414df4e15e4ec43b1ba278ac6313ad0e44a2fe91..a0aa58a9bc65414eb19faa66d778fc9a8dcf5327 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-13  DJ Delorie  <dj@redhat.com>
+
+       * ld-elf/orphan4.d: New.
+       * ld-elf/orphan4.ld: New.
+       * ld-elf/orphan4.s: New.
+
 2010-01-13  Chao-ying Fu  <fu@mips.com>
 
        * ld-mips-elf/jr-to-b-1.d, ld-mips-elf/jr-to-b-2.d: New tests.
diff --git a/ld/testsuite/ld-elf/orphan4.d b/ld/testsuite/ld-elf/orphan4.d
new file mode 100644 (file)
index 0000000..85ebf64
--- /dev/null
@@ -0,0 +1,7 @@
+#source: orphan4.s
+#ld: -T orphan4.ld
+#objdump: -h
+
+#...
+  1 \.foo          00000001  00001000  00001000  00000080  2\*\*0
+#pass
diff --git a/ld/testsuite/ld-elf/orphan4.ld b/ld/testsuite/ld-elf/orphan4.ld
new file mode 100644 (file)
index 0000000..ab9bc9c
--- /dev/null
@@ -0,0 +1,13 @@
+/* The .foo section doesn't specify *any* objects, but the object
+   we're linking has sections named ".foo".  Make sure these sections
+   are linked into the .foo output section anyway.  The bug that was
+   fixed was that a new .foo output section would be created at
+   address 0.  */
+
+SECTIONS {
+       .foo  0x00001000 : {
+       }
+       .text 0x00002000 : {
+               *(.text);
+       }
+}
diff --git a/ld/testsuite/ld-elf/orphan4.s b/ld/testsuite/ld-elf/orphan4.s
new file mode 100644 (file)
index 0000000..1f07646
--- /dev/null
@@ -0,0 +1,4 @@
+       .section ".foo", "ax"
+       .byte   45
+       .text
+       .byte   15