commit e902c231c85890fdba486db3469e1aaf0de83da5 (tree)
parent ad5515bed8789cb7688b3bd6c098be3a16b16d47
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 25 Feb 2025 14:19:36 -0500
Merge pull request #23011 from alexrp/macho-cu-intcast
`link.MachO.UnwindInfo`: Handle `u24` overflow for CU records pointing to DWARF.
Diffstat:
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/link/MachO/UnwindInfo.zig b/src/link/MachO/UnwindInfo.zig
@@ -68,7 +68,18 @@ 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 look for the DWARF entry starting at the hint,
+ // assuming the hint points to a valid CFI record start. If it
+ // fails to find the record, it proceeds in a linear search through
+ // the contiguous CFI records from the hint until the end of the
+ // section. Ideally, in the case where the offset is too large to
+ // be encoded, we would instead encode the largest possible offset
+ // to a valid CFI record, but since we don't keep track of that,
+ // just encode zero -- the start of the section is always the start
+ // of a CFI record.
+ const hint = std.math.cast(u24, fde.out_offset) orelse 0;
+ rec.enc.setDwarfSectionOffset(hint);
+
if (fde.getLsdaAtom(macho_file)) |lsda| {
rec.lsda = lsda.atom_index;
rec.lsda_offset = fde.lsda_offset;