From: Alan Modra Date: Mon, 18 Aug 2014 05:13:03 +0000 (+0930) Subject: PR 17287, DT_NEEDED of unneeded libraries affects --as-needed X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1240be6b7d0a5604c4e3efe12c9e1d08ebc246be;p=binutils-gdb.git PR 17287, DT_NEEDED of unneeded libraries affects --as-needed PR 17287 bfd/ * elflink.c (on_needed_list): Only consider libraries that have been loaded. ld/ * ld.texinfo (--as-needed): Clarify that references from libraries must be from needed libraries. ld/testsuite/ * ld-plugin/needed3.c: New file. * ld-elf/shared.exp: Add needed3 test. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 508a20a2a9c..3c2ed575c85 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2014-08-18 Alan Modra + + PR 17287 + * elflink.c (on_needed_list): Only consider libraries that have + been loaded. + 2014-08-18 Alan Modra * elflink.c (bfd_elf_discard_info): Return int error status. diff --git a/bfd/elflink.c b/bfd/elflink.c index d20f357e2cc..c80ee8257b5 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -3086,7 +3086,8 @@ static bfd_boolean on_needed_list (const char *soname, struct bfd_link_needed_list *needed) { for (; needed != NULL; needed = needed->next) - if (strcmp (soname, needed->name) == 0) + if ((elf_dyn_lib_class (needed->by) & DYN_AS_NEEDED) == 0 + && strcmp (soname, needed->name) == 0) return TRUE; return FALSE; diff --git a/ld/ChangeLog b/ld/ChangeLog index 2c1ec6af9c5..7804d71821a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2014-08-18 Alan Modra + + * ld.texinfo (--as-needed): Clarify that references from libraries + must be from needed libraries. + 2014-08-18 Alan Modra * emultempl/aarch64elf.em (gld${EMULATION_NAME}_after_allocation): diff --git a/ld/ld.texinfo b/ld/ld.texinfo index b559b4f5ed0..718a7d03457 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1179,8 +1179,8 @@ on the command line, regardless of whether the library is actually needed or not. @option{--as-needed} causes a DT_NEEDED tag to only be emitted for a library that @emph{at that point in the link} satisfies a non-weak undefined symbol reference from a regular object file or, if -the library is not found in the DT_NEEDED lists of other libraries, a -non-weak undefined symbol reference from another dynamic library. +the library is not found in the DT_NEEDED lists of other needed libraries, a +non-weak undefined symbol reference from another needed dynamic library. Object files or libraries appearing on the command line @emph{after} the library in question do not affect whether the library is seen as needed. This is similar to the rules for extraction of object files diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index c52203af31a..6b6e8f7ad43 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-08-18 Alan Modra + + * ld-plugin/needed3.c: New file. + * ld-elf/shared.exp: Add needed3 test. + 2014-08-12 Alan Modra * lib/ld-lib.exp (check_plugin_api_available): Match "-plugin PLUGIN". diff --git a/ld/testsuite/ld-elf/needed3.c b/ld/testsuite/ld-elf/needed3.c new file mode 100644 index 00000000000..cbb9d564d63 --- /dev/null +++ b/ld/testsuite/ld-elf/needed3.c @@ -0,0 +1,8 @@ +extern void foo (void); + +int +main () +{ + foo (); + return 0; +} diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index de2a5f29270..b55856a2462 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -222,6 +222,18 @@ set build_tests { {"Build needed2" "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" "" {dummy.c} {} "needed2"} + {"Build libneeded3a.so" + "-shared -Wl,--no-add-needed" "-fPIC" + {needed1a.c} {} "libneeded3a.so"} + {"Build libneeded3b.so" + "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC" + {dummy.c} {} "libneeded3b.so"} + {"Build needed3.o" + "-r -nostdlib" "" + {needed3.c} {} "libneeded3.so"} + {"Build needed3" + "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" "" + {dummy.c} {} "needed3"} {"Build libpr2404a.so" "-shared" "-fPIC" {pr2404a.c} {} "libpr2404a.so"}