compiler: fix new panic handler in release builds

This commit is contained in:
mlugg 2025-09-10 12:53:03 +01:00
parent c1a30bd0d8
commit bfbbda7751
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E
2 changed files with 5 additions and 3 deletions

View file

@ -355,7 +355,7 @@ pub fn relocateContext(dest: *ThreadContext) void {
/// The value which is placed on the stack to make a copy of a `ThreadContext`. /// The value which is placed on the stack to make a copy of a `ThreadContext`.
const ThreadContextBuf = if (ThreadContext == noreturn) void else ThreadContext; const ThreadContextBuf = if (ThreadContext == noreturn) void else ThreadContext;
/// The pointer through which a `ThreadContext` is received from callers of stack tracing logic. /// The pointer through which a `ThreadContext` is received from callers of stack tracing logic.
const ThreadContextPtr = if (ThreadContext == noreturn) noreturn else *const ThreadContext; pub const ThreadContextPtr = if (ThreadContext == noreturn) noreturn else *const ThreadContext;
/// Capture the current context. The register values in the context will reflect the /// Capture the current context. The register values in the context will reflect the
/// state after the platform `getcontext` function returns. /// state after the platform `getcontext` function returns.
@ -1297,7 +1297,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
if (ThreadContext == noreturn) return handleSegfault(addr, name, null); if (ThreadContext == noreturn) return handleSegfault(addr, name, null);
// Some kernels don't align `ctx_ptr` properly, so we'll copy it into a local buffer. // Some kernels don't align `ctx_ptr` properly, so we'll copy it into a local buffer.
var copied_ctx: ThreadContextBuf = undefined; var copied_ctx: posix.ucontext_t = undefined;
const orig_ctx: *align(1) posix.ucontext_t = @ptrCast(ctx_ptr); const orig_ctx: *align(1) posix.ucontext_t = @ptrCast(ctx_ptr);
copied_ctx = orig_ctx.*; copied_ctx = orig_ctx.*;
if (builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) { if (builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) {

View file

@ -17,7 +17,7 @@ pub const debug = struct {
/// crash earlier than that. /// crash earlier than that.
pub var zig_argv0: []const u8 = "zig"; pub var zig_argv0: []const u8 = "zig";
fn handleSegfaultImpl(addr: ?usize, name: []const u8, opt_ctx: ?*std.debug.ThreadContext) noreturn { fn handleSegfaultImpl(addr: ?usize, name: []const u8, opt_ctx: ?std.debug.ThreadContextPtr) noreturn {
@branchHint(.cold); @branchHint(.cold);
dumpCrashContext() catch {}; dumpCrashContext() catch {};
std.debug.defaultHandleSegfault(addr, name, opt_ctx); std.debug.defaultHandleSegfault(addr, name, opt_ctx);
@ -56,6 +56,7 @@ pub const AnalyzeBody = if (build_options.enable_debug_extensions) struct {
current = ab.parent; current = ab.parent;
} }
} else struct { } else struct {
const current: ?noreturn = null;
// Dummy implementation, with functions marked `inline` to avoid interfering with tail calls. // Dummy implementation, with functions marked `inline` to avoid interfering with tail calls.
pub inline fn push(_: AnalyzeBody, _: *Sema, _: *Sema.Block, _: []const Zir.Inst.Index) void {} pub inline fn push(_: AnalyzeBody, _: *Sema, _: *Sema.Block, _: []const Zir.Inst.Index) void {}
pub inline fn pop(_: AnalyzeBody) void {} pub inline fn pop(_: AnalyzeBody) void {}
@ -75,6 +76,7 @@ pub const CodegenFunc = if (build_options.enable_debug_extensions) struct {
current = null; current = null;
} }
} else struct { } else struct {
const current: ?noreturn = null;
// Dummy implementation // Dummy implementation
pub fn start(_: *const Zcu, _: InternPool.Index) void {} pub fn start(_: *const Zcu, _: InternPool.Index) void {}
pub fn stop(_: InternPool.Index) void {} pub fn stop(_: InternPool.Index) void {}