This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/14915: --copy-dt-needed-entries not working when creating DSO
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Tue, 4 Dec 2012 11:12:22 -0800
- Subject: PATCH: PR ld/14915: --copy-dt-needed-entries not working when creating DSO
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
This patch extends --copy-dt-needed-entries support to -shared for
creating shared object. OK to install?
Thanks.
H.J.
---
ld/
2012-12-04 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14915
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Also
check DT_NEEDED entries when creating shared object.
ld/testsuite/
2012-12-04 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14915
* ld-elf/shared.exp (build_tests): Test --add-needed and
--copy-dt-needed-entries with -shared.
Add tests for --no-add-needed and --no-copy-dt-needed-entries
with -shared.
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 6c84b82..875ac2c 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1181,8 +1181,6 @@ gld${EMULATION_NAME}_after_open (void)
special action by the person doing the link. Note that the
needed list can actually grow while we are stepping through this
loop. */
- if (!link_info.executable)
- return;
needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
for (l = needed; l != NULL; l = l->next)
{
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 2e679d9..67017aa 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -188,6 +188,15 @@ set build_tests {
{"Build libneeded1c.o"
"-r -nostdlib" ""
{needed1c.c} {} "libneeded1c.o"}
+ {"Build libneeded1pic.o"
+ "-r -nostdlib" "-fPIC"
+ {needed1c.c} {} "libneeded1pic.o"}
+ {"Build needed1a.so with --add-needed"
+ "-shared tmpdir/libneeded1pic.o -Wl,--add-needed,-rpath=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
+ {dummy.c} {} "needed1ad.so"}
+ {"Build needed1a.so with --copy-dt-needed-entries"
+ "-shared tmpdir/libneeded1pic.o -Wl,--copy-dt-needed-entries,-rpath=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
+ {dummy.c} {} "needed1b.so"}
}
run_cc_link_tests $build_tests
@@ -352,6 +361,20 @@ if { [ regexp "'bar' is defined in DSO tmpdir/libneeded1b.so" $exec_output ] } {
} {
fail $testname
}
+set testname "--no-add-needed -shared"
+set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a"]
+if { [ regexp "'bar' is defined in DSO tmpdir/libneeded1b.so" $exec_output ] } {
+ pass $testname
+} {
+ fail $testname
+}
+set testname "--no-copy-dt-needed-entries -shared"
+set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a"]
+if { [ regexp "'bar' is defined in DSO tmpdir/libneeded1b.so" $exec_output ] } {
+ pass $testname
+} {
+ fail $testname
+}
# Check to see if the C++ compiler works
if { [which $CXX] == 0 } {