Skip to content

Commit ec33705

Browse files
InBetweenNamesandrewrk
authored andcommitted
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 parent 7ae9d80 commit ec33705

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/std/os/linux/start_pie.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)