236 Commits

Author SHA1 Message Date
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 8ffc41f74705246e61f3c02c253d40b1464ea2bf.
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
Jakub Konka
9d9b5a11e8
Merge pull request #20474 from Rexicon226/riscv
more RISC-V backend progress
2024-07-17 08:39:44 +02:00
gooncreeper
9002977051
start: refactor callMain return type checking 2024-07-15 12:29:07 +03:00
David Rubin
5a2c547fc1
riscv: vectors part 3 2024-07-14 23:02:35 -07:00
Alex Rønne Petersen
c533233f42 Revert "start: workaround for LLVM 17 regression"
This reverts commit d7daf7c203f583ed440efc68df6ee690ee8f8f32.

This is no longer needed with the LLVM 18 upgrade, and it was breaking PIE.

Closes #20306.
2024-06-16 23:11:08 -04:00
David Rubin
ffb63a05a3 riscv: finally fix bug + airAggregateInit
i just hadn't realized that I placed the `riscv_start` branch in the non-simplified
starts
2024-05-11 02:17:24 -07:00
David Rubin
6740c1f084 riscv: big rewrite to use latest liveness
this one is even harder to document then the last large overhaul.

TLDR;
- split apart Emit.zig into an Emit.zig and a Lower.zig
- created seperate files for the encoding, and now adding a new instruction
is as simple as just adding it to a couple of switch statements and providing the encoding.
- relocs are handled in a more sane maner, and we have a clear defining boundary between
lea_symbol and load_symbol now.
- a lot of different abstractions for things like the stack, memory, registers, and others.
- we're using x86_64's FrameIndex now, which simplifies a lot of the tougher design process.
- a lot more that I don't have the energy to document. at this point, just read the commit itself :p
2024-05-11 02:17:11 -07:00
David Rubin
8ac239ebce riscv: add enough components to get a test runner working 2024-05-11 02:17:11 -07:00
David Rubin
060c475fcd riscv: update start.zig and restore ra from the proper stack offset 2024-05-11 02:17:11 -07:00
Jakub Konka
2e1fc0dd14 handle visionos target OS tag in the compiler
* rename .xros to .visionos as agreed in the tracking issue
* add support for VisionOS platform in the MachO linker
2024-05-09 15:04:15 +02:00
Jacob Young
5a41704f7e cbe: rewrite CType
Closes #14904
2024-03-30 20:50:48 -04:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Tristan Ross
9d70d614ae
std.builtin: make link mode fields lowercase 2024-03-11 07:09:10 -07:00
Veikka Tuominen
07dbff4f44 std.start: remove event loop integration 2024-02-01 15:22:36 +02:00
joachimschmidt557
f12ec02bd7 stage2 AArch64: get empty file compiling again 2024-01-08 23:53:24 -08:00
Andrew Kelley
702b809ea3
Merge pull request #17815 from Luukdegram/wasm-no-entry
wasm-linker: implement `-fno-entry` and correctly pass `--shared` and `--pie` when given
2023-11-05 18:44:12 -05:00
Ryan Liptak
ae6df9e967 start.zig: Replace kernel32 usage with ntdll
Co-authored-by: e4m2 <git@e4m2.com>
2023-11-03 19:25:46 +02:00
Luuk de Gram
1cb7a01b25
wasm-linker: implement -fno-entry flag
This adds support for the `-fno-entry` and `-fentry` flags respectively, for
zig build-{exe/lib} and the build system. For `zig cc` we use the `--no-entry`
flag to be compatible with clang and existing tooling.

In `start.zig` we now make the main function optional when the target is
WebAssembly, as to allow for the build-exe command in combination with
`-fno-entry`.

When the execution model is set, and is set to 'reactor', we now verify
when an entry name is given it matches what is expected. When no entry
point is given, we set it to `_initialize` by default. This means the user
will also be met with an error when they use the reactor model, but did
not provide the correct function.
2023-11-03 12:48:52 +01:00
Ryan Liptak
42d4d07efa start: Make wWinMain nCmdShow setting match Windows better
It won't match perfectly; see https://github.com/ziglang/zig/issues/17808
2023-11-02 00:19:40 -04:00
Andrew Kelley
d817a3c517 delete std.os.windows.user32
This is progress towards #4426
Closes #17417
2023-10-28 13:16:47 -04:00
Koakuma
375bb5f4a1 lib: Fix asm code in _start for SPARC
SPARCs have delayed branches, that is, it will unconditionally
run the next instruction following a branch.
Slightly reorder the _start code sequence to prevent it from
accidentally executing stray instructions, which may result in odd
program behavior.
2023-10-12 16:13:32 -07:00
Jacob Young
d7daf7c203 start: workaround for LLVM 17 regression
Tracking issue #16799
2023-09-19 09:37:32 -07:00
Jacob G-W
d0fbfd3c9f Plan 9: add more features to std.os.plan9
* Replaces the exit assembly with the function from std.
* Reads the top-of-stack struct at program startup that can get information
  like the pid.
* Changes the read and write functions to use the Pread and Pwrite syscalls
  instead of the depreciated _READ and _WRITE
* Changes the openat function to use flags instead of perms.
  Plan9 does not support perms when opening, just when creating.
* Adds an errstr function to read the errstr buf created by the kernel
2023-08-02 18:19:07 -04:00