ld: Add tests for -z separate-code and -z noseparate-code
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 12 Jan 2018 03:17:46 +0000 (19:17 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 12 Jan 2018 03:18:37 +0000 (19:18 -0800)
Verify that -z separate-code works and -z noseparate-code doesn't disable
-z relro.

PR ld/22393
* testsuite/ld-elf/pr16322.d: Add -z noseparate-code.
* testsuite/ld-elf/pr22393-1.s: New file.
* testsuite/ld-elf/pr22393-1a.d: Likewise.
* testsuite/ld-elf/pr22393-1b.d: Likewise.
* testsuite/ld-elf/pr22393-1c.d: Likewise.
* testsuite/ld-elf/pr22393-1d.d: Likewise.
* testsuite/ld-elf/pr22393-1e.d: Likewise.
* testsuite/ld-elf/pr22393-1f.d: Likewise.
* testsuite/ld-elf/pr22393-2a.c: Likewise.
* testsuite/ld-elf/pr22393-2a.rd: Likewise.
* testsuite/ld-elf/pr22393-2b.c: Likewise.
* testsuite/ld-elf/pr22393-2b.rd: Likewise.
* testsuite/ld-elf/shared.exp: Run tests for -z separate-code.

14 files changed:
ld/ChangeLog
ld/testsuite/ld-elf/pr16322.d
ld/testsuite/ld-elf/pr22393-1.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1a.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1b.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1c.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1d.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1e.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-1f.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-2a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-2a.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-2b.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr22393-2b.rd [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 28ce852de2776d8ff464a5a2ed07b9728cee783b..5b9e3b9e0e67931546f7c30d12517f080b2ced4a 100644 (file)
@@ -1,3 +1,20 @@
+2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22393
+       * testsuite/ld-elf/pr16322.d: Add -z noseparate-code.
+       * testsuite/ld-elf/pr22393-1.s: New file.
+       * testsuite/ld-elf/pr22393-1a.d: Likewise.
+       * testsuite/ld-elf/pr22393-1b.d: Likewise.
+       * testsuite/ld-elf/pr22393-1c.d: Likewise.
+       * testsuite/ld-elf/pr22393-1d.d: Likewise.
+       * testsuite/ld-elf/pr22393-1e.d: Likewise.
+       * testsuite/ld-elf/pr22393-1f.d: Likewise.
+       * testsuite/ld-elf/pr22393-2a.c: Likewise.
+       * testsuite/ld-elf/pr22393-2a.rd: Likewise.
+       * testsuite/ld-elf/pr22393-2b.c: Likewise.
+       * testsuite/ld-elf/pr22393-2b.rd: Likewise.
+       * testsuite/ld-elf/shared.exp: Run tests for -z separate-code.
+
 2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22393
index 40a7975cb060cca1ac81b0789b3b48067fe92d43..348927b38429418900a1d135df9ccce031aa2f9f 100644 (file)
@@ -1,4 +1,4 @@
-#ld: -shared -z relro
+#ld: -shared -z relro -z noseparate-code
 #readelf: -l --wide
 #target: *-*-linux-gnu *-*-gnu* *-*-nacl*
 
diff --git a/ld/testsuite/ld-elf/pr22393-1.s b/ld/testsuite/ld-elf/pr22393-1.s
new file mode 100644 (file)
index 0000000..ffdb620
--- /dev/null
@@ -0,0 +1,21 @@
+       .section .rodata,"a",%progbits
+       .globl  fx1
+       .type   fx1, %object
+fx1:
+       .zero   20
+       .section .data.rel.ro,"aw",%progbits
+       .globl  px1
+       .type   px1, %object
+px1:
+       .dc.a   fx1
+
+       .text
+       .global start   /* Used by SH targets.  */
+start:
+       .global _start
+_start:
+       .global __start
+__start:
+       .global main    /* Used by HPPA targets.  */
+main:
+       .dc.a 0
diff --git a/ld/testsuite/ld-elf/pr22393-1a.d b/ld/testsuite/ld-elf/pr22393-1a.d
new file mode 100644 (file)
index 0000000..f8dc0cc
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -shared -z separate-code -z relro
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-1b.d b/ld/testsuite/ld-elf/pr22393-1b.d
new file mode 100644 (file)
index 0000000..089d779
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -shared -z relro -z separate-code
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*.text.*(.eh_frame|\.rodata).*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-1c.d b/ld/testsuite/ld-elf/pr22393-1c.d
new file mode 100644 (file)
index 0000000..3476be3
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -pie -z separate-code
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-1d.d b/ld/testsuite/ld-elf/pr22393-1d.d
new file mode 100644 (file)
index 0000000..c0d1051
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -pie -z separate-code
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*.text.*(.eh_frame|\.rodata).*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d
new file mode 100644 (file)
index 0000000..673d3f7
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -z separate-code
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d
new file mode 100644 (file)
index 0000000..4c5de43
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -z separate-code
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*.text.*(.eh_frame|\.rodata).*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-2a.c b/ld/testsuite/ld-elf/pr22393-2a.c
new file mode 100644 (file)
index 0000000..68fa4a0
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+test()
+{
+  printf ("PASS\n");
+}
diff --git a/ld/testsuite/ld-elf/pr22393-2a.rd b/ld/testsuite/ld-elf/pr22393-2a.rd
new file mode 100644 (file)
index 0000000..b7ba110
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -shared -z textonly
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
+#...
diff --git a/ld/testsuite/ld-elf/pr22393-2b.c b/ld/testsuite/ld-elf/pr22393-2b.c
new file mode 100644 (file)
index 0000000..3033809
--- /dev/null
@@ -0,0 +1,7 @@
+void test(void);
+
+int main()
+{
+  test();
+  return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr22393-2b.rd b/ld/testsuite/ld-elf/pr22393-2b.rd
new file mode 100644 (file)
index 0000000..b7ba110
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr22393-1.s
+#ld: -shared -z textonly
+#readelf: -l --wide
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
+
+#failif
+#...
+ +[0-9]+  +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
+#...
index 95bac37900111e145e47b867e1a0513685da9892..1247fd217cc300ff0d1c535fbc626dac008f7c80 100644 (file)
@@ -864,6 +864,51 @@ if { [istarget *-*-linux*]
            {} \
            "libpr19579.so" \
        ] \
+       [list \
+           "Build pr22393-2a.so" \
+           "-shared -Wl,-z,separate-code" \
+           "-fPIC" \
+           {pr22393-2a.c} \
+           {{readelf -lW pr22393-2a.rd} \
+            {readelf -lW pr22393-2b.rd}} \
+           "pr22393-2a.so" \
+       ] \
+       [list \
+           "Build pr22393-2a-now.so" \
+           "-shared -Wl,-z,separate-code,-z,now" \
+           "-fPIC" \
+           {pr22393-2a.c} \
+           {{readelf -lW pr22393-2a.rd} \
+            {readelf -lW pr22393-2b.rd}} \
+           "pr22393-2a-now.so" \
+       ] \
+       [list \
+           "Build pr22393-2" \
+           "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
+           "$NOPIE_CFLAGS" \
+           {pr22393-2b.c} \
+           {{readelf -lW pr22393-2a.rd} \
+            {readelf -lW pr22393-2b.rd}} \
+           "pr22393-2" \
+       ] \
+       [list \
+           "Build pr22393-2 (PIE)" \
+           "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
+           "-fPIE" \
+           {pr22393-2b.c} \
+           {{readelf -lW pr22393-2a.rd} \
+            {readelf -lW pr22393-2b.rd}} \
+           "pr22393-2-pie" \
+       ] \
+       [list \
+           "Build pr22393-2 (static)" \
+           "-static -Wl,-z,separate-code" \
+           "" \
+           {pr22393-2a.c pr22393-2b.c} \
+           {{readelf -lW pr22393-2a.rd} \
+            {readelf -lW pr22393-2b.rd}} \
+           "pr22393-2-static" \
+       ] \
     ]
     run_ld_link_exec_tests [list \
        [list \
@@ -1001,6 +1046,32 @@ if { [istarget *-*-linux*]
            "pass.out" \
            "-fPIE" \
        ] \
+       [list \
+           "Run pr22393-2" \
+           "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
+           "" \
+           {pr22393-2b.c} \
+           "pr22393-2" \
+           "pass.out" \
+           "$NOPIE_CFLAGS" \
+       ] \
+       [list \
+           "Run pr22393-2 (PIE)" \
+           "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
+           "" \
+           {pr22393-2b.c} \
+           "pr22393-2-pie" \
+           "pass.out" \
+           "-fPIE" \
+       ] \
+       [list \
+           "Run pr22393-2 (static)" \
+           "-static -Wl,-z,separate-code" \
+           "" \
+           {pr22393-2a.c pr22393-2b.c} \
+           "pr22393-2-static" \
+           "pass.out" \
+       ] \
     ]
 }