authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-25 11:18:42-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-25 11:18:42-08:00
log466ce48e4c315bdd59bd0f5700fe4d32c15d3d8c
tree1e5d1f809b843749d22b9e1c83a82773d998858d
parent743623bc5464b3d1008a97531affd4da029ca9cb

link.MachO.UnwindInfo: reproduce lld's comment

it explains why zero is used instead of saturation

1 files changed, 12 insertions(+), 7 deletions(-)

src/link/MachO/UnwindInfo.zig+12-7
......@@ -68,13 +68,18 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void {
6868 for (info.records.items) |ref| {
6969 const rec = ref.getUnwindRecord(macho_file);
7070 if (rec.getFde(macho_file)) |fde| {
71 // The unwinder will start looking for a matching CFI at the offset we specify here; it
72 // isn't actually an offset to the exact CFI for this record. A consequence of this is
73 // that if the offset doesn't fit in 24 bits, we can just leave it as zero so the
74 // unwinder starts searching at the beginning of the section.
75 if (std.math.cast(u24, fde.out_offset)) |off| {
76 rec.enc.setDwarfSectionOffset(off);
77 }
71 // The unwinder will look for the DWARF entry starting at the hint,
72 // assuming the hint points to a valid CFI record start. If it
73 // fails to find the record, it proceeds in a linear search through
74 // the contiguous CFI records from the hint until the end of the
75 // section. Ideally, in the case where the offset is too large to
76 // be encoded, we would instead encode the largest possible offset
77 // to a valid CFI record, but since we don't keep track of that,
78 // just encode zero -- the start of the section is always the start
79 // of a CFI record.
80 const hint = std.math.cast(u24, fde.out_offset) orelse 0;
81 rec.enc.setDwarfSectionOffset(hint);
82
7883 if (fde.getLsdaAtom(macho_file)) |lsda| {
7984 rec.lsda = lsda.atom_index;
8085 rec.lsda_offset = fde.lsda_offset;