authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-30 17:42:11+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-31 02:06:57+02:00
log653eb7535514d06aca1eaaf777f82e1ecd968086
tree43e2ff4f9a3916358ec8e7557946abc2e004e76c
parent982510f8d565895cd6b467da092d2feb851aabe7
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Disable the gp initialization code for the self-hosted riscv64 backend.


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

lib/std/start.zig+14-8
...@@ -272,21 +272,27 @@ fn _start() callconv(.Naked) noreturn {...@@ -272,21 +272,27 @@ fn _start() callconv(.Naked) noreturn {
272 \\ bstrins.d $sp, $zero, 3, 0272 \\ bstrins.d $sp, $zero, 3, 0
273 \\ b %[posixCallMainAndExit]273 \\ b %[posixCallMainAndExit]
274 ,274 ,
275 // zig fmt: off
275 .riscv32, .riscv64 =>276 .riscv32, .riscv64 =>
276 // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at277 // The self-hosted riscv64 backend is not able to assemble this yet.
277 // startup in order for GP relaxation to work, even in static builds.278 if (builtin.zig_backend != .stage2_riscv64)
278 \\ .weak __global_pointer$279 // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at
279 \\ .hidden __global_pointer$280 // startup in order for GP relaxation to work, even in static builds.
280 \\ .option push281 \\ .weak __global_pointer$
281 \\ .option norelax282 \\ .hidden __global_pointer$
282 \\ lla gp, __global_pointer$283 \\ .option push
283 \\ .option pop284 \\ .option norelax
285 \\ lla gp, __global_pointer$
286 \\ .option pop
287 else ""
288 ++
284 \\ li s0, 0289 \\ li s0, 0
285 \\ li ra, 0290 \\ li ra, 0
286 \\ mv a0, sp291 \\ mv a0, sp
287 \\ andi sp, sp, -16292 \\ andi sp, sp, -16
288 \\ tail %[posixCallMainAndExit]@plt293 \\ tail %[posixCallMainAndExit]@plt
289 ,294 ,
295 // zig fmt: off
290 .m68k =>296 .m68k =>
291 // Note that the - 8 is needed because pc in the jsr instruction points into the middle297 // Note that the - 8 is needed because pc in the jsr instruction points into the middle
292 // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.)298 // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.)