This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR ld/22220: Let plugin know that an indirect symbol is added


When an unversioned definition in a regular object overrides the default
versioned symbol in the shared object, we turn the default versioned
symbol into an indirect symbol so that the references in the shared
object are mapped to the definition in the regular object.  When this
happens, we must call the plugin "notice" function to let it know that
an indirect symbol is added.

OK for master?

H.J.
---
bfd/

	PR ld/22220
	* elflink.c (_bfd_elf_add_default_symbol): Call the plugin
	"notice" function when adding an indirect symbol.

ld/

	PR ld/22220
	* testsuite/ld-plugin/lto.exp: Run PR ld/22220 test.
	* testsuite/ld-plugin/pr22220.h: New file.
	* testsuite/ld-plugin/pr22220.ver: Likewise.
	* testsuite/ld-plugin/pr22220a.cc: Likewise.
	* testsuite/ld-plugin/pr22220b.cc: Likewise.
---
 bfd/elflink.c                      | 17 +++++++++++++++++
 ld/testsuite/ld-plugin/lto.exp     |  9 +++++++++
 ld/testsuite/ld-plugin/pr22220.h   |  9 +++++++++
 ld/testsuite/ld-plugin/pr22220.ver |  4 ++++
 ld/testsuite/ld-plugin/pr22220a.cc |  7 +++++++
 ld/testsuite/ld-plugin/pr22220b.cc | 10 ++++++++++
 6 files changed, 56 insertions(+)
 create mode 100644 ld/testsuite/ld-plugin/pr22220.h
 create mode 100644 ld/testsuite/ld-plugin/pr22220.ver
 create mode 100644 ld/testsuite/ld-plugin/pr22220a.cc
 create mode 100644 ld/testsuite/ld-plugin/pr22220b.cc

diff --git a/bfd/elflink.c b/bfd/elflink.c
index ee5c01fde7..345f83beeb 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1925,6 +1925,23 @@ _bfd_elf_add_default_symbol (bfd *abfd,
       h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
       if (h->def_dynamic)
 	{
+	  /* Let plugin know that we added an indirect symbol.  */
+	  if (info->notice_all
+	      || (info->notice_hash != NULL
+		  && bfd_hash_lookup (info->notice_hash,
+				      hi->root.root.string,
+				      FALSE, FALSE) != NULL))
+	    {
+	      if (! (*info->callbacks->notice) (info,
+						(struct bfd_link_hash_entry *) hi,
+						(struct bfd_link_hash_entry *) h,
+						abfd,
+						bfd_ind_section_ptr,
+						value,
+						BSF_INDIRECT))
+		return FALSE;
+	    }
+
 	  h->def_dynamic = 0;
 	  hi->ref_dynamic = 1;
 	  if (hi->ref_regular
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index ba46d26f90..5dc86d2b76 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -310,6 +310,12 @@ set lto_link_elf_tests [list \
   [list "Build pr21382.so" \
    "-shared" "-O2 -fpic" \
    {pr21382b.c} {} "pr21382.so" "c"] \
+  [list "Build pr22220.so" \
+   "-shared -Wl,--version-script,pr22220.ver" "-fPIC" \
+   {pr22220a.cc} {} "pr22220.so" "c++"] \
+  [list "Build pr22220b.o" \
+   "" "-O2 -flto" \
+   {pr22220b.cc} {} "" "c++"] \
 ]
 
 # Check final symbols in executables.
@@ -423,6 +429,9 @@ 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 "Run pr22220" \
+   "-O2 -flto -Wl,--as-needed tmpdir/pr22220b.o tmpdir/pr22220.so" "" \
+   {dummy.c} "pr22220.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
index 0000000000..e201bdd481
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22220.h
@@ -0,0 +1,9 @@
+extern int doo ();
+
+inline int *goo ()
+{
+  static int xyz;
+  return &xyz;
+}
+
+int *boo();
diff --git a/ld/testsuite/ld-plugin/pr22220.ver b/ld/testsuite/ld-plugin/pr22220.ver
new file mode 100644
index 0000000000..e61a9f5c40
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22220.ver
@@ -0,0 +1,4 @@
+BAR {
+global:
+  *;
+};
diff --git a/ld/testsuite/ld-plugin/pr22220a.cc b/ld/testsuite/ld-plugin/pr22220a.cc
new file mode 100644
index 0000000000..f1e3f95379
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22220a.cc
@@ -0,0 +1,7 @@
+#include "pr22220.h"
+
+int*
+boo ()
+{
+  return goo ();
+}
diff --git a/ld/testsuite/ld-plugin/pr22220b.cc b/ld/testsuite/ld-plugin/pr22220b.cc
new file mode 100644
index 0000000000..cde9b36d02
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22220b.cc
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include "pr22220.h"
+
+int
+main (void)
+{
+  if (boo() == goo())
+    printf ("PASS\n");
+  return 0;
+}
-- 
2.13.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]