authorgravatar for lookatyouhacker@gmail.comShane Peelar <lookatyouhacker@gmail.com> 2024-06-06 20:04:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-08 16:02:47-04:00
logec337051a92b6f65bb29ddf41a290ea8e46b37b1
tree155587f8b88f26fd146d3a5c87e9ea7be37c640e
parent7ae9d8089d49d3bf04b5f248caf46fc095a71290

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.

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

lib/std/os/linux/start_pie.zig+1-1
......@@ -113,7 +113,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {
113113 const rela = std.mem.bytesAsSlice(elf.Rela, @as([*]u8, @ptrFromInt(rela_addr))[0..rela_size]);
114114 for (rela) |r| {
115115 if (r.r_type() != R_RELATIVE) continue;
116 @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr + @as(usize, @bitCast(r.r_addend));
116 @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* = base_addr + @as(usize, @bitCast(r.r_addend));
117117 }
118118 }
119119}