Set SEC_KEEP on section XXX for undefined __start_XXX/__stop_XXX
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 8 Jan 2010 01:43:23 +0000 (01:43 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 8 Jan 2010 01:43:23 +0000 (01:43 +0000)
bfd/

2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11133
* elflink.c (_bfd_elf_gc_mark_hook): Check section XXX for
undefined __start_XXX/__stop_XXX in all input files and set
SEC_KEEP.

ld/testsuite/

2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11133
* ld-gc/gc.exp: Run start.

* ld-gc/start.d: New.
* ld-gc/start.s: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-gc/start.d [new file with mode: 0644]
ld/testsuite/ld-gc/start.s [new file with mode: 0644]

index 01950b4fc0e752bf0386e76a62e38483e627e656..0f2e0e4dc14bbeb7cb9da22f1fb0a4d9ac883ace 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11133
+       * elflink.c (_bfd_elf_gc_mark_hook): Check section XXX for
+       undefined __start_XXX/__stop_XXX in all input files and set
+       SEC_KEEP.
+
 2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/11143
index 284bff14d7a73ee6bd4d35c426c921032f24e2d2..f9f804de739dcf0ffefbd18cac767f036bc50222 100644 (file)
@@ -11331,6 +11331,8 @@ _bfd_elf_gc_mark_hook (asection *sec,
                       struct elf_link_hash_entry *h,
                       Elf_Internal_Sym *sym)
 {
+  const char *sec_name;
+
   if (h != NULL)
     {
       switch (h->root.type)
@@ -11342,6 +11344,33 @@ _bfd_elf_gc_mark_hook (asection *sec,
        case bfd_link_hash_common:
          return h->root.u.c.p->section;
 
+       case bfd_link_hash_undefined:
+       case bfd_link_hash_undefweak:
+         /* To work around a glibc bug, keep all XXX input sections
+            when there is an as yet undefined reference to __start_XXX
+            or __stop_XXX symbols.  The linker will later define such
+            symbols for orphan input sections that have a name
+            representable as a C identifier.  */
+         if (strncmp (h->root.root.string, "__start_", 8) == 0)
+           sec_name = h->root.root.string + 8;
+         else if (strncmp (h->root.root.string, "__stop_", 7) == 0)
+           sec_name = h->root.root.string + 7;
+         else
+           sec_name = NULL;
+
+         if (sec_name && *sec_name != '\0')
+           {
+             bfd *i;
+             
+             for (i = info->input_bfds; i; i = i->link_next)
+               {
+                 sec = bfd_get_section_by_name (i, sec_name);
+                 if (sec)
+                   sec->flags |= SEC_KEEP;
+               }
+           }
+         break;
+
        default:
          break;
        }
index 3320c13dbb8faa9c7344c0475dfd82d38fb3e6c5..220a6d9160c9c1c7563416b6acd5e18e1d34cb4c 100644 (file)
@@ -1,3 +1,11 @@
+2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11133
+       * ld-gc/gc.exp: Run start.
+
+       * ld-gc/start.d: New.
+       * ld-gc/start.s: Likewise.
+
 2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/11143
index 36df2338ebdec81e22c418359de84d5f7af624cf..c271a3d25457e0b042f9ed8ba7b613ebadefa03f 100644 (file)
@@ -91,3 +91,4 @@ test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
 
 run_dump_test "noent"
 run_dump_test "abi-note"
+run_dump_test "start"
diff --git a/ld/testsuite/ld-gc/start.d b/ld/testsuite/ld-gc/start.d
new file mode 100644 (file)
index 0000000..a6f748f
--- /dev/null
@@ -0,0 +1,8 @@
+#name: --gc-sections with __start_
+#ld: --gc-sections -e _start
+#nm: -n
+#target: *-*-linux*
+
+#...
+[0-9a-f]+ A +__start__foo
+#...
diff --git a/ld/testsuite/ld-gc/start.s b/ld/testsuite/ld-gc/start.s
new file mode 100644 (file)
index 0000000..d9f1b2d
--- /dev/null
@@ -0,0 +1,6 @@
+.globl _start
+_start:
+       .long __start__foo
+       .section        _foo,"aw",%progbits
+foo:
+       .long   1