authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-10-27 16:43:27+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-29 14:38:48-04:00
logad6e095ef676ab50799a49eb40419b1ff926e6d7
tree73b1ab2059c70a6c48e152aa9f1ee2eb778c322b
parent4fb896f16ebdc9dc6a04a522550524613d467dae

stage2.Elf: fix off by one error in writeOffsetTableEntry

The code was using the length of the local symbols, which also includes the null symbol. Fix this by using the offset table instead, which only keeps track of the symbols that end up in the got.

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

src/link/Elf.zig+1-1
...@@ -2706,7 +2706,7 @@ fn writeOffsetTableEntry(self: *Elf, index: usize) !void {...@@ -2706,7 +2706,7 @@ fn writeOffsetTableEntry(self: *Elf, index: usize) !void {
2706 if (self.offset_table_count_dirty) {2706 if (self.offset_table_count_dirty) {
2707 // TODO Also detect virtual address collisions.2707 // TODO Also detect virtual address collisions.
2708 const allocated_size = self.allocatedSize(shdr.sh_offset);2708 const allocated_size = self.allocatedSize(shdr.sh_offset);
2709 const needed_size = self.local_symbols.items.len * entry_size;2709 const needed_size = self.offset_table.items.len * entry_size;
2710 if (needed_size > allocated_size) {2710 if (needed_size > allocated_size) {
2711 // Must move the entire got section.2711 // Must move the entire got section.
2712 const new_offset = self.findFreeSpace(needed_size, entry_size);2712 const new_offset = self.findFreeSpace(needed_size, entry_size);