authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-30 04:02:49+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-31 02:05:17+02:00
log982510f8d565895cd6b467da092d2feb851aabe7
tree6aa85edef4e01fa4e47652596439032650b1e69e
parent78e581b86f11bfc8da277cbad7b7a30941e55e95
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Initialize gp to __global_pointer$ on riscv.


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

lib/std/start.zig+8
...@@ -273,6 +273,14 @@ fn _start() callconv(.Naked) noreturn {...@@ -273,6 +273,14 @@ fn _start() callconv(.Naked) noreturn {
273 \\ b %[posixCallMainAndExit]273 \\ b %[posixCallMainAndExit]
274 ,274 ,
275 .riscv32, .riscv64 =>275 .riscv32, .riscv64 =>
276 // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at
277 // startup in order for GP relaxation to work, even in static builds.
278 \\ .weak __global_pointer$
279 \\ .hidden __global_pointer$
280 \\ .option push
281 \\ .option norelax
282 \\ lla gp, __global_pointer$
283 \\ .option pop
276 \\ li s0, 0284 \\ li s0, 0
277 \\ li ra, 0285 \\ li ra, 0
278 \\ mv a0, sp286 \\ mv a0, sp