Extend --copy-dt-needed-entries to creating DSO
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Dec 2012 00:25:19 +0000 (00:25 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Dec 2012 00:25:19 +0000 (00:25 +0000)
ld/

PR ld/14915
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Also
check DT_NEEDED entries when creating shared object with
--copy-dt-needed-entries.

ld/testsuite/

PR ld/14915
* ld-elf/shared.exp (build_tests): Test --add-needed,
--copy-dt-needed-entries, --no-add-needed and
--no-copy-dt-needed-entries with -shared.
Add tests for --no-add-needed and --no-copy-dt-needed-entries
with -shared.

ld/ChangeLog
ld/emultempl/elf32.em
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/shared.exp

index 09c711114284d5e8973dd4f7ab09532d8e2e7ef3..ec911a158c5119767d69b2ebd7e9966cddd2516c 100644 (file)
@@ -1,3 +1,10 @@
+2012-12-05  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 with
+       --copy-dt-needed-entries.
+
 2012-12-05  Leif Ekblad  <leif@rdos.net>
 
        * configure.tgt: Add x86_64-*-rdos.
index 6c84b82d4ed0cff45a291c27b233f3b87e6dbe78..d30a0ad40451ad822fa06f201fb9d812ba6b19ae 100644 (file)
@@ -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)
     {
@@ -1191,9 +1189,13 @@ gld${EMULATION_NAME}_after_open (void)
       int force;
 
       /* If the lib that needs this one was --as-needed and wasn't
-        found to be needed, then this lib isn't needed either.  */
+        found to be needed, then this lib isn't needed either.  Skip
+        the lib when creating a shared object unless we are copying
+        DT_NEEDED entres.  */
       if (l->by != NULL
-         && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
+         && ((bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0
+             || (!link_info.executable
+                 && bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0))
        continue;
 
       /* If we've already seen this file, skip it.  */
index 5b1bc8fcfef5df90b0146f8767b4bb73732ff642..64632bc1f37666a43f1419cb23e20a1254bc7e57 100644 (file)
@@ -1,3 +1,12 @@
+2012-12-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/14915
+       * ld-elf/shared.exp (build_tests): Test --add-needed,
+       --copy-dt-needed-entries, --no-add-needed and
+       --no-copy-dt-needed-entries with -shared.
+       Add tests for --no-add-needed and --no-copy-dt-needed-entries
+       with -shared.
+
 2012-12-06  Alan Modra  <amodra@gmail.com>
 
        * ld-elf/comm-data4.d, ld-elf/comm-data4.s: New test.
index 2e679d9fc7c8e282000f42a4ae747e057b339d31..eef264e1581b1d86d91b2a4d6cae509e6c1f64a3 100644 (file)
@@ -188,6 +188,21 @@ 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} {} "needed1a.so"}
+  {"Build needed1b.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"}
+  {"Build needed1a.so with --no-add-needed"
+   "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed -Ltmpdir -lneeded1a" ""
+   {dummy.c} {} "needed1c.so"}
+  {"Build needed1b.so with --no-copy-dt-needed-entries"
+   "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
+   {dummy.c} {} "needed1d.so"}
 }
 
 run_cc_link_tests $build_tests
@@ -352,6 +367,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,-z,defs -Ltmpdir -lneeded1a"]
+if { [ regexp "undefined reference to `bar'" $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,-z,defs -Ltmpdir -lneeded1a"]
+if { [ regexp "undefined reference to `bar'" $exec_output ] } {
+    pass $testname
+} {
+    fail $testname
+}
 
 # Check to see if the C++ compiler works
 if { [which $CXX] == 0 } {