From f8f4abab9450704615a67a3f577345459ea6b718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 18 Oct 2026 22:49:08 +0200 Subject: [PATCH] Merge pull request '`std.debug.SelfInfo.MachO`: fix a few bugs' (#37318) from alexrp/zig:macos-unwind-stuff into master Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37318 --- lib/std/debug/SelfInfo/MachO.zig | 12 ++++++------ lib/std/macho.zig | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/std/debug/SelfInfo/MachO.zig b/lib/std/debug/SelfInfo/MachO.zig index 22430159cfd00e1efa57933a70af214b4b3803c3..f68572d1ca07fab3f0a9249f1bdf42c85ba9ee2e 100644 --- a/lib/std/debug/SelfInfo/MachO.zig +++ b/lib/std/debug/SelfInfo/MachO.zig @@ -417,7 +417,7 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize { const rules = try context.computeRules(gpa, dwarf, unwind.vmaddr_slide, encoding.value.arm64.dwarf); return context.next(gpa, &rules); }, - .FRAME => ip: { + .FRAME, .FRAME_PAUTH_LR => ip: { const frame = encoding.value.arm64.frame; const fp = (try dwarfRegNative(&context.cpu_state, fp_reg_num)).*; @@ -426,10 +426,10 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize { var reg_addr = fp - @sizeOf(usize); inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".field_names, 0..) |field_name, i| { if (@field(frame.x_reg_pairs, field_name) != 0) { - (try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*; - reg_addr += @sizeOf(usize); - (try dwarfRegNative(&context.cpu_state, 20 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*; - reg_addr += @sizeOf(usize); + (try dwarfRegNative(&context.cpu_state, 19 + i * 2)).* = @as(*const usize, @ptrFromInt(reg_addr)).*; + reg_addr -= @sizeOf(usize); + (try dwarfRegNative(&context.cpu_state, 20 + i * 2)).* = @as(*const usize, @ptrFromInt(reg_addr)).*; + reg_addr -= @sizeOf(usize); } } @@ -437,7 +437,7 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize { // vector registers in the AArch64 `cpu_context` anyway, so there's no reason to // fail a legitimate unwind just because we're asked to restore the registers here. // If some weird/broken unwind info tells us to read them later, we will fail then. - reg_addr += 16 * @as(usize, @popCount(@as(u4, @bitCast(frame.d_reg_pairs)))); + reg_addr -= 16 * @as(usize, @popCount(@as(u4, @bitCast(frame.d_reg_pairs)))); const new_ip = @as(*const usize, @ptrFromInt(ip_ptr)).*; const new_fp = @as(*const usize, @ptrFromInt(fp)).*; diff --git a/lib/std/macho.zig b/lib/std/macho.zig index 1e49fb5ce8a8e749ce3b79df01974c58585b8f61..9cbe321ef401d36a6738a80ceeb4e838ffdb44d8 100644 --- a/lib/std/macho.zig +++ b/lib/std/macho.zig @@ -2137,6 +2137,7 @@ pub const UNWIND_ARM64_MODE = enum(u4) { FRAMELESS = 2, DWARF = 3, FRAME = 4, + FRAME_PAUTH_LR = 5, }; pub const UNWIND_ARM64_FRAME_X19_X20_PAIR: u32 = 0x00000001; @@ -2189,13 +2190,14 @@ pub const CompactUnwindEncoding = packed struct(u32) { x25_x26: u1, x27_x28: u1, }, + unused: u3 = 0, d_reg_pairs: packed struct(u4) { d8_d9: u1, d10_d11: u1, d12_d13: u1, d14_d15: u1, }, - _: u15, + _: u12, }, frameless: packed struct(u24) { _: u12 = 0, -- 2.54.0