From 843d91e75d166ac41d7c9b27b86b236f14865e31 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 21 Jan 2021 20:34:00 +0100 Subject: Bring back stack trace printing on ARM Darwin This temporary patch fixes a segfault caused by miscompilation by the LLD when generating stubs for initialization of thread local storage. We effectively bypass TLS in the default panic handler so that no segfault is generated and the stack trace is correctly reported back to the user. Note that, this is linked directly to a bigger issue with LLD ziglang/zig#7527 and when resolved, we only need to remove the `comptime` code path introduced with this patch to use the default panic handler that relies on TLS. Co-authored-by: Andrew Kelley --- lib/std/debug.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/std/debug.zig') diff --git a/lib/std/debug.zig b/lib/std/debug.zig index e4ef25724b..a434fe0e8b 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -250,6 +250,24 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c resetSegfaultHandler(); } + if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64) + nosuspend { + // As a workaround for not having threadlocal variable support in LLD for this target, + // we have a simpler panic implementation that does not use threadlocal variables. + // TODO https://github.com/ziglang/zig/issues/7527 + const stderr = io.getStdErr().writer(); + if (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst) == 0) { + stderr.print("panic: " ++ format ++ "\n", args) catch os.abort(); + if (trace) |t| { + dumpStackTrace(t.*); + } + dumpCurrentStackTrace(first_trace_addr); + } else { + stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort(); + } + os.abort(); + }; + nosuspend switch (panic_stage) { 0 => { panic_stage = 1; -- cgit v1.2.3