Skip to content

Commit

Permalink
macho: fix applying __eh_frame records after -r
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 4, 2024
1 parent 1863406 commit 5012a81
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/MachO/Object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ fn initEhFrameRecords(self: *Object, sect_id: u8, macho_file: *MachO) !void {
for (relocs.items, 0..) |rel, i| {
switch (rel.type) {
.unsigned => {
// TODO this is actually incorrect
assert(rel.meta.length == 3 and rel.meta.has_subtractor); // TODO error
assert((rel.meta.length == 2 or rel.meta.length == 3) and rel.meta.has_subtractor); // TODO error
const S: i64 = switch (rel.tag) {
.local => rel.meta.symbolnum,
.@"extern" => @intCast(nlists[rel.meta.symbolnum].n_value),
Expand All @@ -603,7 +602,11 @@ fn initEhFrameRecords(self: *Object, sect_id: u8, macho_file: *MachO) !void {
.@"extern" => @intCast(nlists[sub_rel.meta.symbolnum].n_value),
};
};
mem.writeInt(u64, self.eh_frame_data.items[rel.offset..][0..8], @bitCast(S + A - SUB), .little);
switch (rel.meta.length) {
0, 1 => unreachable,
2 => mem.writeInt(u32, self.eh_frame_data.items[rel.offset..][0..4], @bitCast(@as(i32, @truncate(S + A - SUB))), .little),
3 => mem.writeInt(u64, self.eh_frame_data.items[rel.offset..][0..8], @bitCast(S + A - SUB), .little),
}
},
else => {},
}
Expand Down

0 comments on commit 5012a81

Please sign in to comment.