From 7d409ac001cce916661d345bff01ed589991e762 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 4 Feb 2021 13:56:34 +1030 Subject: [PATCH] PR27311, (symbol from plugin): undefined reference, hidden sym bfd/ PR 27311 * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed libraries for IR references on pass over libraries after LTO recompilation. ld/ * testsuite/ld-plugin/pr27311d.c: New test. * testsuite/ld-plugin/lto.exp: Rename pr27311 to pr27311-1, compile and link new test as pr27311-2. --- bfd/ChangeLog | 7 +++++++ bfd/elflink.c | 1 + ld/ChangeLog | 6 ++++++ ld/testsuite/ld-plugin/lto.exp | 10 ++++++++-- ld/testsuite/ld-plugin/pr27311d.c | 5 +++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-plugin/pr27311d.c diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 99987a26402..d40aa5028b3 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2021-02-04 Alan Modra + + PR 27311 + * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed + libraries for IR references on pass over libraries after LTO + recompilation. + 2021-02-03 Alan Modra PR 27311 diff --git a/bfd/elflink.c b/bfd/elflink.c index b8c29250a2c..291cec0df25 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -5279,6 +5279,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) && h->ref_regular_nonweak) || (old_bfd != NULL && (old_bfd->flags & BFD_PLUGIN) != 0 + && !info->lto_all_symbols_read && bind != STB_WEAK) || (h->ref_dynamic_nonweak && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0 diff --git a/ld/ChangeLog b/ld/ChangeLog index e5f9beaabf0..cf5217b6c70 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2021-02-04 Alan Modra + + * testsuite/ld-plugin/pr27311d.c: New test. + * testsuite/ld-plugin/lto.exp: Rename pr27311 to pr27311-1, compile + and link new test as pr27311-2. + 2021-02-03 Alan Modra * testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so): diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 324adcd00ce..c96617f9e9e 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -424,9 +424,15 @@ set lto_link_elf_tests [list \ [list {pr27311c.o} \ {} {-flto} \ {pr27311c.c} {} {} {c}] \ - [list {pr27311} \ + [list {pr27311d.o} \ + {} {-flto} \ + {pr27311d.c} {} {} {c}] \ + [list {pr27311-1} \ {tmpdir/pr27311c.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \ - {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311}] \ + {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-1}] \ + [list {pr27311-2} \ + {tmpdir/pr27311d.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \ + {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-2}] \ ] # PR 14918 checks that libgcc is not spuriously included in a shared link of diff --git a/ld/testsuite/ld-plugin/pr27311d.c b/ld/testsuite/ld-plugin/pr27311d.c new file mode 100644 index 00000000000..11e4ba4d6dd --- /dev/null +++ b/ld/testsuite/ld-plugin/pr27311d.c @@ -0,0 +1,5 @@ +__attribute__((visibility("hidden"))) void inlib1(void) {} +int main() +{ + return 0; +} -- 2.30.2