mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
Fix slight deviation from spec in handling Elf*_Rela relative relocations
`Elf*_Rela` relocations store their argument in `r_addend`, including for `R_*_RELATIVE` relocations. Unlike `Elf*_Rel` relocations, they are not applied as a delta to the destination virtual address. Instead, they are computed from `base_address + r_addend` directly.
This commit is contained in:
parent
7ae9d8089d
commit
ec337051a9
@ -113,7 +113,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {
|
|||||||
const rela = std.mem.bytesAsSlice(elf.Rela, @as([*]u8, @ptrFromInt(rela_addr))[0..rela_size]);
|
const rela = std.mem.bytesAsSlice(elf.Rela, @as([*]u8, @ptrFromInt(rela_addr))[0..rela_size]);
|
||||||
for (rela) |r| {
|
for (rela) |r| {
|
||||||
if (r.r_type() != R_RELATIVE) continue;
|
if (r.r_type() != R_RELATIVE) continue;
|
||||||
@as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr + @as(usize, @bitCast(r.r_addend));
|
@as(*usize, @ptrFromInt(base_addr + r.r_offset)).* = base_addr + @as(usize, @bitCast(r.r_addend));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user