Also hide symbols without PLT nor GOT references.
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 16 Sep 2011 01:17:16 +0000 (01:17 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 16 Sep 2011 01:17:16 +0000 (01:17 +0000)
bfd/

2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/13177
* elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
nor GOT references.

ld/testsuite/

2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/13177
* ld-elf/pr13177.d: New.
* ld-elf/pr13177.s: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/pr13177.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr13177.s [new file with mode: 0644]

index b063de9ac93ec76ab2911b14cf8336195b7ee517..352128984f72ad2c7bf56eddb0676018bc4cd309 100644 (file)
@@ -1,3 +1,9 @@
+2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/13177
+       * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
+       nor GOT references.
+
 2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/12975
index 25601042401a116cdbdd8975f9f59ee6e9356ba6..9ccf37df051d075f24d945f21cf273dada6742bd 100644 (file)
@@ -11689,13 +11689,18 @@ struct elf_gc_sweep_symbol_info
 static bfd_boolean
 elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
 {
-  if ((h->root.type == bfd_link_hash_defined
-       || h->root.type == bfd_link_hash_defweak)
-      && !h->root.u.def.section->gc_mark
-      && !(h->root.u.def.section->owner->flags & DYNAMIC))
+  if (((h->root.type == bfd_link_hash_defined
+       || h->root.type == bfd_link_hash_defweak)
+       && !h->root.u.def.section->gc_mark
+       && (!(h->root.u.def.section->owner->flags & DYNAMIC)
+          || (h->plt.refcount <= 0
+              && h->got.refcount <= 0)))
+      || (h->root.type == bfd_link_hash_undefined
+         && h->plt.refcount <= 0
+         && h->got.refcount <= 0))
     {
       struct elf_gc_sweep_symbol_info *inf =
-          (struct elf_gc_sweep_symbol_info *) data;
+       (struct elf_gc_sweep_symbol_info *) data;
       (*inf->hide_symbol) (inf->info, h, TRUE);
     }
 
index 7a90b261e834bc08ffe3ea0492360d138ee63db7..c5349be6302b20be19b9658d648fac1744560405 100644 (file)
@@ -1,3 +1,9 @@
+2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/13177
+       * ld-elf/pr13177.d: New.
+       * ld-elf/pr13177.s: Likewise.
+
 2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/12975
diff --git a/ld/testsuite/ld-elf/pr13177.d b/ld/testsuite/ld-elf/pr13177.d
new file mode 100644 (file)
index 0000000..425a239
--- /dev/null
@@ -0,0 +1,11 @@
+#source: pr13177.s
+#ld: --gc-sections -shared
+#readelf: -s -D --wide
+#notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+# generic linker targets don't support --gc-sections, nor do a bunch of others
+
+#failif
+#...
+.*: 0+0 +0 +NOTYPE +GLOBAL +DEFAULT +UND bar
+#...
diff --git a/ld/testsuite/ld-elf/pr13177.s b/ld/testsuite/ld-elf/pr13177.s
new file mode 100644 (file)
index 0000000..25232ba
--- /dev/null
@@ -0,0 +1,9 @@
+       .section .text.foo,"ax",%progbits
+       .globl  foo
+       .type   foo, %function
+foo:
+       .byte 0
+       .section .text.opt_out,"ax",%progbits
+       .type   opt_out, %function
+opt_out:
+       .dc.a bar