Commit Graph

299 Commits

Author SHA1 Message Date
Alex Rønne Petersen 826b46d7bc compiler: fix and simplify DllMainCRTStartup handling
See: https://github.com/llvm/llvm-project/pull/171680
2026-04-22 15:31:57 +02:00
Mason Remaley 94ff38af87 Separates error return traces from stack traces
Doesn't commit the changes to stage1, we can generate those at the end
once we're not making any more changes to it to avoid wasting storage.
2026-04-12 04:01:29 -07:00
Carl Åstholm 81be7f62ec Fix debug I/O color detection for most targets
On POSIX, start.zig did not reset the `environ_initialized` field, which
prevented the environment variables from ever actually getting scanned.

On Windows, environment variable scanning is allocation-free, so it's
okay for `std.Io.Threaded.init_single_threaded` to use the global
environment block.
2026-04-11 12:28:24 -07:00
Carl Åstholm 3223d3a1ac Improve debug I/O color detection/handling for WASI and Emscripten
When linking libc, these targets can get their environment variables
from `std.c.environ`. Additionally, it's okay for WASI to use ANSI
escape sequences; nothing in the relevant specs claim otherwise.
2026-04-11 12:25:22 -07:00
Nathan Bourgeois fdf19984b8 std.Target: add psp os 2026-03-21 02:56:24 -04:00
Jacob Young 3c8b96df6d windows: use enums for boolean types 2026-03-20 02:25:16 +01:00
Alex Rønne Petersen 57db8498df start: add loongarch32 support 2026-03-19 19:53:03 +01:00
Jacob Young b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Jacob Young ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Matthew Lugg 85cac9e5b6 std: use sigaltstack for default segfault handler
This allows stack overflows to print stack traces. The size of the
sigaltstack (and whether it is actually set) can be configured by
setting `std.Options.signal_stack_size`.

The default value for the signal stack size was chosen experimentally by
doubling the value required to get stack traces on stack overflow with
the self-hosted x86_64 backend. While some targets may typically use
more stack space than x86_64-linux, the self-hosted x86_64 backend is
quite wasteful with stack at the moment, making it a fair benchmark.
Executables produced by the LLVM backend should have lower stack usage.
2026-01-13 07:24:49 +01:00
Andrew Kelley 6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
Andrew Kelley ff67f70cf9 start: tweak default allocator choices
On wasm targets, when libc is linked, we have to go through libc.
2026-01-04 00:27:09 -08:00
Andrew Kelley 1070c2a71a rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
2026-01-04 00:27:09 -08:00
Andrew Kelley 0ca83dd9d2 start: fix compilation with -lc on windows 2026-01-04 00:27:08 -08:00
Andrew Kelley 1ccc87363a std: fixes for WASI 2026-01-04 00:27:08 -08:00
Andrew Kelley 50e185b718 start: tweak allocator choice
Favor DebugAllocator in Debug mode, even when linking libc. Prevent use
of smp_allocator when single_threaded
2026-01-04 00:27:08 -08:00
Andrew Kelley 0362d9f321 start: make leaks into warnings
I think it will be less confusing if memory leak checking doesn't change
the return code of the process.
2026-01-04 00:27:08 -08:00
Andrew Kelley 08447ca47e std.fs.path: make relative a pure function
Instead of querying the operating system for current working directory
and environment variables, this function now accepts those things as
inputs.
2026-01-04 00:27:08 -08:00
Andrew Kelley de8c4cd64e compiler: update to new std.process APIs 2026-01-04 00:27:08 -08:00
Andrew Kelley 384bfc5f99 std.Progress: go through Io interface for parent IPC mechanism
and fix start code
2026-01-04 00:27:08 -08:00
Andrew Kelley 42988fc5f4 std.process.Environ.Block: enhance type safety 2026-01-04 00:27:08 -08:00
Andrew Kelley d6a1e73142 std: start wrangling environment variables and process args
this commit is unfinished. It marks a spot where I wanted to start
moving child process stuff below the std.Io.VTable
2026-01-04 00:27:07 -08:00
Andrew Kelley 7c1236e267 std: different way of doing some options
to avoid dependency loops
2025-12-23 22:15:12 -08:00
Andrew Kelley 3c2f5adf41 std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0

also fix some places that needed recancel(), thanks mlugg!

See #30562
2025-12-23 22:15:12 -08:00
Andrew Kelley 9ccd68de0b std: move abort and exit from posix into process
and delete the unit tests that called fork()

no forking allowed in the std lib, including unit tests, except to implement child process spawning.
2025-12-23 22:15:08 -08:00
Alex Rønne Petersen 8fae6630c4 std.start: add kvx support 2025-11-10 09:40:44 +01:00
Ryan Liptak b31a03f134 Let CRT take care of the entry point for wWinMain if libc is linked
Fixes #7852

Before, the modified test would fail with:

