0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
Commit graph

37,607 commits

Author SHA1 Message Date
Matthew Lugg
fca3f6f62e
MachO: don't split subsections on N_ALT_ENTRY symbols
MachO has a mechanism where symbols can introduce "subsections", which
(as I understand it) allows a linker to garbage-collect parts of
sections without pulling in the heavy machinery of `-fdata-sections` and
`-ffunction-sections`. Essentially, symbols can be considered to
partition a section, and these boundaries are not allowed to be crossed
by memory accesses, so the linker can detect symbols which are unused
and drop the corresponding input section regions.

However, the symbol flag `N_ALT_ENTRY` indicates that a symbol should
not participate in this "splitting", and is instead an "alternate entry
point" to the previous subsection, which should continue through this
symbol.

The Mach-O linker was failing to ignore `N_ALT_ENTRY` symbols when
creating subsections, which meant that for certain link inputs, it would
create additional subsection splits, and then garbage collect the extra
sections (due to the `N_ALT_ENTRY` symbol being unused). Naturally, this
silent dropping of parts of input sections led to miscompilations.
2026-03-28 16:50:43 +00:00
Pavel Verigo
6ed9c05210
link.Wasm: fix indirect function table handling
The changes to the LLVM backend here changed the compiler_rt object
which LLVM emits, and exposed some buggy behavior in the self-hosted
WASM linker when parsing that object.
2026-03-28 16:50:43 +00:00
Matthew Lugg
4a494a8cf9
tests: enable incremental tests for x86_64-linux-llvm
These all pass now! I have also removed the warning about the LLVM
backend not supporting incremental compilation; I expect it will work
sort of okay in practice by now.
2026-03-28 16:50:43 +00:00
Matthew Lugg
d28c5069b8
llvm: rework handling of globals
The main goal here is to make incremental compilation work a bit better.
I also slightly expanded some `std.zig.llvm.Builder` APIs so that we
don't need to pointlessly create new `Global`s whenever e.g. a function
turns into a variable or vice versa.

Also, lean into aliases for exports! If we just use aliases for every
export, everything becomes simpler. Besides, we can't just go around
renaming the globals of `Nav`s: the export could disappear on a future
update, in which case we'd have to somehow revert that change, which is
easier said than done.
2026-03-28 16:50:42 +00:00
Matthew Lugg
500e6c7cfe
llvm: some more random enhancements
Avoid directly querying `Builder.Type`s in favour of `lowerType` calls
in a couple of places. The idea here is to avoid querying state stored
in the `Builder` to try and move towards a world where codegen
(essentially the logic in `codegen.llvm.FuncGen`) can happen on a
separate thread to "linking" (which actually interacts with shared state
on `codegen.llvm.Object` and `std.zig.llvm.Builder`).

Don't clear the `Builder` state during `emit`; this is clearly
incompatible with incremental compilation. With that line of code
removed, incremental compilation is actually already somewhat functional
with the LLVM backend.

Also, don't use `c_uint` for source location state---I have no idea
where this came from but it definitely isn't correct.
2026-03-28 16:47:57 +00:00
Matthew Lugg
9c0c65c313
llvm: minor refactors, and incremental @tagName updates 2026-03-28 16:47:55 +00:00
Matthew Lugg
fb224178aa
Air: change misleading instruction tag name 2026-03-28 16:47:02 +00:00
Matthew Lugg
c0f3a23831
llvm: get rid of a bunch of PerThread usages
Also, notably, remove `Air.value`! The `onePossibleValue` check was
actually dead code, because it is a bug if Sema ever emits code which
considers a value of OPV type to be runtime-known---and at that point
`Air.value` is just a thin wrapper around `Air.Ref.toInterned`.
2026-03-28 16:46:59 +00:00
Matthew Lugg
bd8088bb98
llvm: random enhancements and cleanups 2026-03-28 16:46:23 +00:00
Matthew Lugg
5941c9da08
llvm: remove almost all GEPs
LLVM is gradually transitioning from the `getelementptr` instruction to
a new `ptradd` instruction. The latter instruction doesn't actually
exist yet, but for now, LLVM is considering `getelementptr i8` to be
equivalent. LLVM is already internally canonicalizing `getelementptr`
usages to this pattern in many cases, and it's far easier for us to emit
that, so... let's do so!

For runtime indexing this does sometimes require an explicit
multiplication to scale an index to a byte offset. The helper function
`llvm.FuncGen.ptraddScaled` makes this common pattern more convenient.

A particularly nice side effect from this is that after removing some
dead code (left over from before we made all `struct`s etc by-ref), it
has eliminated the need to maintain that nasty mapping between Zig field
indices and LLVM field indices. `FuncGen` no longer cares at all how
aggregate types are lowered!

