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

Closes #22052.
This commit is contained in:
Alex Rønne Petersen 2024-11-24 20:45:02 +01:00
parent fefcdc5673
commit ad2be71514
No known key found for this signature in database
4 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,14 @@
const builtin = @import("builtin");
const std = @import("std");
fn _start() callconv(.naked) void {}
comptime {
@export(&_start, .{ .name = if (builtin.cpu.arch.isMIPS()) "__start" else "_start" });
}
// compile
// backend=stage2,llvm
// 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
// pic=true
// output_mode=Exe

14
test/cases/pic_linux.zig Normal file
View file

@ -0,0 +1,14 @@
const std = @import("std");
// Eventually, this test should be made to work without libc by providing our
// own `__tls_get_addr` implementation. powerpcle-linux should be added to the
// target list here when that happens.
//
// https://github.com/ziglang/zig/issues/20625
pub fn main() void {}
// run
// backend=stage2,llvm
// 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
// pic=true
// link_libc=true

View file

@ -0,0 +1,16 @@
const builtin = @import("builtin");
const std = @import("std");
// The self-hosted backends currently output a bunch of bad relocations for PIE,
// so this test is LLVM only for now.
fn _start() callconv(.naked) void {}
comptime {
@export(&_start, .{ .name = if (builtin.cpu.arch.isMIPS()) "__start" else "_start" });
}
// compile
// backend=llvm
// 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
// pie=true
// output_mode=Exe

10
test/cases/pie_linux.zig Normal file
View file

@ -0,0 +1,10 @@
const std = @import("std");
// The self-hosted backends can't handle `.hidden _DYNAMIC` and `.weak _DYNAMIC`
// directives in inline assembly yet, so this test is LLVM only for now.
pub fn main() void {}
// run
// backend=llvm
// 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
// pie=true