Add tests for --add-needed/--copy-dt-needed-entries
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 4 Dec 2012 17:44:43 +0000 (17:44 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 4 Dec 2012 17:44:43 +0000 (17:44 +0000)
* ld-elf/shared.exp (build_tests): Build libneeded1b.so,
libneeded1a.so and libneeded1c.o.
(run_tests): Test --add-needed and --copy-dt-needed-entries.
Add tests for --no-add-needed and --no-copy-dt-needed-entries.

* ld-elf/needed1.out: New file.
* ld-elf/needed1a.c: Likewise.
* ld-elf/needed1b.c: Likewise.
* ld-elf/needed1c.c: Likewise.

ld/testsuite/ChangeLog
ld/testsuite/ld-elf/needed1.out [new file with mode: 0644]
ld/testsuite/ld-elf/needed1a.c [new file with mode: 0644]
ld/testsuite/ld-elf/needed1b.c [new file with mode: 0644]
ld/testsuite/ld-elf/needed1c.c [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 72347430da06d41c17002008c7f9bebf88aa62bd..6f68d809c26a23ab1f84bd4878bc924552a48889 100644 (file)
@@ -1,3 +1,15 @@
+2012-12-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ld-elf/shared.exp (build_tests): Build libneeded1b.so,
+       libneeded1a.so and libneeded1c.o.
+       (run_tests): Test --add-needed and --copy-dt-needed-entries.
+       Add tests for --no-add-needed and --no-copy-dt-needed-entries.
+
+       * ld-elf/needed1.out: New file.
+       * ld-elf/needed1a.c: Likewise.
+       * ld-elf/needed1b.c: Likewise.
+       * ld-elf/needed1c.c: Likewise.
+
 2012-12-03  Maciej W. Rozycki  <macro@codesourcery.com>
 
        * ld-mips-elf/attr-gnu-4-45.d: Add missing "readelf" keyword.
diff --git a/ld/testsuite/ld-elf/needed1.out b/ld/testsuite/ld-elf/needed1.out
new file mode 100644 (file)
index 0000000..2c94e48
--- /dev/null
@@ -0,0 +1,2 @@
+OK
+OK
diff --git a/ld/testsuite/ld-elf/needed1a.c b/ld/testsuite/ld-elf/needed1a.c
new file mode 100644 (file)
index 0000000..8b23ec8
--- /dev/null
@@ -0,0 +1,7 @@
+extern void bar (void);
+
+void
+foo (void)
+{
+  bar ();
+}
diff --git a/ld/testsuite/ld-elf/needed1b.c b/ld/testsuite/ld-elf/needed1b.c
new file mode 100644 (file)
index 0000000..1b9b393
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+bar (void)
+{
+  printf ("OK\n");
+}
diff --git a/ld/testsuite/ld-elf/needed1c.c b/ld/testsuite/ld-elf/needed1c.c
new file mode 100644 (file)
index 0000000..e03c380
--- /dev/null
@@ -0,0 +1,10 @@
+extern void foo (void);
+extern void bar (void);
+
+int
+main ()
+{
+  foo ();
+  bar ();
+  return 0;
+}
index 9b35d53ef76e915bf041fbc2573d344e9e6f06ce..2e679d9fc7c8e282000f42a4ae747e057b339d31 100644 (file)
@@ -179,6 +179,15 @@ set build_tests {
   {"Build libpr14862.so"
    "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
    {pr14862-2.c} {} "libpr14862.so"}
+  {"Build libneeded1b.so"
+   "-shared" "-fPIC"
+   {needed1b.c} {} "libneeded1b.so"}
+  {"Build libneeded1a.so"
+   "-shared -Ltmpdir -lneeded1b" "-fPIC"
+   {needed1a.c} {} "libneeded1a.so"}
+  {"Build libneeded1c.o"
+   "-r -nostdlib" ""
+   {needed1c.c} {} "libneeded1c.o"}
 }
 
 run_cc_link_tests $build_tests
@@ -317,11 +326,33 @@ set run_tests {
     {"Run with pr14862-1.c libpr14862.so"
      "--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" ""
      {dummy.c} "pr14862" "pr14862.out"}
+    {"Link with --add-needed"
+     "tmpdir/libneeded1c.o --add-needed -rpath=tmpdir -Ltmpdir -lneeded1a" ""
+     {dummy.c} "needed1a" "needed1.out"}
+    {"Link with --copy-dt-needed-entries"
+     "tmpdir/libneeded1c.o --copy-dt-needed-entries -rpath=tmpdir -Ltmpdir -lneeded1a" ""
+     {dummy.c} "needed1b" "needed1.out"}
 }
 
 # NetBSD ELF systems do not currently support the .*_array sections.
 run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests
 
+# Check --no-add-needed and --no-copy-dt-needed-entries
+set testname "--no-add-needed"
+set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -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"
+set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -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 } {
     return