This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] PR ld/22220: Let plugin know that an indirect symbol is added
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 28 Sep 2017 01:15:20 -0700
- Subject: Re: [PATCH] PR ld/22220: Let plugin know that an indirect symbol is added
- Authentication-results: sourceware.org; auth=none
- References: <20170927224634.GA16695@gmail.com>
On Wed, Sep 27, 2017 at 03:46:34PM -0700, H.J. Lu wrote:
> 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?
Here is a simpler version. OK for master?
H.J.
---
Subject: [PATCH] LTO: Let plugin know symbol is referenced in shared object
When an unversioned definition in a regular object overrides the default
versioned symbol in the shared object, we set ref_dynamic to 1 on the
unversioned definition. We also should set non_ir_ref_dynamic to 1 to
let plugin know that symbol is referenced in a normal dynamic object file.
bfd/
PR ld/22220
* elflink.c (_bfd_elf_add_default_symbol): Let plugin know that
symbol is referenced in a normal dynamic object file.
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 | 3 +++
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, 42 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..7e61ae4d41 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1927,6 +1927,9 @@ _bfd_elf_add_default_symbol (bfd *abfd,
{
h->def_dynamic = 0;
hi->ref_dynamic = 1;
+ /* Let plugin know that symbol is referenced in a normal
+ dynamic object file. */
+ hi->root.non_ir_ref_dynamic = 1;
if (hi->ref_regular
|| hi->def_regular)
{
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index f0bc345f2c..5c8655ae1d 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -295,6 +295,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.
@@ -396,6 +402,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