aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-07-30 04:02:49 +0200
committerAlex Rønne Petersen <alex@alexrp.com>2024-07-31 02:05:17 +0200
commit982510f8d565895cd6b467da092d2feb851aabe7 (patch)
tree6aa85edef4e01fa4e47652596439032650b1e69e /lib/std/start.zig
parent78e581b86f11bfc8da277cbad7b7a30941e55e95 (diff)
downloadzig-982510f8d565895cd6b467da092d2feb851aabe7.tar.gz
zig-982510f8d565895cd6b467da092d2feb851aabe7.zip
start: Initialize gp to __global_pointer$ on riscv.
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index bca0922fb3..7b68f99b9f 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -273,6 +273,14 @@ fn _start() callconv(.Naked) noreturn {
\\ b %[posixCallMainAndExit]
,
.riscv32, .riscv64 =>
+ // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at
+ // startup in order for GP relaxation to work, even in static builds.
+ \\ .weak __global_pointer$
+ \\ .hidden __global_pointer$
+ \\ .option push
+ \\ .option norelax
+ \\ lla gp, __global_pointer$
+ \\ .option pop
\\ li s0, 0
\\ li ra, 0
\\ mv a0, sp