authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-13 20:55:16+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-16 10:37:19+01:00
log52dd990f80500e685cc37edd8de271036e24e0f8
treec794eaa4708bde35e2331d9a7461f3c5f77c61c6
parent67e525d546ec87000bc1148de61916abcf1d91fb
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: PLT fixes


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

src/link/Elf2.zig+19-2
...@@ -8267,9 +8267,9 @@ fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void...@@ -8267,9 +8267,9 @@ fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void
8267 const plt_slice: []Inst = @ptrCast(@alignCast(plt_ni.slice(&elf.mf)[@intCast(got_plt_offset)..][0..32]));8267 const plt_slice: []Inst = @ptrCast(@alignCast(plt_ni.slice(&elf.mf)[@intCast(got_plt_offset)..][0..32]));
8268 @memcpy(plt_slice, &[8]Inst{8268 @memcpy(plt_slice, &[8]Inst{
8269 // sethi (. - .plt[0]), %g18269 // sethi (. - .plt[0]), %g1
8270 .{ .imm22 = .{ .imm = @truncate(got_plt_offset), .op = 0b0000000011 } },8270 .{ .imm22 = .{ .imm = @truncate(got_plt_offset), .op = 0b0000001100 } },
8271 // ba,a %xcc, .plt[1]8271 // ba,a %xcc, .plt[1]
8272 .{ .disp19 = .{ .disp = @truncate((got_plt_offset + 4 - 32) >> 2), .op = 0b1100001101000 } },8272 .{ .disp19 = .{ .disp = @truncate((got_plt_offset + 4 - 32) >> 2), .op = 0b0011000001101 } },
8273 // nop8273 // nop
8274 .{ .raw = 0x0100_0000 },8274 .{ .raw = 0x0100_0000 },
8275 // nop8275 // nop
...@@ -8283,6 +8283,9 @@ fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void...@@ -8283,6 +8283,9 @@ fn addPltEntry(elf: *Elf, global_name: String(.strtab), dynsym_index: u32) void
8283 // nop8283 // nop
8284 .{ .raw = 0x0100_0000 },8284 .{ .raw = 0x0100_0000 },
8285 });8285 });
8286 if (elf.targetEndian() != std.lang.Endian.native) {
8287 std.mem.byteSwapAllElements(Inst, plt_slice);
8288 }
8286 },8289 },
8287 }8290 }
8288 },8291 },
...@@ -8353,6 +8356,13 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -8353,6 +8356,13 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
8353 .LOONGARCH => {8356 .LOONGARCH => {
8354 switch (which) {8357 switch (which) {
8355 .plt => {8358 .plt => {
8359 // Re-apply all PLT relocations. If a symbol is in the PLT then the majority of
8360 // its relocations are probably going through the PLT, so we don't bother with
8361 // specific tracking for PLT relocations---instead just re-apply all relocations
8362 // targeting symbols with PLT entries.
8363 for (elf.plt.keys()) |name| {
8364 Symbol.Id.global(name).applyTargetRelocs(elf);
8365 }
8356 // We also need to update all of the references from `.plt` to `.got.plt`.8366 // We also need to update all of the references from `.plt` to `.got.plt`.
8357 // However, if there's also a flush pending for `.got.plt`, don't bother doing8367 // However, if there's also a flush pending for `.got.plt`, don't bother doing
8358 // this now, because we'll do it when `.got.plt` is flushed anyway.8368 // this now, because we'll do it when `.got.plt` is flushed anyway.
...@@ -8413,6 +8423,13 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad...@@ -8413,6 +8423,13 @@ fn flushMovedPltSection(elf: *Elf, which: enum { plt, plt_sec, got_plt }, old_ad
8413 },8423 },
8414 .SPARCV9 => switch (which) {8424 .SPARCV9 => switch (which) {
8415 .plt => {8425 .plt => {
8426 // Re-apply all PLT relocations. If a symbol is in the PLT then the majority of
8427 // its relocations are probably going through the PLT, so we don't bother with
8428 // specific tracking for PLT relocations---instead just re-apply all relocations
8429 // targeting symbols with PLT entries.
8430 for (elf.plt.keys()) |name| {
8431 Symbol.Id.global(name).applyTargetRelocs(elf);
8432 }
8416 // Update the offsets of the relocation entries in `.rela.plt`.8433 // Update the offsets of the relocation entries in `.rela.plt`.
8417 const rela_plt_shndx = elf.shndx.rela_plt;8434 const rela_plt_shndx = elf.shndx.rela_plt;
8418 for (0..elf.plt.count()) |plt_index| {8435 for (0..elf.plt.count()) |plt_index| {