authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-14 07:47:00-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-14 11:47:00+00:00
log094cd92615f906116e68fe6a665122b58f66cd3b
treeb40ba27bb6d5480d895183c6c1f9b251b1f96c14
parentb177e17d155c2f300188d82ea2753bbfd5d29038
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

macho: fix __unwind_info sentinel entry not always being the upper bound (#16395)

macho: record highest address of unwind records before folding --------- Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>

1 files changed, 13 insertions(+), 3 deletions(-)

src/link/MachO/UnwindInfo.zig+13-3
......@@ -44,6 +44,9 @@ lsdas_lookup: std.AutoHashMapUnmanaged(RecordIndex, u32) = .{},
4444/// List of second level pages.
4545pages: std.ArrayListUnmanaged(Page) = .{},
4646
47/// Upper bound (exclusive) of all the record ranges
48end_boundary: u64 = 0,
49
4750const RecordIndex = u32;
4851
4952const max_personalities = 3;
......@@ -327,6 +330,13 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
327330 }
328331 }
329332
333 // Record the ending boundary before folding.
334 assert(records.items.len > 0);
335 info.end_boundary = blk: {
336 const last_record = records.items[records.items.len - 1];
337 break :blk last_record.rangeStart + last_record.rangeLength;
338 };
339
330340 // Fold records
331341 try info.records.ensureTotalCapacity(info.gpa, records.items.len);
332342 try info.records_lookup.ensureTotalCapacity(info.gpa, @as(u32, @intCast(atom_indexes.items.len)));
......@@ -629,10 +639,10 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
629639 });
630640 }
631641
632 const last_entry = info.records.items[info.records.items.len - 1];
633 const sentinel_address = @as(u32, @intCast(last_entry.rangeStart + last_entry.rangeLength));
642 // Relocate end boundary address
643 const end_boundary = @as(u32, @intCast(info.end_boundary + text_sect.addr - seg.vmaddr));
634644 try writer.writeStruct(macho.unwind_info_section_header_index_entry{
635 .functionOffset = sentinel_address,
645 .functionOffset = end_boundary,
636646 .secondLevelPagesSectionOffset = 0,
637647 .lsdaIndexArraySectionOffset = lsda_base_offset +
638648 @as(u32, @intCast(info.lsdas.items.len)) * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),