Skip to content

Commit 843d91e

Browse files
kubkonandrewrk
andcommitted
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 #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 <[email protected]>
1 parent bea791b commit 843d91e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/std/debug.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,24 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
250250
resetSegfaultHandler();
251251
}
252252

253+
if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64)
254+
nosuspend {
255+
// As a workaround for not having threadlocal variable support in LLD for this target,
256+
// we have a simpler panic implementation that does not use threadlocal variables.
257+
// TODO https://github.com/ziglang/zig/issues/7527
258+
const stderr = io.getStdErr().writer();
259+
if (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst) == 0) {
260+
stderr.print("panic: " ++ format ++ "\n", args) catch os.abort();
261+
if (trace) |t| {
262+
dumpStackTrace(t.*);
263+
}
264+
dumpCurrentStackTrace(first_trace_addr);
265+
} else {
266+
stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort();
267+
}
268+
os.abort();
269+
};
270+
253271
nosuspend switch (panic_stage) {
254272
0 => {
255273
panic_stage = 1;

0 commit comments

Comments
 (0)