authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-26 09:53:34+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-29 12:24:14+01:00
log13f71bb636b3912952297c4b615edcc64c73a918
treecca6a1051b0f01c3f9d1da4ddc0bcd066c0714e8
parent3d4aabdf795edcb1e131ed3a2e3c2910d8343c85
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: initialize GOT header entries properly

Previously these weren't being written until flush, which meant we hadn't reserved capacity for them in `.rela.dyn`, so if they needed runtime relocations we might hit Illegal Behavior when adding that relocation in `updateGotEntry`.

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

src/link/Elf2.zig+7
......@@ -4376,6 +4376,12 @@ fn initHeaders(
43764376 assert(elf.targetLoad(&shdr.size) == elf.got.count() * @sizeOf(Addr));
43774377 },
43784378 }
4379 if (elf.shndx.dynamic != .UNDEF) {
4380 try elf.shndx.rela_dyn.relaEnsureAdditionalCapacity(elf, elf.got.count());
4381 }
4382 for (0..elf.got.count()) |got_index| {
4383 elf.updateGotEntry(got_index);
4384 }
43794385
43804386 // Create any always-provided linker-defined symbols. The symbols marking the `INIT_ARRAY`/
43814387 // `FINI_ARRAY`/`PREINIT_ARRAY` sections are instead created by `createInitFiniArraySection`
......@@ -7187,6 +7193,7 @@ fn addGotRelocAssumeCapacity(
71877193 });
71887194}
71897195fn updateGotEntry(elf: *Elf, got_index: usize) void {
7196 assert(elf.ehdrType() != .REL);
71907197 const entry_value: union(enum) {
71917198 unsigned: u64,
71927199 signed: i64,