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;...@@ -22,6 +22,7 @@ const R_RISCV_RELATIVE = 3;
22const R_390_RELATIVE = 12;22const R_390_RELATIVE = 12;
23const R_SH_RELATIVE = 165;23const R_SH_RELATIVE = 165;
24const R_SPARC_RELATIVE = 22;24const R_SPARC_RELATIVE = 22;
25const R_XTENSA_RELATIVE = 5;
2526
26const R_RELATIVE = switch (builtin.cpu.arch) {27const R_RELATIVE = switch (builtin.cpu.arch) {
27 .x86 => R_386_RELATIVE,28 .x86 => R_386_RELATIVE,
...@@ -43,6 +44,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) {...@@ -43,6 +44,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) {
43 .s390x => R_390_RELATIVE,44 .s390x => R_390_RELATIVE,
44 .sh, .sheb => R_SH_RELATIVE,45 .sh, .sheb => R_SH_RELATIVE,
45 .sparc, .sparc64 => R_SPARC_RELATIVE,46 .sparc, .sparc64 => R_SPARC_RELATIVE,
47 .xtensa, .xtensaeb => R_XTENSA_RELATIVE,
46 else => @compileError("Missing R_RELATIVE definition for this target"),48 else => @compileError("Missing R_RELATIVE definition for this target"),
47};49};
4850
...@@ -261,6 +263,25 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {...@@ -261,6 +263,25 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
261 : [ret] "=r" (-> [*]const elf.Dyn),263 : [ret] "=r" (-> [*]const elf.Dyn),
262 :264 :
263 : .{ .l7 = true }),265 : .{ .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 }),
264 else => {285 else => {
265 @compileError("PIE startup is not yet supported for this target!");286 @compileError("PIE startup is not yet supported for this target!");
266 },287 },