Ignore dynamic references on forced local symbols
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Jan 2018 23:36:40 +0000 (15:36 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Jan 2018 23:36:54 +0000 (15:36 -0800)
We should ignore dynamic references on forced local symbols during
garbage collection since they can never be referenced dynamically.

bfd/

PR ld/22649
* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Ignore dynamic
references on forced local symbols.

ld/

PR ld/22649
* testsuite/ld-elf/pr22649-1.s: New file.
* testsuite/ld-elf/pr22649-2a.s: Likewise.
* testsuite/ld-elf/pr22649-2b.s: Likewise.
* testsuite/ld-elf/pr22649.msg: Likewise.
* testsuite/ld-elf/shared.exp: Run ld/22649 tests.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/pr22649-1.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr22649-2a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr22649-2b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr22649.msg [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 8f2feae455bc285a097bf54bf577d8609c9244d5..5ceb5a0e661549a62b2be0eb879b18a7702cb80f 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22649
+       * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Ignore dynamic
+       references on forced local symbols.
+
 2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22677
index 4c92a048cea8ebd359c5b5a4f8770061b671e875..e3751fa122cf936a3c277ddd36631a5b0d2647f2 100644 (file)
@@ -13277,7 +13277,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
 
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
-      && (h->ref_dynamic
+      && ((h->ref_dynamic && !h->forced_local)
          || ((h->def_regular || ELF_COMMON_DEF_P (h))
              && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
              && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
index 34fdb1f031d9b5e9eb3121aa38244fdb6aaf5031..977d779d264f63e967eb31e618e58675781c6706 100644 (file)
@@ -1,3 +1,12 @@
+2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22649
+       * testsuite/ld-elf/pr22649-1.s: New file.
+       * testsuite/ld-elf/pr22649-2a.s: Likewise.
+       * testsuite/ld-elf/pr22649-2b.s: Likewise.
+       * testsuite/ld-elf/pr22649.msg: Likewise.
+       * testsuite/ld-elf/shared.exp: Run ld/22649 tests.
+
 2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22677
diff --git a/ld/testsuite/ld-elf/pr22649-1.s b/ld/testsuite/ld-elf/pr22649-1.s
new file mode 100644 (file)
index 0000000..9a7da7e
--- /dev/null
@@ -0,0 +1,4 @@
+       .data
+       .globl foo
+foo:
+       .dc.a bar
diff --git a/ld/testsuite/ld-elf/pr22649-2a.s b/ld/testsuite/ld-elf/pr22649-2a.s
new file mode 100644 (file)
index 0000000..b5908b0
--- /dev/null
@@ -0,0 +1,8 @@
+       .data
+       .hidden foo
+       .hidden bar
+       .globl foo
+       .globl bar
+foo:
+bar:
+       .dc.a foo
diff --git a/ld/testsuite/ld-elf/pr22649-2b.s b/ld/testsuite/ld-elf/pr22649-2b.s
new file mode 100644 (file)
index 0000000..999686c
--- /dev/null
@@ -0,0 +1,7 @@
+       .data
+       .hidden foo
+       .globl foo
+       .globl bar
+foo:
+bar:
+       .dc.a foo
diff --git a/ld/testsuite/ld-elf/pr22649.msg b/ld/testsuite/ld-elf/pr22649.msg
new file mode 100644 (file)
index 0000000..b4e45bd
--- /dev/null
@@ -0,0 +1 @@
+.*: Removing unused section '\.data' in file 'tmpdir/pr22649-2.*\.o'
index 0c5456887962d31b33f1f181447d5427b6cfccf7..95bac37900111e145e47b867e1a0513685da9892 100644 (file)
@@ -81,6 +81,51 @@ run_ld_link_tests [list \
        {} \
        "pr22471" \
     ] \
+    [list \
+       "Build pr22649-1.so" \
+       "$LFLAGS -shared" \
+       "" \
+       "$AFLAGS_PIC" \
+       {pr22649-1.s} \
+       {} \
+       "pr22649-1.so" \
+    ] \
+    [list \
+       "Build pr22649-2a.so" \
+       "$LFLAGS -shared -gc-sections -print-gc-sections" \
+       "" \
+       "$AFLAGS_PIC" \
+       {pr22649-2a.s} \
+       {{ld pr22649.msg}} \
+       "pr22649-2a.so" \
+    ] \
+    [list \
+       "Build pr22649-2b.so" \
+       "$LFLAGS -shared -gc-sections -print-gc-sections" \
+       "tmpdir/pr22649-1.so" \
+       "$AFLAGS_PIC" \
+       {pr22649-2a.s} \
+       {{ld pr22649.msg}} \
+       "pr22649-2b.so" \
+    ] \
+    [list \
+       "Build pr22649-2c.so" \
+       "$LFLAGS -shared -gc-sections -print-gc-sections" \
+       "" \
+       "$AFLAGS_PIC" \
+       {pr22649-2b.s} \
+       {} \
+       "pr22649-2b.so" \
+    ] \
+    [list \
+       "Build pr22649-2d.so" \
+       "$LFLAGS -shared -gc-sections -print-gc-sections" \
+       "tmpdir/pr22649-1.so" \
+       "$AFLAGS_PIC" \
+       {pr22649-2b.s} \
+       {} \
+       "pr22649-2b.so" \
+    ] \
 ]
 
 run_ld_link_tests [list \