authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-24 20:45:02+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-24 22:11:17+01:00
logad2be71514adb5f46176c80d6376e74df5f93c93
tree719f4b16b035d7911edde5f70d967ba9fb44280f
parentfefcdc56735744efaa53d26adc44b2c4ab1c8abb
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: Add test cases for PIC/PIE on various supported platforms.

Closes #22052.

4 files changed, 54 insertions(+), 0 deletions(-)

test/cases/pic_freestanding.zig created+14
......@@ -0,0 +1,14 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4fn _start() callconv(.naked) void {}
5
6comptime {
7 @export(&_start, .{ .name = if (builtin.cpu.arch.isMIPS()) "__start" else "_start" });
8}
9
10// compile
11// backend=stage2,llvm
12// target=arm-freestanding,armeb-freestanding,thumb-freestanding,thumbeb-freestanding,aarch64-freestanding,aarch64_be-freestanding,loongarch64-freestanding,mips-freestanding,mipsel-freestanding,mips64-freestanding,mips64el-freestanding,powerpc-freestanding,powerpcle-freestanding,powerpc64-freestanding,powerpc64le-freestanding,riscv32-freestanding,riscv64-freestanding,s390x-freestanding,x86-freestanding,x86_64-freestanding
13// pic=true
14// output_mode=Exe
test/cases/pic_linux.zig created+14
......@@ -0,0 +1,14 @@
1const std = @import("std");
2
3// Eventually, this test should be made to work without libc by providing our
4// own `__tls_get_addr` implementation. powerpcle-linux should be added to the
5// target list here when that happens.
6//
7// https://github.com/ziglang/zig/issues/20625
8pub fn main() void {}
9
10// run
11// backend=stage2,llvm
12// target=arm-linux,armeb-linux,thumb-linux,thumbeb-linux,aarch64-linux,aarch64_be-linux,loongarch64-linux,mips-linux,mipsel-linux,mips64-linux,mips64el-linux,powerpc-linux,powerpc64-linux,powerpc64le-linux,riscv32-linux,riscv64-linux,s390x-linux,x86-linux,x86_64-linux
13// pic=true
14// link_libc=true
test/cases/pie_freestanding.zig created+16
......@@ -0,0 +1,16 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4// The self-hosted backends currently output a bunch of bad relocations for PIE,
5// so this test is LLVM only for now.
6fn _start() callconv(.naked) void {}
7
8comptime {
9 @export(&_start, .{ .name = if (builtin.cpu.arch.isMIPS()) "__start" else "_start" });
10}
11
12// compile
13// backend=llvm
14// target=arm-freestanding,armeb-freestanding,thumb-freestanding,thumbeb-freestanding,aarch64-freestanding,aarch64_be-freestanding,loongarch64-freestanding,mips-freestanding,mipsel-freestanding,mips64-freestanding,mips64el-freestanding,powerpc-freestanding,powerpcle-freestanding,powerpc64-freestanding,powerpc64le-freestanding,riscv32-freestanding,riscv64-freestanding,s390x-freestanding,x86-freestanding,x86_64-freestanding
15// pie=true
16// output_mode=Exe
test/cases/pie_linux.zig created+10
......@@ -0,0 +1,10 @@
1const std = @import("std");
2
3// The self-hosted backends can't handle `.hidden _DYNAMIC` and `.weak _DYNAMIC`
4// directives in inline assembly yet, so this test is LLVM only for now.
5pub fn main() void {}
6
7// run
8// backend=llvm
9// target=arm-linux,armeb-linux,thumb-linux,thumbeb-linux,aarch64-linux,aarch64_be-linux,loongarch64-linux,mips-linux,mipsel-linux,mips64-linux,mips64el-linux,powerpc-linux,powerpcle-linux,powerpc64-linux,powerpc64le-linux,riscv32-linux,riscv64-linux,s390x-linux,x86-linux,x86_64-linux
10// pie=true