summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-05-17 07:59:52 -0700
committerH.J. Lu <hjl.tools@gmail.com>2016-05-17 09:56:56 -0700
commit85ff5b7b6638ef04f745f0b8fd4418499a3676c6 (patch)
tree630fbe91d01d721e022618ac6162795f0f499e4c
parent68bce0209f2be6d0f852ef7092b9d412d78fd43a (diff)
downloadbinutils-gdb-users/hjl/pr20103.tar.gz
Skip an archive element if not added by linkerusers/hjl/pr20103
During archive rescan to resolve symbol references for files added by LTO, linker add_archive_element callback is called to check if an archive element should added. After all IR symbols have been claimed, linker won't claim new IR symbols and shouldn't add the LTO archive element. This patch updates linker add_archive_element callback to return FALSE when seeing an LTO archive element during rescan and changes ELF linker to skip such archive element. Other linker backends may also need similar update. bfd/ PR ld/20103 * elflink.c (elf_link_add_archive_symbols): Skip archive element if linker add_archive_element callback returns FALSE. ld/ PR ld/20103 * ldmain.c (add_archive_element): Don't claim new IR symbols after all IR symbols have been claimed. * plugin.c (plugin_call_claim_file): Remove no_more_claiming check. * testsuite/ld-plugin/lto.exp (pr20103): New proc. Run PR ld/20103 tests. * testsuite/ld-plugin/pr20103a.c: New file. * testsuite/ld-plugin/pr20103b.c: Likewise. * testsuite/ld-plugin/pr20103c.c: Likewise.
-rw-r--r--bfd/elflink.c2
-rw-r--r--ld/ldmain.c12
-rw-r--r--ld/plugin.c2
-rw-r--r--ld/testsuite/ld-plugin/lto.exp85
-rw-r--r--ld/testsuite/ld-plugin/pr20103a.c8
-rw-r--r--ld/testsuite/ld-plugin/pr20103b.c3
-rw-r--r--ld/testsuite/ld-plugin/pr20103c.c6
7 files changed, 114 insertions, 4 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 1569e93c5b8..b4efd5aec20 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5283,7 +5283,7 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
if (!(*info->callbacks
->add_archive_element) (info, element, symdef->name, &element))
- goto error_return;
+ continue;
if (!bfd_link_add_symbols (element, info))
goto error_return;
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 21133ab7209..7d04be29bbc 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -796,12 +796,22 @@ add_archive_element (struct bfd_link_info *info,
BFD, but we still want to output the original BFD filename. */
orig_input = *input;
#ifdef ENABLE_PLUGINS
- if (link_info.lto_plugin_active && !no_more_claiming)
+ if (link_info.lto_plugin_active)
{
/* We must offer this archive member to the plugins to claim. */
plugin_maybe_claim (input);
if (input->flags.claimed)
{
+ if (no_more_claiming)
+ {
+ /* Don't claim new IR symbols after all IR symbols have
+ been claimed. */
+ if (trace_files || verbose)
+ info_msg ("%I: no new IR symbols to claimi\n",
+ &orig_input);
+ input->flags.claimed = 0;
+ return FALSE;
+ }
input->flags.claim_archive = TRUE;
*subsbfd = input->the_bfd;
}
diff --git a/ld/plugin.c b/ld/plugin.c
index a60ffca70e9..c951995dccb 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -1033,8 +1033,6 @@ plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed)
{
plugin_t *curplug = plugins_list;
*claimed = FALSE;
- if (no_more_claiming)
- return 0;
while (curplug && !*claimed)
{
if (curplug->claim_file_handler)
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 6330a178aba..7a13abbfdb6 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -460,4 +460,89 @@ if { [is_elf_format] } {
run_ld_link_exec_tests [] $lto_run_elf_tests
}
+proc pr20103 {cflags libs} {
+ global CC
+
+ set testname "PR ld/20103 ($cflags $libs)"
+ set exec_output [run_host_cmd "$CC" "$cflags $libs"]
+ if { [ regexp "undefined reference to `dead'" $exec_output ] } {
+ pass "$testname (1)"
+ } {
+ fail "$testname (1)"
+ }
+ if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
+ fail "$testname (2)"
+ } {
+ pass "$testname (2)"
+ }
+}
+
+if { [check_lto_fat_available] } {
+ run_cc_link_tests [list \
+ [list \
+ "Build fatpr20103a.a" \
+ "$plug_opt" "-flto -ffat-lto-objects" \
+ {pr20103a.c} {} "fatpr20103a.a"
+ ] \
+ [list \
+ "Build fatpr20103b.a" \
+ "$plug_opt" "-flto -ffat-lto-objects" \
+ {pr20103b.c} {} "fatpr20103b.a"
+ ] \
+ [list \
+ "Build fatpr20103c.a" \
+ "$plug_opt" "-flto -ffat-lto-objects" \
+ {pr20103c.c} {} "fatpr20103c.a" \
+ ] \
+ [list \
+ "Build thinpr20103a.a" \
+ "$plug_opt" "-flto -fno-fat-lto-objects" \
+ {pr20103a.c} {} "thinpr20103a.a"
+ ] \
+ [list \
+ "Build thinpr20103b.a" \
+ "$plug_opt" "-flto -fno-fat-lto-objects" \
+ {pr20103b.c} {} "thinpr20103b.a"
+ ] \
+ [list \
+ "Build thinpr20103c.a" \
+ "$plug_opt" "-flto -fno-fat-lto-objects" \
+ {pr20103c.c} {} "thinpr20103c.a" \
+ ] \
+ [list \
+ "Build pr20103a" \
+ "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
+ "-O2 -flto" \
+ {dummy.c} {} "pr20103a" \
+ ] \
+ [list \
+ "Build pr20103b" \
+ "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
+ "-O2 -flto" \
+ {dummy.c} {} "pr20103b" \
+ ] \
+ [list \
+ "Build pr20103c" \
+ "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
+ "-O2" \
+ {dummy.c} {} "pr20103c" \
+ ] \
+ ]
+ pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
+ pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
+ pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
+
+ if { [at_least_gcc_version 4 9] } {
+ run_cc_link_tests [list \
+ [list \
+ "Build pr20103d" \
+ "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
+ "-O2" \
+ {dummy.c} {} "pr20103d" \
+ ] \
+ ]
+ pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
+ }
+}
+
restore_notify
diff --git a/ld/testsuite/ld-plugin/pr20103a.c b/ld/testsuite/ld-plugin/pr20103a.c
new file mode 100644
index 00000000000..6ebfd2c5671
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr20103a.c
@@ -0,0 +1,8 @@
+void live();
+
+int
+main ()
+{
+ live();
+ return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr20103b.c b/ld/testsuite/ld-plugin/pr20103b.c
new file mode 100644
index 00000000000..ead122dbe9b
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr20103b.c
@@ -0,0 +1,3 @@
+void dead()
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr20103c.c b/ld/testsuite/ld-plugin/pr20103c.c
new file mode 100644
index 00000000000..fb94e02f935
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr20103c.c
@@ -0,0 +1,6 @@
+extern void dead ();
+
+void live()
+{
+ dead ();
+}