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(...@@ -4376,6 +4376,12 @@ fn initHeaders(
4376 assert(elf.targetLoad(&shdr.size) == elf.got.count() * @sizeOf(Addr));4376 assert(elf.targetLoad(&shdr.size) == elf.got.count() * @sizeOf(Addr));
4377 },4377 },
4378 }4378 }
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
4380 // Create any always-provided linker-defined symbols. The symbols marking the `INIT_ARRAY`/4386 // Create any always-provided linker-defined symbols. The symbols marking the `INIT_ARRAY`/
4381 // `FINI_ARRAY`/`PREINIT_ARRAY` sections are instead created by `createInitFiniArraySection`4387 // `FINI_ARRAY`/`PREINIT_ARRAY` sections are instead created by `createInitFiniArraySection`
...@@ -7187,6 +7193,7 @@ fn addGotRelocAssumeCapacity(...@@ -7187,6 +7193,7 @@ fn addGotRelocAssumeCapacity(
7187 });7193 });
7188}7194}
7189fn updateGotEntry(elf: *Elf, got_index: usize) void {7195fn updateGotEntry(elf: *Elf, got_index: usize) void {
7196 assert(elf.ehdrType() != .REL);
7190 const entry_value: union(enum) {7197 const entry_value: union(enum) {
7191 unsigned: u64,7198 unsigned: u64,
7192 signed: i64,7199 signed: i64,