```
error: lld-link: undefined symbol: wWinMain
    note: referenced by C:\Users\Ryan\Programming\Zig\zig-x86_64-windows-0.15.1\lib\libc\mingw\crt\crtexewin.c:66
    note:               libmingw32.lib(ucrtexewin.obj):(wmain)
```
2025-11-08 17:11:12 -08:00
Carl Åstholm 075d300342 Remove std.builtin.subsystem
The subsystem detection was flaky and often incorrect and was not
actually needed by the compiler or standard library. The actual
subsystem won't be known until at link time, so it doesn't make
sense to try to determine it at compile time.
2025-11-05 01:29:00 +01:00
Jacob Young 0834e696f7 Elf2: start implementing dynamic linking 2025-10-29 18:15:09 -04:00
Andrew Kelley 05b28409e7 std.Io.Threaded: install and cleanup signal handlers
rather than in start code. delete std.options.keep_sig_io and
std.options.keep_sig_pipe
2025-10-29 06:20:52 -07:00
Andrew Kelley 80a341b411 std: remove awareness of POLL signal
this signal seems to be deprecated and/or useless on every target
2025-10-29 06:20:51 -07:00
Andrew Kelley 8b269f7e18 std: make signal numbers into an enum
fixes start logic for checking whether IO/POLL exist
2025-10-29 06:20:51 -07:00
Andrew Kelley ef55dcae67 start: fix logic for signal hanlding when SIG.POLL does not exist
fixes a compilation failure on FreeBSD
2025-10-29 06:20:51 -07:00
Andrew Kelley aadd8d4a3e std: back out the StackTrace byval changes
Let's keep passing this thing by pointer
2025-10-29 06:20:50 -07:00
Andrew Kelley aa6e8eff40 std.Io.Threaded: implement dirAccess for Windows 2025-10-29 06:20:50 -07:00
Jacob Young 08b609a79f Io: implement sleep and fix cancel bugs 2025-10-29 06:20:48 -07:00
Alex Rønne Petersen dba1bf9353 remove all Oracle Solaris support
There is no straightforward way for the Zig team to access the Solaris system
headers; to do this, one has to create an Oracle account, accept their EULA to
download the installer ISO, and finally install it on a machine or VM. We do not
have to jump through hoops like this for any other OS that we support, and no
one on the team has expressed willingness to do it.

As a result, we cannot audit any Solaris contributions to std.c or other
similarly sensitive parts of the standard library. The best we would be able to
do is assume that Solaris and illumos are 100% compatible with no way to verify
that assumption. But at that point, the solaris and illumos OS tags would be
functionally identical anyway.

For Solaris especially, any contributions that involve APIs introduced after the
OS was made closed-source would also be inherently more risky than equivalent
contributions for other proprietary OSs due to the case of Google LLC v. Oracle
America, Inc., wherein Oracle clearly demonstrated its willingness to pursue
legal action against entities that merely copy API declarations.

Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in
maintenance mode since, presumably to be retired completely sometime in the 2030s.

For these reasons, this commit removes all Oracle Solaris support.

Anyone who still wishes to use Zig on Solaris can try their luck by simply using
illumos instead of solaris in target triples - chances are it'll work. But there
will be no effort from the Zig team to support this use case; we recommend that
people move to illumos instead.
2025-10-27 07:35:38 -07:00
Alex Rønne Petersen 4193ea8239 std.start: add sh support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen c792ebfee2 std.start: add microblaze support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen 252e1fd7ec std.start: add alpha support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen 3e2daa509a std.Target: add arceb and xtensaeb Cpu.Arch tags 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen 38caa4902f Merge pull request #25623 from alexrp/or1k
Add `or1k-linux` support (via CBE)
2025-10-19 11:50:06 +02:00
GasInfinity 1bca158c6e fix(std): don't add the default _start and panic in homebrew targets
* even if std supported those targets, they're not posixy to be in that codepath.
2025-10-18 23:54:27 +02:00
Alex Rønne Petersen 2d5cdfcfc2 std.start: align stack pointer according to ARC v3 ABI 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen 0d2d51dd8c std.start: add or1k support 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen 2305527342 std.start: fix _start for mipsn32
This is more similar to O32 than N64.
2025-10-18 12:11:27 +02:00
Alex Rønne Petersen b8d776928a std: make all MIPS inline asm safe for MIPS I
MIPS I has load hazards so we need to insert nops in a few places. This is not a
problem for MIPS II and later.

While doing this, I also touched up all the inline asm to use ABI register
aliases and a consistent formatting convention. Also fixed a few places that
didn't properly check if the syscall return value should be negated.
2025-10-18 11:16:31 +02:00
mlugg 604fb3001d std.start: also don't print error trace targeting .other
This only matters if `callMain` is called by a user, since `std.start`
will never itself call `callMain` when `target.os.tag == .other`.
However, it *is* a valid use case for a user to call
`std.start.callMain` in their own startup logic, so this makes sense.
2025-09-30 13:44:54 +01:00
mlugg 51d08f4b9b fix compile errors and minor bugs 2025-09-30 13:44:54 +01:00
mlugg 202aeacc05 std: fixes 2025-09-30 13:44:51 +01:00