mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
macho: fix parsing addend for non-extern SIGNED_X reloc
If `r_extern == 0` (the relocation is non-extern, meaning it targets a specific memory offset within the object's section) and if the relocation type signifies that the relocation requires correction for RIP such as SIGNED_1, then we need to subtract the correction, here 1 for SIGNED_1, from the calculated addend value as it's implicitly included.
This commit is contained in:
parent
aa61e03f24
commit
7e27ab0947
@ -437,9 +437,11 @@ pub fn parseRelocs(self: *Atom, relocs: []macho.relocation_info, context: RelocC
|
||||
};
|
||||
addend = mem.readIntLittle(i32, self.code.items[offset..][0..4]) + correction;
|
||||
if (rel.r_extern == 0) {
|
||||
// Note for the future self: when r_extern == 0, we should subtract correction from the
|
||||
// addend.
|
||||
const seg = context.object.load_commands.items[context.object.segment_cmd_index.?].Segment;
|
||||
const target_sect_base_addr = seg.sections.items[rel.r_symbolnum - 1].addr;
|
||||
addend += @intCast(i64, context.base_addr + offset + correction + 4) -
|
||||
addend += @intCast(i64, context.base_addr + offset + 4) -
|
||||
@intCast(i64, target_sect_base_addr);
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user