Slices are still by-val at least for now, but they never lived in that
mapping because their structure is simple and consistent (they always
have a pointer at field index 0 and a usize at field index 1, with no
explicit padding necessary).
2026-03-28 16:45:55 +00:00
Matthew Lugg
e3ee37f983
llvm: start separating out function codegen
This mostly just moves `FuncGen` into its own file, but there are also a
few more cleanups, such as removing `NavGen` (it no longer served any
purpose) and slightly simplifying the logic for emitting codegen errors.
2026-03-28 16:45:54 +00:00
Jacob Young
3dc5f13989 llvm: fix -fstrip keeping globals only referenced by the symbol table 2026-03-27 21:03:31 -04:00
Andrew Kelley
4b85f05f06 Fetch: fix recompression not preserving symlinks
closes #31660
2026-03-27 20:06:32 +01:00
Andrew Kelley
b490412cd2 build runner: fail, not warn when insufficient memory
Users can proceed by telling the build system how much memory to assume
the system has. I have improved the failure message to communicate this.

Partially reverts 87f8f47ba5

Even if we wanted to unrevert this reverted commit, it's not sufficient
to merely downgrade the failure to a warning, because the main
scheduling logic will fail to schedule steps that have a max_rss
exceeding the detected system value, causing some steps to never get
executed, eventually tripping an assert. Such a change would need to
also override the max_rss value to be equal to the greatest value across
all steps.

closes #31510
2026-03-27 18:06:08 +01:00
Andrew Kelley
523cfabcdf build.zig: hard cap on compiler max_rss at 8G
This number should never be raised. If the value is exceeded, then it is
considered a bug in the Zig project that building the compiler takes
more than 8G of memory.

Partial revert of 1293f080fd

