Skip to content

Commit d2ea9f3

Browse files
committed
PR27311, ld.bfd (symbol from plugin): undefined reference
A default versioned symbol definition in a shared library is overridden by an unversioned definition in a regular object file, and thus should not be reason to make an as-needed library needed. bfd/ PR 27311 * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed libraries when H is an indirect symbol after calling _bfd_elf_add_default_symbol. ld/ * testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so): Link with --as-needed. * testsuite/ld-plugin/pr27311.d, * testsuite/ld-plugin/pr27311.ver, * testsuite/ld-plugin/pr27311a.c, * testsuite/ld-plugin/pr27311b.c, * testsuite/ld-plugin/pr27311c.c: New testcase. * testsuite/ld-plugin/lto.exp: Run it. Correct PR14918 and PR12982 entries. (cherry picked from commit 9918bff) (cherry picked from commit 6955136) (cherry picked from commit f01fb44)
1 parent ee6dd62 commit d2ea9f3

File tree

10 files changed

+56
-8
lines changed

10 files changed

+56
-8
lines changed

bfd/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2021-02-03 Alan Modra <amodra@gmail.com>
2+
3+
PR 27311
4+
* elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
5+
libraries when H is an indirect symbol after calling
6+
_bfd_elf_add_default_symbol.
7+
18
2021-01-28 Alan Modra <amodra@gmail.com>
29

310
PR 27259

bfd/elflink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5274,6 +5274,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
52745274
if (!add_needed
52755275
&& matched
52765276
&& definition
5277+
&& h->root.type != bfd_link_hash_indirect
52775278
&& ((dynsym
52785279
&& h->ref_regular_nonweak)
52795280
|| (old_bfd != NULL

ld/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2021-02-03 Alan Modra <amodra@gmail.com>
2+
3+
Apply from mainline
4+
2021-02-03 Alan Modra <amodra@gmail.com>
5+
* testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so):
6+
Link with --as-needed.
7+
8+
2021-02-02 Alan Modra <amodra@gmail.com>
9+
* testsuite/ld-plugin/pr27311.d,
10+
* testsuite/ld-plugin/pr27311.ver,
11+
* testsuite/ld-plugin/pr27311a.c,
12+
* testsuite/ld-plugin/pr27311b.c,
13+
* testsuite/ld-plugin/pr27311c.c: New testcase.
14+
* testsuite/ld-plugin/lto.exp: Run it. Correct PR14918 and
15+
PR12982 entries.
16+
117
2021-01-28 Alan Modra <amodra@gmail.com>
218

319
PR 27259

ld/testsuite/ld-ifunc/ifunc.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ run_cc_link_tests [list \
397397
] \
398398
[list \
399399
"Build libpr16467b.so" \
400-
"-shared tmpdir/pr16467b.o tmpdir/libpr16467a.so \
400+
"-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467a.so \
401401
-Wl,--version-script=pr16467b.map" \
402402
"-fPIC" \
403403
{ dummy.c } \
@@ -422,7 +422,7 @@ run_cc_link_tests [list \
422422
] \
423423
[list \
424424
"Build libpr16467bn.so" \
425-
"-shared tmpdir/pr16467b.o tmpdir/libpr16467an.so \
425+
"-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467an.so \
426426
-Wl,--version-script=pr16467b.map" \
427427
"-fPIC" \
428428
{ dummy.c } \

ld/testsuite/ld-plugin/lto.exp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ set lto_link_elf_tests [list \
415415
[list {pr26806.so} \
416416
{-shared} {-fpic -O2 -flto} \
417417
{pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
418+
[list {pr27311a.so} \
419+
{-shared -Wl,--version-script=pr27311.ver} {-fPIC} \
420+
{pr27311a.c} {} {pr27311a.so}] \
421+
[list {pr27311b.so} \
422+
{-shared -Wl,--no-as-needed tmpdir/pr27311a.so} {-fPIC} \
423+
{pr27311b.c} {} {pr27311b.so}] \
424+
[list {pr27311c.o} \
425+
{} {-flto} \
426+
{pr27311c.c} {} {} {c}] \
427+
[list {pr27311} \
428+
{tmpdir/pr27311c.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
429+
{dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311}] \
418430
]
419431

420432
# PR 14918 checks that libgcc is not spuriously included in a shared link of
@@ -423,23 +435,21 @@ set lto_link_elf_tests [list \
423435
# __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
424436
# test fails. Hence this code to skip the test.
425437
if { ! [istarget "arm*-*-*"] } {
426-
lappend lto_link_elf_tests [list \
438+
lappend lto_link_elf_tests \
427439
[list "PR ld/14918" \
428440
"-flto" "-flto" \
429-
{pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
430-
]
441+
{pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"]
431442
}
432443

433444
# PR 12982 checks that an executable stack is not created by default
434445
# when using the LTO plugin. The HPPA target however requires an
435446
# executable stack for syscall restarts and signal returns, so we
436447
# skip this test for that target.
437448
if { ! [istarget "hppa*-*-*"] } {
438-
lappend lto_link_elf_tests [list \
449+
lappend lto_link_elf_tests \
439450
[list "PR ld/12982" \
440451
"-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
441-
{pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
442-
]
452+
{pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"]
443453
}
444454

445455
# Check final symbols in executables.

ld/testsuite/ld-plugin/pr27311.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#failif
2+
#...
3+
.* _*inlib1.*
4+
#...

ld/testsuite/ld-plugin/pr27311.ver

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LIBFOO {
2+
*;
3+
};

ld/testsuite/ld-plugin/pr27311a.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void inlib1(void) {}

ld/testsuite/ld-plugin/pr27311b.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void inlib2(void) {}

ld/testsuite/ld-plugin/pr27311c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void inlib1(void) {}
2+
int main()
3+
{
4+
return 0;
5+
}

0 commit comments

Comments
 (0)