| ... | ... | @@ -232,6 +232,16 @@ fn _start() callconv(.Naked) noreturn { |
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | // Move this to the riscv prong below when this is resolved: https://github.com/ziglang/zig/issues/20918 |
| 236 | if (builtin.cpu.arch.isRISCV() and builtin.zig_backend != .stage2_riscv64) asm volatile ( |
| 237 | \\ .weak __global_pointer$ |
| 238 | \\ .hidden __global_pointer$ |
| 239 | \\ .option push |
| 240 | \\ .option norelax |
| 241 | \\ lla gp, __global_pointer$ |
| 242 | \\ .option pop |
| 243 | ); |
| 244 | |
| 235 | 245 | // Note that we maintain a very low level of trust with regards to ABI guarantees at this point. |
| 236 | 246 | // We will redundantly align the stack, clear the link register, etc. While e.g. the Linux |
| 237 | 247 | // kernel is usually good about upholding the ABI guarantees, the same cannot be said of dynamic |
| ... | ... | @@ -275,24 +285,19 @@ fn _start() callconv(.Naked) noreturn { |
| 275 | 285 | \\ and sp, #-16 |
| 276 | 286 | \\ b %[posixCallMainAndExit] |
| 277 | 287 | , |
| 278 | | // zig fmt: off |
| 279 | 288 | .csky => |
| 280 | | if (builtin.position_independent_code) |
| 281 | | // The CSKY ABI assumes that `gb` is set to the address of the GOT in order for |
| 282 | | // position-independent code to work. We depend on this in `std.os.linux.start_pie` |
| 283 | | // to locate `_DYNAMIC` as well. |
| 284 | | \\ grs t0, 1f |
| 285 | | \\ 1: |
| 286 | | \\ lrw gb, 1b@GOTPC |
| 287 | | \\ addu gb, t0 |
| 288 | | else "" |
| 289 | | ++ |
| 289 | // The CSKY ABI assumes that `gb` is set to the address of the GOT in order for |
| 290 | // position-independent code to work. We depend on this in `std.os.linux.start_pie` |
| 291 | // to locate `_DYNAMIC` as well. |
| 292 | \\ grs t0, 1f |
| 293 | \\ 1: |
| 294 | \\ lrw gb, 1b@GOTPC |
| 295 | \\ addu gb, t0 |
| 290 | 296 | \\ movi lr, 0 |
| 291 | 297 | \\ mov a0, sp |
| 292 | 298 | \\ andi sp, sp, -8 |
| 293 | 299 | \\ jmpi %[posixCallMainAndExit] |
| 294 | 300 | , |
| 295 | | // zig fmt: on |
| 296 | 301 | .hexagon => |
| 297 | 302 | // r29 = SP, r30 = FP |
| 298 | 303 | \\ r30 = #0 |
| ... | ... | @@ -308,27 +313,13 @@ fn _start() callconv(.Naked) noreturn { |
| 308 | 313 | \\ bstrins.d $sp, $zero, 3, 0 |
| 309 | 314 | \\ b %[posixCallMainAndExit] |
| 310 | 315 | , |
| 311 | | // zig fmt: off |
| 312 | 316 | .riscv32, .riscv64 => |
| 313 | | // The self-hosted riscv64 backend is not able to assemble this yet. |
| 314 | | if (builtin.zig_backend != .stage2_riscv64) |
| 315 | | // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at |
| 316 | | // startup in order for GP relaxation to work, even in static builds. |
| 317 | | \\ .weak __global_pointer$ |
| 318 | | \\ .hidden __global_pointer$ |
| 319 | | \\ .option push |
| 320 | | \\ .option norelax |
| 321 | | \\ lla gp, __global_pointer$ |
| 322 | | \\ .option pop |
| 323 | | else "" |
| 324 | | ++ |
| 325 | 317 | \\ li s0, 0 |
| 326 | 318 | \\ li ra, 0 |
| 327 | 319 | \\ mv a0, sp |
| 328 | 320 | \\ andi sp, sp, -16 |
| 329 | 321 | \\ tail %[posixCallMainAndExit]@plt |
| 330 | 322 | , |
| 331 | | // zig fmt: on |
| 332 | 323 | .m68k => |
| 333 | 324 | // Note that the - 8 is needed because pc in the jsr instruction points into the middle |
| 334 | 325 | // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.) |