commit 71e1d7cb8bfe52ccf82f5ba64d1c5d6c5b5077fc (tree)
parent 30f4b05b5f733b57e5e821de9e0ecdc53711a57c
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Mon, 25 May 2026 06:41:30 +0100
codegen.x86_64: fix Elf2 relocations under PIC
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/codegen/x86_64/Emit.zig b/src/codegen/x86_64/Emit.zig
@@ -850,8 +850,12 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
emit.atom_id,
end_offset - 4,
target.symbol,
- reloc.off,
- .{ .X86_64 = .@"32S" },
+ if (emit.pic) reloc.off - 4 else reloc.off,
+ .{ .X86_64 = rt: {
+ if (!emit.pic) break :rt .@"32S";
+ if (target.is_extern and !target.force_pcrel_direct) break :rt .GOTPCREL;
+ break :rt .PC32;
+ } },
) else if (emit.bin_file.cast(.coff2)) |coff| try coff.addReloc(
@enumFromInt(@intFromEnum(emit.atom_id)),
end_offset - 4,