962 Commits
Author SHA1 Message Date
Alex Rønne Petersen 84d9795610 cmake: no need for -fdata-sections 2026-10-26 11:02:42 +01:00
Jacob Young f08a8f0fc2 main: reimplement compiler debug flags
* Add `.llvmbc`/`.llvmir` to `ObjectFormat` for emitting unoptimized IR
* Replace `--verbose-air`, `--verbose-intern-pool`,
  `--verbose-generic-instances`, `--verbose-llvm-ir`, and
  `--verbose-llvm-bc` with various `--debug-log` scopes
  * `--debug-log illegal-air`: pre-legalized Air
  * `--debug-log legal-air`: post-legalized Air
  * `--debug-log air`: final Air with liveness
  * `--debug-log ip-stats`: InternPool statistics
  * `--debug-log ip-values`: InternPool values
  * `--debug-log ip-generic-instances`: InternPool generic instances
  * `--debug-log llvm-ir`: pre-optimized LLVM IR
  * `--debug-log opt-llvm-ir`: post-optimized LLVM IR
* Delete `--verbose-cimport` which does nothing
* Delete `--verbose-llvm-cpu-features` which is equivalent to looking at
  the outputs of `--show-builtin` and `--debug-log llvm-ir`
2026-10-21 10:04:01 -07:00
Alex Rønne Petersen 1797101fda cmake: detect glibc and set ZIG_HOST_TARGET_ABI accordingly
closes https://codeberg.org/ziglang/zig/issues/37304
2026-10-17 22:35:16 +02:00
Alex Rønne Petersen cc3b6ab1a8 cmake: remove workaround for Clang crash on s390x
https://github.com/llvm/llvm-project/pull/215027
2026-10-07 00:30:52 +02:00
Alex Rønne Petersen 37b8e4fc8f build: update to LLVM 23 2026-10-07 00:30:51 +02:00
Alex Rønne Petersen 5fb8343c7a build: pass -lc when generating compiler_rt.c 2026-10-04 18:33:19 +02:00
Alex Rønne Petersen 5e754304de remove support for wasi-libc
closes https://github.com/ziglang/zig/issues/9342
closes https://github.com/ziglang/zig/issues/15005
closes https://github.com/ziglang/zig/issues/20747
closes https://github.com/ziglang/zig/issues/22570
closes https://codeberg.org/ziglang/zig/issues/30977
2026-10-04 18:23:18 +02:00
Andrew Kelley a6c6412a8f start the 0.18.0 release cycle 2026-10-01 14:59:12 -07:00
Jacob Young 79bb28aa57 Elf2: implement dwarf unwind info
Other debug info is still in progress.

