]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR22220, BFD linker wrongly marks symbols as PREVAILING_DEF_IRONLY
authorAlan Modra <amodra@gmail.com>
Thu, 28 Sep 2017 07:41:38 +0000 (17:11 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 28 Sep 2017 08:06:36 +0000 (17:36 +0930)
non_ir_ref_dynamic wasn't being set in the case where we have a
versioned dynamic symbol definition with a non-versioned matching IR
symbol.

bfd/
PR 22220
* elflink.c (_bfd_elf_merge_symbol): Set non_ir_ref_dynamic in
a case where plugin_notice isn't called.
ld/
* testsuite/ld-plugin/pr22220.h,
* testsuite/ld-plugin/pr22220lib.cc,
* testsuite/ld-plugin/pr22220lib.ver,
* testsuite/ld-plugin/pr22220main.cc: New test.
* testsuite/ld-plugin/lto.exp: Run it.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr22220.h [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22220lib.cc [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22220lib.ver [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22220main.cc [new file with mode: 0644]

index 1a4bde1ee65d354fe537cf3ad78ce53b0a702804..8fca051b8395d229dc3d4d8f795ed2b191d3d6bb 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-28  Alan Modra  <amodra@gmail.com>
+
+       PR 22220
+       * elflink.c (_bfd_elf_merge_symbol): Set non_ir_ref_dynamic in
+       a case where plugin_notice isn't called.
+
 2017-09-27  Kuan-Lin Chen  <kuanlinchentw@gmail.com>
 
        * elf32-nds32.c (nds32_elf_relax_section): Fix a tautological
index ee5c01fde786daf5a6dde2ecd0e551b64cfffda2..982bf4f04ffc590148458c6ae6a0ed36b425a5ff 100644 (file)
@@ -1234,6 +1234,16 @@ _bfd_elf_merge_symbol (bfd *abfd,
       olddyn = (oldsec->symbol->flags & BSF_DYNAMIC) != 0;
     }
 
+  /* Handle a case where plugin_notice won't be called and thus won't
+     set the non_ir_ref flags on the first pass over symbols.  */
+  if (oldbfd != NULL
+      && (oldbfd->flags & BFD_PLUGIN) != (abfd->flags & BFD_PLUGIN)
+      && newdyn != olddyn)
+    {
+      h->root.non_ir_ref_dynamic = TRUE;
+      hi->root.non_ir_ref_dynamic = TRUE;
+    }
+
   /* NEWDEF and OLDDEF indicate whether the new or old symbol,
      respectively, appear to be a definition rather than reference.  */
 
index 0ccc02be6284d8d89b05239d4e13683fdfa1c619..d671ed1649d2dc77e2ca7c4ba6a6728b8cd59175 100644 (file)
@@ -1,3 +1,11 @@
+2017-09-28  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/ld-plugin/pr22220.h,
+       * testsuite/ld-plugin/pr22220lib.cc,
+       * testsuite/ld-plugin/pr22220lib.ver,
+       * testsuite/ld-plugin/pr22220main.cc: New test.
+       * testsuite/ld-plugin/lto.exp: Run it.
+
 2017-09-26  Maciej W. Rozycki  <macro@imgtec.com>
 
        * testsuite/ld-undefined/undefined.exp: Correct the dyn reloc
index f0bc345f2c76b3fb1ed44b4354089932e1a45253..6b7ad536fbc6652386469813f5f067f688534ac9 100644 (file)
@@ -295,6 +295,12 @@ set lto_link_elf_tests [list \
   [list "Build pr21382.so" \
    "-shared" "-O2 -fpic" \
    {pr21382b.c} {} "pr21382.so" "c"] \
+  [list {Build pr22220lib.so} \
+   {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
+   {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
+  [list {Build pr22220main.o} \
+   {} {-flto} \
+   {pr22220main.cc} {} {} {c++}] \
 ]
 
 # Check final symbols in executables.
@@ -396,6 +402,12 @@ set lto_run_elf_shared_tests [list \
   [list "Run pr21382" \
    "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
    {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
+  [list {pr22220a} \
+   {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
+   {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
+  [list {pr22220b} \
+   {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
+   {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
 ]
 
 # LTO run-time tests for ELF
diff --git a/ld/testsuite/ld-plugin/pr22220.h b/ld/testsuite/ld-plugin/pr22220.h
new file mode 100644 (file)
index 0000000..b15b45c
--- /dev/null
@@ -0,0 +1,8 @@
+extern int doo();
+
+inline int *goo() {
+       static int xyz;
+       return &xyz;
+}
+
+int *boo();
diff --git a/ld/testsuite/ld-plugin/pr22220lib.cc b/ld/testsuite/ld-plugin/pr22220lib.cc
new file mode 100644 (file)
index 0000000..771f44f
--- /dev/null
@@ -0,0 +1,6 @@
+#include "pr22220.h"
+
+int* boo()
+{
+  return goo ();
+}
diff --git a/ld/testsuite/ld-plugin/pr22220lib.ver b/ld/testsuite/ld-plugin/pr22220lib.ver
new file mode 100644 (file)
index 0000000..6da7e1a
--- /dev/null
@@ -0,0 +1 @@
+BAR { global: *; };
diff --git a/ld/testsuite/ld-plugin/pr22220main.cc b/ld/testsuite/ld-plugin/pr22220main.cc
new file mode 100644 (file)
index 0000000..38c206f
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "pr22220.h"
+
+int main()
+{
+  if (boo() == goo())
+    {
+      printf ("PASS\n");
+      return 0;
+    }
+  return 1;
+}