Commit Graph

208 Commits

Author SHA1 Message Date
Andrew Kelley 8184912a98 Merge pull request #20925 from alexrp/windows-tls
`std`: Some Windows TLS cleanup and fixes
2024-08-07 01:12:11 -07:00
Alex Rønne Petersen c0681d6b6e start: Add sparc32 support. 2024-08-07 01:09:18 -07:00
Alex Rønne Petersen 8056a85151 std: Move start_windows_tls.zig to os/windows/tls.zig.
Just to be consistent with Linux.
2024-08-03 20:35:08 +02:00
Alex Rønne Petersen a9c7818512 start: Fix an isARM() check to use isArmOrThumb() instead. 2024-08-01 20:58:08 +02:00
Andrew Kelley 7a0da805a8 Merge pull request #20797 from alexrp/start-more-arches
`start`: Add POSIX arc, csky, and hexagon support
2024-08-01 01:34:33 -07:00
Andrew Kelley 91163b44dd Merge pull request #20857 from alexrp/tls-porting
`std.os.linux.tls`: Refactor, improve documentation, fix a bug, and port to more architectures
2024-08-01 01:15:17 -07:00
Andrew Kelley 63aa85e7af Merge pull request #20872 from alexrp/riscv-gp
start: Initialize `gp` to `__global_pointer$` on riscv.
2024-08-01 00:47:05 -07:00
David Rubin 2b8a71489a start: remove riscv condition 2024-07-31 13:40:00 -07:00
Alex Rønne Petersen 653eb75355 start: Disable the gp initialization code for the self-hosted riscv64 backend. 2024-07-31 02:06:57 +02:00
Alex Rønne Petersen 982510f8d5 start: Initialize gp to __global_pointer$ on riscv. 2024-07-31 02:05:17 +02:00
Alex Rønne Petersen 78e581b86f start: Copy the mips64 comment about gp to the mips32 code.
Also, don't incorrectly claim that it's only needed for dynamic linking/PIC.
2024-07-30 17:58:22 +02:00
Alex Rønne Petersen 108c682df0 start: Add POSIX csky support. 2024-07-30 17:47:46 +02:00
Andrew Kelley f219286573 Merge pull request #20852 from ziglang/init-array-start-code
start code: implement __init_array_start, __init_array_end
2024-07-29 18:40:27 -07:00
Alex Rønne Petersen b52e054261 std.os.linux.tls: Refactor and improve documentation.
* Elaborate on the sub-variants of Variant I.
* Clarify the use of the TCB term.
* Rename a bunch of stuff to be more accurate/descriptive.
* Follow Zig's style around namespacing more.
* Use a structure for the ABI TCB.

No functional change intended.
2024-07-30 02:32:32 +02:00
Andrew Kelley 38e0f049c5 Merge pull request #20389 from alexrp/riscv32
Some `riscv32-linux` porting work
2024-07-29 16:13:35 -07:00
Andrew Kelley 7342017404 Merge pull request #20822 from alexrp/start-mips-fixes
`start`: A handful of MIPS fixes
2024-07-29 12:02:59 -07:00
Andrew Kelley 3f2d1b17fc disable the new code for self-hosted riscv backend 2024-07-29 11:38:11 -07:00
Alex Rønne Petersen d633b35f35 start: Always inline the call to std.os.linux.pie.relocate().
At this stage, we're not ready to make calls yet on some architectures (e.g. MIPS).
2024-07-29 10:08:34 +02:00
Alex Rønne Petersen d6c637c36b start: Set std.os.linux.elf_aux_maybe after PIE relocations.
Accesses to this global variable can require relocations on some platforms (e.g.
MIPS). If we do it before PIE relocations have been applied, we'll crash.
2024-07-29 10:05:28 +02:00
Alex Rønne Petersen e33af8e902 start: Perform the posixCallMainAndExit() call with jalr on mips.
It's actually important for the ABI that r25 (t9) contains the address of the
called function, so that this standard prologue sequence works:

    lui $2, %hi(_gp_disp)
    addiu $2, $2, %lo(_gp_disp)
    addu $gp, $2, $t9

(This is a bit similar to the ToC situation on powerpc that was fixed in
7bc78967b400322a0fc5651f37a1b0428c37fb9d.)
2024-07-29 10:05:25 +02:00
Alex Rønne Petersen 77fc3b88fb start: Set up the gp register on mips and mips64. 2024-07-29 10:04:54 +02:00
Alex Rønne Petersen 8b176ab303 start: Implement _start() for riscv32. 2024-07-29 09:50:09 +02:00
Andrew Kelley 728024f9f3 start code: implement __init_array_start, __init_array_end 2024-07-28 23:54:49 -07:00
David Rubin 7ff5709e1b riscv: implement lr/sr loop logic for non-native atomics 2024-07-26 04:19:57 -07:00
David Rubin a1f6a8ef90 riscv: airAsm rewrite
with this rewrite we can call functions inside of
inline assembly, enabling us to use the default start.zig logic

