authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-26 08:07:45+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-26 08:11:04+02:00
loga6ab35353293531d1b04cc18b667729fd5ee280e
tree26b62c401e52c15e6bef0f52914845b8caafcdb3
parent5143239e2bcc41f6aba8a56b73810f2f9965feb4
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.pie: add xtensa support

This might need more work to handle the DT_XTENSA_GOT_LOC_{OFF,SZ} insanity, but this is at least a start.

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

lib/std/pie.zig+21
......@@ -22,6 +22,7 @@ const R_RISCV_RELATIVE = 3;
2222const R_390_RELATIVE = 12;
2323const R_SH_RELATIVE = 165;
2424const R_SPARC_RELATIVE = 22;
25const R_XTENSA_RELATIVE = 5;
2526
2627const R_RELATIVE = switch (builtin.cpu.arch) {
2728 .x86 => R_386_RELATIVE,
......@@ -43,6 +44,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) {
4344 .s390x => R_390_RELATIVE,
4445 .sh, .sheb => R_SH_RELATIVE,
4546 .sparc, .sparc64 => R_SPARC_RELATIVE,
47 .xtensa, .xtensaeb => R_XTENSA_RELATIVE,
4648 else => @compileError("Missing R_RELATIVE definition for this target"),
4749};
4850
......@@ -261,6 +263,25 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
261263 : [ret] "=r" (-> [*]const elf.Dyn),
262264 :
263265 : .{ .l7 = true }),
266 .xtensa, .xtensaeb => asm volatile (
267 \\ .weak _DYNAMIC
268 \\ .hidden _DYNAMIC
269 // Set things up such that after the `call0`, `a0` will point 1 byte before the
270 // embedded constant. Note that `call0` is a 3-byte instruction, so we need both
271 // `.balign` directives to be safe.
272 \\ .balign 4
273 \\ .begin no-transform
274 \\ call0 1f
275 \\ .end no-transform
276 \\ .balign 4
277 \\ .word _DYNAMIC - .
278 \\1:
279 \\ add a0, a0, 1
280 \\ l32i a8, a0, 0
281 \\ add %[ret], a0, a8
282 : [ret] "=a" (-> [*]const elf.Dyn),
283 :
284 : .{ .a0 = true, .a8 = true }),
264285 else => {
265286 @compileError("PIE startup is not yet supported for this target!");
266287 },