orphan section logic

DJ Delorie dj@redhat.com
Thu Jan 14 04:57:00 GMT 2010


Committed as follows:

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.

Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.207
diff -p -U3 -r1.207  ld/emultempl/elf32.em
--- ld/emultempl/elf32.em	11 Dec 2009 13:42:15 -0000	1.207
+++ ld/emultempl/elf32.em	14 Jan 2010 04:52:45 -0000
@@ -1782,6 +1782,7 @@ gld${EMULATION_NAME}_place_orphan (asect
   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 (asect
 	    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: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.155
diff -p -U3 -r1.155  ld/emultempl/pe.em
--- ld/emultempl/pe.em	15 Nov 2009 07:52:44 -0000	1.155
+++ ld/emultempl/pe.em	14 Jan 2010 04:52:45 -0000
@@ -1816,6 +1816,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
   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 (asec
 	    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: ld/emultempl/pep.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pep.em,v
retrieving revision 1.32
diff -p -U3 -r1.32  ld/emultempl/pep.em
--- ld/emultempl/pep.em	15 Nov 2009 07:52:44 -0000	1.32
+++ ld/emultempl/pep.em	14 Jan 2010 04:52:46 -0000
@@ -1582,6 +1582,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
   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 (asec
 	    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[] =


2010-01-13  DJ Delorie  <dj@redhat.com>

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

Index: ld/testsuite/ld-elf/orphan4.d
===================================================================
RCS file: ld/testsuite/ld-elf/orphan4.d
diff -N  ld/testsuite/ld-elf/orphan4.d
--- ld/testsuite/ld-elf/orphan4.d	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/orphan4.d	14 Jan 2010 04:52:46 -0000
@@ -0,0 +1,7 @@
+#source: orphan4.s
+#ld: -T orphan4.ld
+#objdump: -h
+
+#...
+  1 \.foo          00000001  00001000  00001000  00000080  2\*\*0
+#pass
Index: ld/testsuite/ld-elf/orphan4.ld
===================================================================
RCS file: ld/testsuite/ld-elf/orphan4.ld
diff -N  ld/testsuite/ld-elf/orphan4.ld
--- ld/testsuite/ld-elf/orphan4.ld	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/orphan4.ld	14 Jan 2010 04:52:46 -0000
@@ -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);
+	}
+}
Index: ld/testsuite/ld-elf/orphan4.s
===================================================================
RCS file: ld/testsuite/ld-elf/orphan4.s
diff -N  ld/testsuite/ld-elf/orphan4.s
--- ld/testsuite/ld-elf/orphan4.s	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/orphan4.s	14 Jan 2010 04:52:46 -0000
@@ -0,0 +1,4 @@
+	.section ".foo", "ax"
+	.byte	45
+	.text
+	.byte	15



More information about the Binutils mailing list