summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-plugin
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-04-20 07:48:24 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-04-20 07:48:35 -0700
commit59fa66c53823dc695f78669f40ec2eebab3aec42 (patch)
tree175d8e3b6761189c2a361c6cfdb4dce606d10c38 /ld/testsuite/ld-plugin
parentc76886885987e543f9162809ad86a0a37b394e82 (diff)
downloadbinutils-gdb-59fa66c53823dc695f78669f40ec2eebab3aec42.tar.gz
Handle symbol defined in IR and referenced in DSO
We need to make an IR symbol visible if it is defined in an IR object and referenced in a dynamic object. When --as-needed is used, since linker removes the IR symbol reference of the dynamic object if the dynamic object isn't needed in the first pass, the IR definition isn't visible to the dynamic object even if the dynamic object becomes needed in the second pass. Add dynamic_ref_after_ir_def to bfd_link_hash_entry to track IR symbol which is defined in an IR object and later referenced in a dynamic object. dynamic_ref_after_ir_def is preserved when restoring the symbol table for unneeded dynamic object. bfd/ PR ld/21382 * elflink.c (elf_link_add_object_symbols): Preserve dynamic_ref_after_ir_def when restoring the symbol table for unneeded dynamic object. include/ PR ld/21382 * bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def. ld/ PR ld/21382 * plugin.c (is_visible_from_outside): Symbol may be visible from outside if dynamic_ref_after_ir_def is set. (plugin_notice): Set dynamic_ref_after_ir_def if the symbol is defined in an IR object and referenced in a dynamic object. * testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests. * testsuite/ld-plugin/pr21382a.c: New file. * testsuite/ld-plugin/pr21382b.c: Likewise.
Diffstat (limited to 'ld/testsuite/ld-plugin')
-rw-r--r--ld/testsuite/ld-plugin/lto.exp9
-rw-r--r--ld/testsuite/ld-plugin/pr21382a.c17
-rw-r--r--ld/testsuite/ld-plugin/pr21382b.c7
3 files changed, 33 insertions, 0 deletions
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 80c084bda11..f0bc345f2c7 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -289,6 +289,12 @@ set lto_link_elf_tests [list \
[list "PR ld/14918" \
"-flto" "-flto" \
{pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
+ [list "Build pr21382a.o" \
+ "" "-O2 -flto" \
+ {pr21382a.c} {} "" "c"] \
+ [list "Build pr21382.so" \
+ "-shared" "-O2 -fpic" \
+ {pr21382b.c} {} "pr21382.so" "c"] \
]
# Check final symbols in executables.
@@ -387,6 +393,9 @@ set lto_run_elf_shared_tests [list \
[list "LTO 7" \
"-O2 -flto -fuse-linker-plugin tmpdir/lto-7b.o tmpdir/lto-7c.o tmpdir/lto-7a.o -Wl,--no-as-needed tmpdir/liblto-7.so" "" \
{dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
+ [list "Run pr21382" \
+ "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
+ {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
]
# LTO run-time tests for ELF
diff --git a/ld/testsuite/ld-plugin/pr21382a.c b/ld/testsuite/ld-plugin/pr21382a.c
new file mode 100644
index 00000000000..09b9d758d3e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr21382a.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+extern void y (void);
+
+void
+x (void)
+{
+ printf ("PASS\n");
+}
+
+
+int
+main (void)
+{
+ y ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr21382b.c b/ld/testsuite/ld-plugin/pr21382b.c
new file mode 100644
index 00000000000..c5b74a94417
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr21382b.c
@@ -0,0 +1,7 @@
+extern void x (void);
+
+void
+y (void)
+{
+ x ();
+}