authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-01-21 20:34:00+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-01-21 23:20:42+01:00
log843d91e75d166ac41d7c9b27b86b236f14865e31
treede1c2ec0ce1953b03b881726f7b74dd17b62b146
parentbea791b63992d57501c0f878408923806650069b

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 <andrew@ziglang.org>

1 files changed, 18 insertions(+), 0 deletions(-)

lib/std/debug.zig+18
......@@ -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;