all that's left is to implement lr/sc loops for atomically manipulating
1 and 2 byte values, after which we can use the segfault handler logic.
2024-07-26 04:19:55 -07:00
Alex Rønne Petersen 389ce984b5 start: Add POSIX arc support. 2024-07-26 02:32:19 +02:00
Alex Rønne Petersen 7c98a65ae4 start: Add POSIX hexagon support. 2024-07-26 02:32:16 +02:00
Alex Rønne Petersen fff5ce053f start: Align the stack on sparc64 just in case.
The kernel does this as required, but we cannot trust dynamic linkers to do it.
2024-07-25 00:55:52 +02:00
Alex Rønne Petersen ebefee6088 start: Fix mips stack alignment value (should be 8, not 16). 2024-07-25 00:55:36 +02:00
Alex Rønne Petersen 5478b0eb38 start: Simplify mips and mips64 startup code.
Switches from using r1 as a temporary to r2. That way, we don't have to set the
`noat` assembler option. (r1 is the scratch register used by the assembler's
pseudoinstructions; the assembler warns when code uses that register explicitly
without `noat` set.)
2024-07-25 00:55:00 +02:00
Alex Rønne Petersen 47c0464e86 start: Explicitly clear the link register on mips and mips64 just in case.
The kernel does this as required, but we cannot trust dynamic linkers to do it.
2024-07-24 21:56:54 +02:00
Alex Rønne Petersen 1b13d7477d start: Properly escape percent signs in the s390x inline asm.
Silly mistake in 8ffc41f747.
2024-07-24 21:56:54 +02:00
Alex Rønne Petersen ce81525f3f start: Align the stack on s390x just in case.
The kernel does this as required, but we cannot trust dynamic linkers to do it.
2024-07-24 21:56:54 +02:00
Alex Rønne Petersen 52653ec82b start: Align the stack on powerpc just in case.
The kernel does this as required, but we cannot trust dynamic linkers to do it.
2024-07-24 21:56:54 +02:00
Alex Rønne Petersen 714e743393 start: Align the stack on aarch64 just in case.
The kernel does this as required, but we cannot trust dynamic linkers to do it.
2024-07-24 21:56:52 +02:00
Alex Rønne Petersen 9771390f89 start: Simplify the sparc64 inline asm a bit. 2024-07-24 20:12:14 +02:00
Alex Rønne Petersen 58e38ff1f8 start: Add a comment explaining the sparc64 stack bias. 2024-07-24 20:12:14 +02:00
Alex Rønne Petersen 5c96192c19 start: Add a comment explaining our paranoid stance on ABI guarantees. 2024-07-24 20:12:14 +02:00
Alex Rønne Petersen 557c4f04c2 start: Handle loongarch32 together with loongarch64.
Nothing bitness-specific about this startup code.
2024-07-24 10:25:51 -07:00
Andrew Kelley 718f8d5314 Merge pull request #20706 from alexrp/sigaction-nosys
`std.posix`: Make `sigaction()` infallible
2024-07-23 11:49:43 -07:00
Andrew Kelley 6f3e9939d0 Merge pull request #20725 from ziglang/fuzz
initial support for integrated fuzzing
2024-07-23 11:39:19 -07:00
Andrew Kelley bde8c4a46a update start code to use @disableInstrumentation
This prevents it from trying to access thread local storage before it
has set up thread local storage, particularly when code coverage
instrumentation is enabled.
2024-07-22 14:26:17 -07:00
Alex Rønne Petersen 8ffc41f747 start: Add POSIX s390x startup code. 2024-07-22 14:39:55 +02:00
Alex Rønne Petersen c53673276b start: Add POSIX loongarch64 startup code. 2024-07-22 14:39:55 +02:00
Alex Rønne Petersen 1fa5ca24fe start: Add POSIX m68k startup code. 2024-07-22 14:39:55 +02:00
Alex Rønne Petersen 142209444a start: Pass _start() into its own inline asm as an operand. 2024-07-22 14:39:53 +02:00
Alex Rønne Petersen 81232f7c91 start: Add clrrdi to align the stack pointer on powerpc64. 2024-07-22 01:23:04 +02:00
Alex Rønne Petersen 7bc78967b4 start: Fix _start() to initialize the ToC for powerpc64.
The previous version of this function referenced the argc_argv_ptr global
variable as an inline asm operand. This caused LLVM to generate prologue code to
initialize the ToC so that the global variable can actually be accessed.

Ordinarily, there's nothing wrong with that. But _start() is a naked function!
This makes it actually super surprising that LLVM did this. It also means that
the old version only really worked by accident.

Once the reference to the global variable was removed, no ToC was set up, thus
violating the calling convention once we got to posixCallMainAndExit(). This
then caused any attempt to access global variables here to crash - namely when
setting std.os.linux.elf_aux_maybe.

The fix is to just initialize the ToC manually in _start().
2024-07-22 01:22:47 +02:00
Alex Rønne Petersen ecd459b864 start: Avoid going through the argc_argv_ptr global variable.
This is problematic for PIE. There's nothing but luck preventing the accesses to
this global variable from requiring relocations. I've observed this being an
issue on MIPS and PowerPC personally, but others may be affected.

Besides, we're really just passing the initial stack pointer value to
posixCallMainAndExit(), so... just do that.
2024-07-21 22:38:14 +02:00
Alex Rønne Petersen 2cced8903e std.posix: Consider invalid signal numbers to sigaction() to be programmer error.
The set of signals that cannot have their action changed is documented in POSIX,
and any additional, non-standard signals are documented by the specific OS. I
see no valid reason why EINVAL should be considered an unpredictable error here.
2024-07-21 22:38:09 +02:00