Skip to content

Commit

Permalink
zacho: sort relocs in unwind info accounting for -r mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 31, 2023
1 parent 4852da8 commit 607f4b4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ZachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,21 @@ pub fn printUnwindInfo(self: *const ZachO, writer: anytype) !void {

const num_entries = @divExact(data.len, @sizeOf(macho.compact_unwind_entry));
const entries = @as([*]align(1) const macho.compact_unwind_entry, @ptrCast(data))[0..num_entries];
const relocs = @as([*]align(1) const macho.relocation_info, @ptrCast(self.data.ptr + sect.reloff))[0..sect.nreloc];
const relocs = relocs: {
const relocs = @as([*]align(1) const macho.relocation_info, @ptrCast(self.data.ptr + sect.reloff))[0..sect.nreloc];
const out = try self.gpa.alloc(macho.relocation_info, relocs.len);
@memcpy(out, relocs);
break :relocs out;
};
defer self.gpa.free(relocs);

const sortFn = struct {
fn sortFn(ctx: void, lhs: macho.relocation_info, rhs: macho.relocation_info) bool {
_ = ctx;
return lhs.r_address > rhs.r_address;
}
}.sortFn;
mem.sort(macho.relocation_info, relocs, {}, sortFn);

try writer.writeAll("Contents of __LD,__compact_unwind section:\n");

Expand Down

0 comments on commit 607f4b4

Please sign in to comment.