Deprioritizes #31510
2026-03-27 18:05:59 +01:00
Andrew Kelley
b4e21ccb49 Merge pull request 'std.tar.extract: sanitize path traversal' (#31685) from tar into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31685
2026-03-27 15:00:29 +01:00
Andrew Kelley
053b5e3bdd Package.Manifest: add missing hash validation
closes #31225

reverts e96d86064e which was an inadequate
attempt to address the same problem (lack of hash validation).
2026-03-27 14:57:05 +01:00
Andrew Kelley
2d3694ab42 Merge pull request 'std.Io.Dir: add resolve_beneath flag and implement for freebsd,macos' (#31684) from resolve_beneath into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31684
2026-03-27 12:24:09 +01:00
GasInfinity
1f79a9e4e3 feat(Io.net): add allow_broadcast to BindOptions
* and implement it in `Threaded`, `Uring` and `Kqueue`
2026-03-27 09:43:57 +01:00
Andrew Kelley
9ad6843b20 std.tar.extract: sanitize path traversal
closes #31362
2026-03-27 01:27:38 -07:00
Andrew Kelley
79b5433da7 std.tar: rename pipeToFileSystem to extract 2026-03-27 01:27:26 -07:00
Andrew Kelley
2e4482cd14 std.Io.Dir: add resolve_beneath flag and implement for freebsd,macos 2026-03-27 01:23:04 -07:00
Andrew Kelley
6f467e436d std.Io: move File.CreateFlags to Dir.CreateFileOptions
for naming consistency.

same thing with File.OpenFlags -> Dir.OpenFileFlags
2026-03-27 01:23:04 -07:00
Andrew Kelley
0d25302d43 Package.Fetch: bump redirect buffer size
RFC 9110 says

> It is RECOMMENDED that all senders and recipients support, at a minimum,
> URIs with lengths of 8000 octets in protocol elements.

closes #30207
2026-03-27 08:42:02 +01:00
Alex Rønne Petersen
a85495ca22
ci: update more system deps comments 2026-03-27 05:11:53 +01:00
Alex Rønne Petersen
142703ba51
ci: x86_64-linux-release requires cc 2026-03-27 04:42:05 +01:00
Jacob Young
49a258c0e0 std.Build.Step.Run: improve syscalls while running zig test executables
Previously, each message requires an unseekable error to be returned
from a syscall before proceeding.  Ideally, the code would just pass
around `*std.Io.Writer` instead of `std.Io.File` in the first place, but
even then, you could argue for saving a syscall with `writerStreaming`.
2026-03-27 03:28:50 +01:00
Alex Rønne Petersen
49fa67d826
fixup 58490f588c 2026-03-27 02:49:12 +01:00
Alex Rønne Petersen
58490f588c
test: disable standalone test run_output_caching on windows
https://codeberg.org/ziglang/zig/issues/31564
2026-03-27 02:24:23 +01:00
Alex Rønne Petersen
f40eb50157
std.fs.test: disable '.' and '..' in Dir functions test on *-windows
https://codeberg.org/ziglang/zig/issues/31561
2026-03-27 02:24:23 +01:00
Alex Rønne Petersen
36b28050f4
std.fs.test: disable AtomicFile test on windows
https://codeberg.org/ziglang/zig/issues/31389
2026-03-27 02:24:21 +01:00
Alex Rønne Petersen
c3d474bf6f Merge pull request 'link.MachO.Dylib: allow aarch64-macos to match arm64e-macos TBD entries' (#31673) from alexrp/zig:thanks-apple into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31673
2026-03-27 01:30:00 +01:00
Linus Groh
f19be20912 libc: Update macOS headers to SDK 26.4 2026-03-26 19:25:56 +00:00
Alex Rønne Petersen
13b1050d4c
link.MachO.Dylib: allow aarch64-macos to match arm64e-macos TBD entries
closes https://codeberg.org/ziglang/zig/issues/31658
2026-03-26 08:48:38 +01:00
Alex Rønne Petersen
6bdb45beaf
test: don't run test-zigc on targets that don't support libzigc 2026-03-26 08:48:38 +01:00
Alex Rønne Petersen
a216c74131
test: partial revert of ac793232ee
This is just obviously wrong?! I'm fairly certain I didn't intend to push that
commit in that state.
2026-03-26 05:50:51 +01:00
Alex Rønne Petersen
cef16b5130
std.Target: don't claim that OpenBSD requires libc
https://codeberg.org/ziglang/zig/issues/30982
2026-03-26 05:50:51 +01:00
Alex Rønne Petersen
e4a977f9e4
compiler: do not enforce PIC for Android
This requirement was put here many years ago in stage1 and I have no idea why
because Android does not actually require PIC.
2026-03-26 05:50:51 +01:00
Alex Rønne Petersen
4219037faf
compiler: default to PIC if the target defaults to PIE
Otherwise, by default and with no special flags, we produce objects and static
libraries that cannot be linked into executables.
2026-03-26 05:50:51 +01:00
Andrew Kelley
abd131e336 zig cc: make --version use the full clang CLI lowering code path
because clang wants to parse the -target argument with clang -target
syntax.

closes #30178
2026-03-25 18:29:19 -07:00
Alex Rønne Petersen
54b3484256 Revert "disable flaky test: aarch64-macos stage3/4 nondeterminism check"
This reverts commit 8669898819.
2026-03-25 20:40:29 +01:00
Alex Rønne Petersen
5e0e1841c0 Compilation: close the linker output file before writing whole cache manifest
Otherwise a different process may get a cache hit on the file while we still
have a writable fd open for it. This isn't actually a real problem in the sense
that running the file should just work as expected if the OS allows it. But
until very recently[0], the Linux kernel would give ETXTBSY in this case. So
make sure we close the file before letting other processes know that it's
usable.

closes https://codeberg.org/ziglang/zig/issues/31563

[0] 2a010c4128
2026-03-25 19:33:43 +01:00
Alex Rønne Petersen
8a517285ce Merge pull request 'std.heap.ArenaAllocator/std.heap.FixedBufferAllocator: fix end_index memory ordering' (#31647) from justusk/zig:arena-mem-ord into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31647
Reviewed-by: jacobly <jacobly@noreply.codeberg.org>
2026-03-25 18:27:03 +01:00
Justus Klausecker
5363a81a57 std.heap.FixedBufferAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:45 +01:00
Justus Klausecker
3af5f81e11 std.heap.ArenaAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:43 +01:00
Justus Klausecker
9bfe827ade Revert "std.heap.ArenaAllocator: Make resize and free check whether allocation is within current node more rigorously"
This reverts commit 589bcb2544.

The scenario presented in the reverted commit cannot actually happen.
Even if there are two contiguous arena nodes N1 and N2 and the `end_index`
of N1 points to somewhere in N2, a `resize` can never lead to an increase
of the `end_index` of N1 since it checks whether it's `<= size` first.
A `resize`/`free` *can* decrease `end_index`, but even if it is wrongly
assumed that some allocation that belongs to N2 actually belongs to N1
based on the `end_index` of N1, it can only ever be decreased to the start
of the buffer of N2. That's because a valid allocation of N2 logically
cannot be at any lower address than N2 itself. And any point still in N2
can never also be in N1, so there's no danger of overwriting any other
allocations of N1.
2026-03-25 11:20:21 +01:00
Andrew Kelley
94355f1920 README: add information about installation via bootstrap.c
closes #31650
2026-03-25 01:43:12 -07:00
rpkak
8f6bad065e std.Thread.setName/getName: remove wrong error handling
std.posix.prctl already does error handling.
According to the man page PR_SET_NAME(2const), 0 is returned on success.
2026-03-25 08:10:25 +01:00
Jake Greenfield
4431ca28b8 fix Windows clock handling
Address two separate but related issues:
- Return value of `RtlQueryPerformanceFrequency` was used inconsistently; it
  returns a nonzero value to indicate success.
- `timeoutToWindowsInterval` wasn't converting absolute deadlines back to the
  Windows epoch before passing them to the system, which meant that values (in
  the Unix epoch) were always in the distant past, so sleeps would return
  immediately.

Fixes #31653
2026-03-24 21:33:27 -04:00
akhildevelops
eec244c5a2 std.crypto.tls.Client: expose InitError (#31610)
Fixes: https://codeberg.org/ziglang/zig/issues/31581
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31610
Co-authored-by: akhildevelops <akhildevelops@noreply.codeberg.org>
Co-committed-by: akhildevelops <akhildevelops@noreply.codeberg.org>
2026-03-25 00:56:22 +01:00