From 743623bc5464b3d1008a97531affd4da029ca9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 25 Feb 2025 08:10:12 +0100 Subject: [PATCH] link.MachO.UnwindInfo: Handle u24 overflow for CU records pointing to DWARF. Closes #23010. --- src/link/MachO/UnwindInfo.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/link/MachO/UnwindInfo.zig b/src/link/MachO/UnwindInfo.zig index cf8a49bed1..e831f50e87 100644 --- a/src/link/MachO/UnwindInfo.zig +++ b/src/link/MachO/UnwindInfo.zig @@ -68,7 +68,13 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void { for (info.records.items) |ref| { const rec = ref.getUnwindRecord(macho_file); if (rec.getFde(macho_file)) |fde| { - rec.enc.setDwarfSectionOffset(@intCast(fde.out_offset)); + // The unwinder will start looking for a matching CFI at the offset we specify here; it + // isn't actually an offset to the exact CFI for this record. A consequence of this is + // that if the offset doesn't fit in 24 bits, we can just leave it as zero so the + // unwinder starts searching at the beginning of the section. + if (std.math.cast(u24, fde.out_offset)) |off| { + rec.enc.setDwarfSectionOffset(off); + } if (fde.getLsdaAtom(macho_file)) |lsda| { rec.lsda = lsda.atom_index; rec.lsda_offset = fde.lsda_offset;