From 8cbf091a9a5dd1996453dfce08e7e3a109b6c30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 4 Aug 2024 10:36:34 +0200 Subject: [PATCH] std.os.linux.start_pie: Add sparc/sparc64 support. --- lib/std/os/linux/start_pie.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index 7b086250d6..dbe3f5565e 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -32,6 +32,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => R_PPC_RELATIVE, .riscv32, .riscv64 => R_RISCV_RELATIVE, .s390x => R_390_RELATIVE, + .sparc, .sparc64 => R_SPARC_RELATIVE, else => @compileError("Missing R_RELATIVE definition for this target"), }; @@ -182,6 +183,16 @@ inline fn getDynamicSymbol() [*]elf.Dyn { \\ 2: : [ret] "=r" (-> [*]elf.Dyn), ), + // The compiler does not necessarily have any obligation to load the `l7` register (pointing + // to the GOT), so do it ourselves just in case. + .sparc, .sparc64 => asm volatile ( + \\ sethi %%hi(_GLOBAL_OFFSET_TABLE_ - 4), %%l7 + \\ call 1f + \\ add %%l7, %%lo(_GLOBAL_OFFSET_TABLE_ + 4), %%l7 + \\ 1: + \\ add %%l7, %%o7, %[ret] + : [ret] "=r" (-> [*]elf.Dyn), + ), else => { @compileError("PIE startup is not yet supported for this target!"); },