authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-12 17:39:59+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-11 00:10:17+01:00
log7d0087707634028308d3a870883249bfa59d94b8
treefd8ffc793bba2194d5e7ee47127d1898e9799b6a
parent43b6bd42434cdc71e3405b4d5c3a36f6ff76ed01
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Extend DWARF unwinding protection to more architectures.

The function is not marked .cantunwind for Arm/Thumb because of an LLVM assembler bug: https://github.com/llvm/llvm-project/issues/115891

1 files changed, 23 insertions(+), 1 deletions(-)

lib/std/start.zig+23-1
......@@ -230,6 +230,29 @@ fn _start() callconv(.naked) noreturn {
230230 );
231231 }
232232
233 // This is the first userspace frame. Prevent DWARF-based unwinders from unwinding further. We
234 // prevent FP-based unwinders from unwinding further by zeroing the register further below.
235 asm volatile (switch (native_arch) {
236 .arc => ".cfi_undefined blink",
237 .arm, .armeb, .thumb, .thumbeb => "", // https://github.com/llvm/llvm-project/issues/115891
238 .aarch64, .aarch64_be => ".cfi_undefined lr",
239 .csky => ".cfi_undefined lr",
240 .hexagon => ".cfi_undefined r31",
241 .loongarch32, .loongarch64 => ".cfi_undefined 1",
242 .m68k => ".cfi_undefined pc",
243 .mips, .mipsel, .mips64, .mips64el => ".cfi_undefined $ra",
244 .powerpc, .powerpcle, .powerpc64, .powerpc64le => ".cfi_undefined lr",
245 .riscv32, .riscv64 => if (builtin.zig_backend == .stage2_riscv64)
246 ""
247 else
248 ".cfi_undefined ra",
249 .s390x => ".cfi_undefined %%r14",
250 .sparc, .sparc64 => ".cfi_undefined %%i7",
251 .x86 => ".cfi_undefined %%eip",
252 .x86_64 => ".cfi_undefined %%rip",
253 else => @compileError("unsupported arch"),
254 });
255
233256 // Move this to the riscv prong below when this is resolved: https://github.com/ziglang/zig/issues/20918
234257 if (builtin.cpu.arch.isRISCV() and builtin.zig_backend != .stage2_riscv64) asm volatile (
235258 \\ .weak __global_pointer$
......@@ -247,7 +270,6 @@ fn _start() callconv(.naked) noreturn {
247270 // linker explicitly.
248271 asm volatile (switch (native_arch) {
249272 .x86_64 =>
250 \\ .cfi_undefined %%rip
251273 \\ xorl %%ebp, %%ebp
252274 \\ movq %%rsp, %%rdi
253275 \\ andq $-16, %%rsp