Closes #25421
2026-09-03 11:00:53 -04:00
Andrew Kelley 515a494220 Merge pull request 'loongarch: self-hosted backend' (#36418) from AstraFall/zig:loongarch/isel-pr into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36418
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-08-20 22:01:52 +02:00
Jacob Young 821d122c82 bootstrap: change/enable c compiler optimizations for zig1/zig2 2026-08-09 15:24:42 +02:00
xtex 726f539fe5 loongarch: scaffold a self-hosted LoongArch backend
Signed-off-by: xtex <xtex@astrafall.org>
2026-08-09 11:10:26 +08:00
Jacob Young 703baa4cd6 llvm: implement c abi for loongarch
Closes #35798
2026-07-27 14:44:41 -04:00
Jacob Young 0c0be6da88 llvm: implement c cabi for s390x
Closes #35799
2026-07-27 14:35:12 -04:00
Andrew Kelley 71ee8ceed9 compiler: jit commands support --zig-lib=[path]
when it is the first parameter after the command name.

fixes regression introduced in d4b7050555
2026-07-01 20:16:23 -07:00
Andrew Kelley d4b7050555 cmake: remove --zig-lib-dir arg from zig build
This demonstrates one of the downsides of the approach in this branch:
since `zig build` CLI is intentionally unaware of the command line
parsing that will be done by the child process, it cannot obtain zig lib
dir override from the command line even as it needs that information in
order to build the subcommand.

Consequently, zig lib dir has to be passed via env var. CMake does not
provide a way to do this. So instead we rely on Zig's automatic lookup
functionality.

This could be mitigated by adding CLI arg parsing that happens *before*
the subcommand. I find this kind of special case to be awkward and
unpleasant however. I think it's better to simply remove the ability to
pass `--zig-lib-dir` to `zig build`.
2026-06-29 23:50:19 -07:00
Andrew Kelley 15204cc210 cmake: remove dead files 2026-06-29 23:50:19 -07:00
Andrew Kelley b52a2ff73b build: compiler no longer depends on aro module
Thanks to 0b22111bc9 there is no more
`@import("aro")`.
2026-06-24 20:09:42 +02:00
Matthew Lugg 6d2c8349c5 compiler: fully switch to new @bitCast semantics 2026-06-24 10:20:56 +01:00
Matthew Lugg 8df04e1444 std: actually rename std.builtin to std.lang
This is now the canonical name, and `std.builtin` is a deprecated alias.
2026-05-03 12:22:37 +01:00
Alex Rønne Petersen c166c49b19 build: use -ffunction-sections -fdata-sections for the Zig compiler on Hexagon 2026-04-27 13:55:38 +02:00
Alex Rønne Petersen 2b6ab59435 cmake: update to LLVM 22
closes https://codeberg.org/ziglang/zig/issues/30558
2026-04-25 21:49:39 +02:00
Andrew Kelley 67a5b6e5e8 delete @cImport from the language
closes #20630
2026-04-15 17:43:53 -07:00
Andrew Kelley 7977ef80f9 start the 0.17.0 release cycle 2026-04-13 11:19:29 -07:00
Andrew Kelley 06b85a4fd0 CLI: use zon format for clang options
- plain old data ftw
- 177K -> 151K
- data bypasses Sema

This change is not really important but it was nice to explore best
practices for data like this.

When I measured building the compiler, I found no statistically
significant difference in compilation time.
2026-03-20 06:46:13 +01:00
fardragon 4acecad933 bootstrap.c: work around the gcc sra miscomp using preprocessor checks rather than CLI arg (#31589)
Closes #31577
I've also extended the "good" ranges to fit versions >14.3 and >13.4, since both of these branches have the fix merged so if they ever make a dot release it should be good.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31589
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: fardragon <michaldrozd@protonmail.ch>
Co-committed-by: fardragon <michaldrozd@protonmail.ch>
2026-03-20 04:55:51 +01:00
Matthew Lugg 79e7b719a3 bootstrap: disable strict aliasing
The C backend has always gleefully violated C's strict aliasing rules,
and I just got bitten by it for the first time when bootstrapping on
macOS. This probably hasn't been helping with some of the weird
bootstrap-related CI failures we've seen. So, update `bootstrap.c` and
`CMakeLists.txt` to tell GCC/Clang to disable type-based alias analysis.

No change is needed to the MSVC flags because MSVC does not, and never
has, implemented TBAA.
2026-03-10 11:28:36 +00:00
Matthew Lugg a5219cd288 bootstrap: work around GCC bug
GCC bug 119085, which affects versions 13.0--15.1, is being triggered by
the C backend, resulting in a (small but critical) miscompilation in
zig2. Unfortunately, we can't really work around that bug without a
command-line flag, because the bug is sensitive to things like the order
in which `struct` types are defined.

Therefore, I have added an option to `bootstrap.c` which causes it to
pass the appropriate flag to `gcc` to disable the optimization pass in
question. This flag can likely be removed in future, once the affected
GCC versions become less common.

At least one of our x86_64-linux CI machines is using an affected GCC
version, so I also updated the relevant CI script to pass this flag when
testing no-LLVM bootstrap.

CMakeLists also has a workaround, but no user intervention is required
there: the GCC version range is automatically detected by CMakeLists.
2026-03-10 10:26:15 +00:00
Alex Rønne Petersen 2d867223be build: use -ffunction-sections -fdata-sections for the Zig compiler on ARM
See 7daf0b6f4660245ac518c663f8971aad7e540da8; builds for ARM can run into the
same problems due to limited branch range.
2026-02-26 20:48:29 +01:00
Justus Klausecker a3a9dc111d std.heap.ArenaAllocator: make it threadsafe
Modifies the `Allocator` implementation provided by `ArenaAllocator` to be
threadsafe using only atomics and no synchronization primitives locked
behind an `Io` implementation.

At its core this is a lock-free singly linked list which uses CAS loops to
exchange the head node. A nice property of `ArenaAllocator` is that the
only functions that can ever remove nodes from its linked list are `reset`
and `deinit`, both of which are not part of the `Allocator` interface and
thus aren't threadsafe, so node-related ABA problems are impossible.

There *are* some trade-offs: end index tracking is now per node instead of
per allocator instance. It's not possible to publish a head node and its
end index at the same time if the latter isn't part of the former.

Another compromise had to be made in regards to resizing existing nodes.
Annoyingly, `rawResize` of an arbitrary thread-safe child allocator can
of course never be guaranteed to be an atomic operation, so only one
`alloc` call can ever resize at the same time, other threads have to
consider any resizes they attempt during that time failed. This causes
slightly less optimal behavior than what could be achieved with a mutex.
The LSB of `Node.size` is used to signal that a node is being resized.
This means that all nodes have to have an even size.

Calls to `alloc` have to allocate new nodes optimistically as they can
only know whether any CAS on a head node will succeed after attempting it,
and to attempt the CAS they of course already need to know the address of
the freshly allocated node they are trying to make the new head.
The simplest solution to this would be to just free the new node again if
a CAS fails, however this can be expensive and would mean that in practice
arenas could only really be used with a GPA as their child allocator. To
work around this, this implementation keeps its own free list of nodes
which didn't make their CAS to be reused by a later `alloc` invocation.
To keep things simple and avoid ABA problems the free list is only ever
be accessed beyond its head by 'stealing' the head node (and thus the
entire list) with an atomic swap. This makes iteration and removal trivial
since there's only ever one thread doing it at a time which also owns all
nodes it's holding. When the thread is done it can just push its list onto
the free list again.

This implementation offers comparable performance to the previous one when
only being accessed by a single thread and a slight speedup compared to
the previous implementation wrapped into a `ThreadSafeAllocator` up to ~7
threads performing operations on it concurrently.
(measured on a base model MacBook Pro M1)
2026-02-25 19:12:35 +01:00
Andrew Kelley 2372c68ae8 cmake: remove compiler rt source listings 2026-02-09 20:11:39 -08:00
Andrew Kelley 550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
Andrew Kelley b191e50be5 std.Thread: remove ResetEvent and WaitGroup
* std.Thread.ResetEvent -> Io.Event
* std.Thread.WaitGroup -> Io.Group
2026-02-02 00:09:48 -08:00
David Rubin 938efe4aab compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)`
with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose
magnitude is below the rounding capacity of the constant. For a 64-bit mantissa
(like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to
be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough,
we lose a bit to rounding.

For reference, the musl implementation does the same thing, using `mantissa - 1`:
https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18
where `LDBL_MANT_DIG` is 64 for `long double` on x86.

This commit also combines the floor and ceil implementations into one generic one.
2026-01-08 00:45:52 +01:00
Alex Rønne Petersen 7daf0b6f46 build: use -ffunction-sections -fdata-sections for the Zig compiler on PowerPC
It has been observed in practice on powerpc64(le)-linux that zig.o (in various
stages and build modes) is large enough that the +/- 32MB branch range of
PowerPC is insufficient to reach from one end of the code section to the other.
With LLVM 21, this leads to silent miscompiles that then crash at runtime. With
LLVM 22, it will at least lead to branch range errors that fail the compilation,
but that gets us no closer to a working compiler.

By using these options, we give the linker much greater flexibility to move code
and data around to satisfy these range constraints; without them, the linker is
not allowed to split up the huge code and data sections of zig.o to do so.

Similar issues have also been observed on powerpc-linux (32-bit), hexagon-linux,
and some variations of mips(64)(el)-linux. But let's be conservative for now;
those other targets can be added to the condition later.

As a data point to support this change, it's worth noting that LLD started
enabling these options for LTO precisely because the resulting large compilation
units ran into these range issues. In some abstract sense, Zig can be seen as
doing a limited form of "LTO" in the frontend, so it's not surprising that we
would hit the same issues.
2026-01-06 21:15:02 +01:00
Alex Rønne Petersen a78f891d05 compiler: support building openbsd crt0 and stub shared libraries
closes #2878
2026-01-05 16:50:46 +01:00
Andrew Kelley f612464331 compiler: delete DarwinPosixSpawn
if this is reintroduced it will need to be part of the std.Io
implementation
2026-01-04 00:27:08 -08:00
Andrew Kelley e956948f99 std: remove fs.getAppDataDir with no replacement
This API is a bit too opinionated for the Zig standard library.
Applications should contain this logic instead.
2025-12-30 16:21:25 -08:00
Andrew Kelley 814480db7c std: all File functions moved to std.Io 2025-12-23 22:15:07 -08:00
Andrew Kelley d1d2c37af2 std: all Dir functions moved to std.Io 2025-12-23 22:15:07 -08:00
Matthew Lugg 23e5a17187 std: delete Thread.Pool in favour of Io 2025-12-22 12:55:16 +00:00
Matthew Lugg 20bd5e8018 compiler-rt: remove dead code
`__addosi4`, `__addodi4`, `__addoti4`, `__subosi4`, `__subodi4`, and
`__suboti4` were all functions which we invented for no apparent reason.
Neither LLVM, nor GCC, nor the Zig compiler use these functions. It
appears the functions were created in a kind of misunderstanding of an
old language proposal; see https://github.com/ziglang/zig/pull/10824.

There is no benefit to these functions existing; if a Zig compiler
backend needs this operation, it is trivial to implement, and *far*
simpler than calling a compiler-rt routine. Therefore, this commit
deletes them. A small amount of that code was used by other parts of
compiler-rt; the logic is trivial so has just been inlined where needed.
I also chose to quickly implement `__addvdi3` (a standard function)
because it is trivial and we already implement the `sub` parallel.
2025-11-12 16:00:16 +00:00
Alex Rønne Petersen ee0a0f119c cmake: add a - missed in 0f71a9291a 2025-11-12 11:29:36 +01:00
Alex Rønne Petersen 0f71a9291a cmake: improve host system detection in some more cases 2025-11-12 10:04:30 +01:00
Andrew Kelley a072d821be Merge pull request #25592 from ziglang/init-std.Io
std: Introduce `Io` Interface
2025-10-29 13:51:37 -07:00
Alex Rønne Petersen a7119d4269 remove all IBM AIX and z/OS support
As with Solaris (dba1bf9353), we have no way to
actually audit contributions for these OSs. IBM also makes it even harder than
Oracle to actually obtain these OSs.

closes #23695
closes #23694
closes #3655
closes #23693
2025-10-29 14:25:51 +01:00
Andrew Kelley 5469db66e4 std.Thread.ResetEvent: make it more reusable 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
Jacob Young 969f2cff82 Elf2: implement virtual allocation
This allows segments to be moved around in the output file without
needing to reapply relocations until virtual address space is exhaused.
2025-10-06 11:27:39 -07:00
Jacob Young 1fa11e0954 Coff: delete 2025-10-02 17:44:52 -04:00