From aef28989904e92e391fee905e51abc6bb2fd4de0 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 1 Feb 2016 15:49:52 -0800 Subject: [PATCH] Don't add DT_NEEDED for unmatched symbol Don't add DT_NEEDED if a symbol from a library loaded via DT_NEEDED doesn't match the symbol referenced by regular object. bfd/ PR ld/19553 * elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED if a symbol from a library loaded via DT_NEEDED doesn't match the symbol referenced by regular object. ld/testsuite/ PR ld/19553 * testsuite/ld-elf/indirect.exp: Run tests for PR ld/19553. * testsuite/ld-elf/pr19553.map: New file. * testsuite/ld-elf/pr19553.map: Likewise. * testsuite/ld-elf/pr19553a.c: Likewise. * testsuite/ld-elf/pr19553b.c: Likewise. * testsuite/ld-elf/pr19553b.out: Likewise. * testsuite/ld-elf/pr19553c.c: Likewise. * testsuite/ld-elf/pr19553c.out: Likewise. * testsuite/ld-elf/pr19553d.c: Likewise. * testsuite/ld-elf/pr19553d.out: Likewise. --- bfd/ChangeLog | 7 +++++++ bfd/elflink.c | 4 +++- ld/ChangeLog | 14 ++++++++++++++ ld/testsuite/ld-elf/indirect.exp | 24 +++++++++++++++++++++++- ld/testsuite/ld-elf/pr19553.map | 5 +++++ ld/testsuite/ld-elf/pr19553a.c | 8 ++++++++ ld/testsuite/ld-elf/pr19553b.c | 8 ++++++++ ld/testsuite/ld-elf/pr19553b.out | 1 + ld/testsuite/ld-elf/pr19553c.c | 9 +++++++++ ld/testsuite/ld-elf/pr19553c.out | 1 + ld/testsuite/ld-elf/pr19553d.c | 8 ++++++++ ld/testsuite/ld-elf/pr19553d.out | 1 + 12 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr19553.map create mode 100644 ld/testsuite/ld-elf/pr19553a.c create mode 100644 ld/testsuite/ld-elf/pr19553b.c create mode 100644 ld/testsuite/ld-elf/pr19553b.out create mode 100644 ld/testsuite/ld-elf/pr19553c.c create mode 100644 ld/testsuite/ld-elf/pr19553c.out create mode 100644 ld/testsuite/ld-elf/pr19553d.c create mode 100644 ld/testsuite/ld-elf/pr19553d.out diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 35d596d561f..06596f9d5e8 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2016-02-01 H.J. Lu + + PR ld/19553 + * elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED + if a symbol from a library loaded via DT_NEEDED doesn't match + the symbol referenced by regular object. + 2016-02-01 Nathaniel Smith * peicode.h (pe_ILF_build_a_bfd): Create an import symbol for both diff --git a/bfd/elflink.c b/bfd/elflink.c index e71cb507975..ac03ce5003a 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -4562,8 +4562,10 @@ error_free_dyn: break; } - /* Don't add DT_NEEDED for references from the dummy bfd. */ + /* Don't add DT_NEEDED for references from the dummy bfd nor + for unmatched symbol. */ if (!add_needed + && matched && definition && ((dynsym && h->ref_regular_nonweak diff --git a/ld/ChangeLog b/ld/ChangeLog index 34b4feb112a..47af0bdd8b2 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,17 @@ +2016-02-01 H.J. Lu + + PR ld/19553 + * testsuite/ld-elf/indirect.exp: Run tests for PR ld/19553. + * testsuite/ld-elf/pr19553.map: New file. + * testsuite/ld-elf/pr19553.map: Likewise. + * testsuite/ld-elf/pr19553a.c: Likewise. + * testsuite/ld-elf/pr19553b.c: Likewise. + * testsuite/ld-elf/pr19553b.out: Likewise. + * testsuite/ld-elf/pr19553c.c: Likewise. + * testsuite/ld-elf/pr19553c.out: Likewise. + * testsuite/ld-elf/pr19553d.c: Likewise. + * testsuite/ld-elf/pr19553d.out: Likewise. + 2016-01-30 H.J. Lu PR ld/19539 diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp index 86324ec9cdf..1a012796541 100644 --- a/ld/testsuite/ld-elf/indirect.exp +++ b/ld/testsuite/ld-elf/indirect.exp @@ -66,7 +66,11 @@ if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o] || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o] || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o] || ![ld_compile "$CC -O2 -fPIC -I../bfd" $srcdir/$subdir/pr18720a.c tmpdir/pr18720a.o] - || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o] } { + || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o] + || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553d.c tmpdir/pr19553d.o] + || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553c.c tmpdir/pr19553c.o] + || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553b.c tmpdir/pr19553b.o] + || ![ld_compile $CC $srcdir/$subdir/pr19553a.c tmpdir/pr19553a.o] } { unresolved "Indirect symbol tests" return } @@ -87,6 +91,15 @@ set build_tests { {"Build pr18720b1.o" "-r -nostdlib tmpdir/pr18720b.o" "" {dummy.c} {} "pr18720b1.o"} + {"Build libpr19553b.so" + "-shared -Wl,--version-script=pr19553.map" "-fPIC" + {pr19553b.c} {} "libpr19553b.so"} + {"Build libpr19553c.so" + "-shared -Wl,--version-script=pr19553.map" "-fPIC" + {pr19553c.c} {} "libpr19553c.so"} + {"Build libpr19553d.so" + "-shared tmpdir/libpr19553c.so" "-fPIC" + {pr19553d.c} {} "libpr19553d.so"} } run_cc_link_tests $build_tests @@ -155,6 +168,15 @@ set run_tests { {"Run with libpr18720c.so 5" "tmpdir/libpr18720c.so tmpdir/pr18720b1.o tmpdir/pr18720a.o" "" {check-ptr-eq.c} "pr18720d" "pr18720.out"} + {"Run with libpr19553b.so" + "tmpdir/libpr19553b.so tmpdir/libpr19553d.so -rpath-link ." "" + {pr19553a.c} "pr19553b" "pr19553b.out"} + {"Run with libpr19553c.so" + "tmpdir/libpr19553c.so tmpdir/libpr19553b.so tmpdir/libpr19553d.so" "" + {pr19553a.c} "pr19553c" "pr19553c.out"} + {"Run with libpr19553d.so" + "tmpdir/libpr19553d.so tmpdir/libpr19553b.so -rpath-link ." "" + {pr19553a.c} "pr19553d" "pr19553d.out"} } run_ld_link_exec_tests [] $run_tests diff --git a/ld/testsuite/ld-elf/pr19553.map b/ld/testsuite/ld-elf/pr19553.map new file mode 100644 index 00000000000..f2c03ac7a13 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553.map @@ -0,0 +1,5 @@ +FOO +{ +global: + foo; +}; diff --git a/ld/testsuite/ld-elf/pr19553a.c b/ld/testsuite/ld-elf/pr19553a.c new file mode 100644 index 00000000000..f1cb6b492bd --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553a.c @@ -0,0 +1,8 @@ +extern void foo (void); + +int +main (void) +{ + foo (); + return 0; +} diff --git a/ld/testsuite/ld-elf/pr19553b.c b/ld/testsuite/ld-elf/pr19553b.c new file mode 100644 index 00000000000..0c438a24682 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553b.c @@ -0,0 +1,8 @@ +#include + +__attribute__ ((weak)) +void +foo (void) +{ + printf ("pr19553b\n"); +} diff --git a/ld/testsuite/ld-elf/pr19553b.out b/ld/testsuite/ld-elf/pr19553b.out new file mode 100644 index 00000000000..a5575d98a85 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553b.out @@ -0,0 +1 @@ +pr19553b diff --git a/ld/testsuite/ld-elf/pr19553c.c b/ld/testsuite/ld-elf/pr19553c.c new file mode 100644 index 00000000000..d80dfc9fc3b --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553c.c @@ -0,0 +1,9 @@ +#include + +void +foo (void) +{ + printf ("pr19553c\n"); +} + +asm (".symver foo,foo@FOO"); diff --git a/ld/testsuite/ld-elf/pr19553c.out b/ld/testsuite/ld-elf/pr19553c.out new file mode 100644 index 00000000000..9d232155b9c --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553c.out @@ -0,0 +1 @@ +pr19553c diff --git a/ld/testsuite/ld-elf/pr19553d.c b/ld/testsuite/ld-elf/pr19553d.c new file mode 100644 index 00000000000..d48f8f38456 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553d.c @@ -0,0 +1,8 @@ +#include + +__attribute__ ((weak)) +void +foo (void) +{ + printf ("pr19553d\n"); +} diff --git a/ld/testsuite/ld-elf/pr19553d.out b/ld/testsuite/ld-elf/pr19553d.out new file mode 100644 index 00000000000..2b4cf0b05dc --- /dev/null +++ b/ld/testsuite/ld-elf/pr19553d.out @@ -0,0 +1 @@ +pr19553d -- 2.30.2