diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-11-13 12:47:38 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2018-01-09 09:28:59 -0800 |
commit | 37c28ba4dc86613d510cd8fafc16f2993a11254e (patch) | |
tree | 6bfe547d94ed9fb4ead76d48bd0a5430e16fcf48 | |
parent | 75f88a3cce479cad61b460efe2273997acb6b474 (diff) | |
download | binutils-gdb-37c28ba4dc86613d510cd8fafc16f2993a11254e.tar.gz |
ld: Add tests for -z separate-code and -z noseparate-code
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.
-rw-r--r-- | ld/testsuite/ld-elf/pr16322.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1.s | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1a.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1b.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1c.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1d.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1e.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1f.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-2a.c | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-2a.rd | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-2b.c | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-2b.rd | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/shared.exp | 71 |
13 files changed, 179 insertions, 1 deletions
diff --git a/ld/testsuite/ld-elf/pr16322.d b/ld/testsuite/ld-elf/pr16322.d index 40a7975cb06..348927b3842 100644 --- a/ld/testsuite/ld-elf/pr16322.d +++ b/ld/testsuite/ld-elf/pr16322.d @@ -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 index 00000000000..ffdb6209156 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1.s @@ -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 index 00000000000..f8dc0cc8f28 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1a.d @@ -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 index 00000000000..089d779591b --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1b.d @@ -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 index 00000000000..3476be30a55 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1c.d @@ -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 index 00000000000..c0d1051f554 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1d.d @@ -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 index 00000000000..673d3f76b5e --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1e.d @@ -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 index 00000000000..4c5de439ff6 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-1f.d @@ -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 index 00000000000..68fa4a0dd04 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-2a.c @@ -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 index 00000000000..b7ba1100952 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-2a.rd @@ -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 index 00000000000..3033809b02d --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-2b.c @@ -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 index 00000000000..b7ba1100952 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22393-2b.rd @@ -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/shared.exp b/ld/testsuite/ld-elf/shared.exp index 0c545688796..b9e5d403cdb 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -819,6 +819,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 \ @@ -956,6 +1001,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" \ + ] \ ] } |