533 Commits

Author SHA1 Message Date
Alex Rønne Petersen ca0b3318a0 std.Target: update CPU and feature data to LLVM 22 2026-04-25 21:54:47 +02:00
andrew.kraevskii bbab366b78 Audit usages of toOwnedSlice (#32001)
Followup to #30769

I grepped for `try .*toOwnedSlice` and checked all of them by hand.

Fixes a bunch of memory leaks removes usages or `errdefer` and `vars` in some places. I also switched array_list.Managed to ArrayList where it was convenient.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32001
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-22 19:35:46 +02:00
glowsquid 0b768cd9dd zig reduce: fix compilation (#31930)
fixes #31926

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31930
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-22 02:00:41 +02:00
Ryan Liptak 3252a05531 Prefer <err> => |e| return e over <err> => return <err>
Avoids the potential for a typo on the `return <err>` side of the prong
2026-04-20 18:03:14 -07:00
Mason Remaley e2c3920fb1 Renames buffer first allocator in compiler and std 2026-04-18 14:51:49 -07:00
Mason Remaley 8c96487bb9 Updates all uses of StackFallbackAllocator 2026-04-18 14:51:49 -07:00
Sam Connelly 17e0afd0e5 feat: init eZ80 arch via CBE 2026-04-16 19:21:16 +02:00
Andrew Kelley 67a5b6e5e8 delete @cImport from the language
closes #20630
2026-04-15 17:43:53 -07:00
Mason Remaley 5984d5dbde Fixes compiler error in fuzz tester due to stack trace and error trace separation 2026-04-15 22:52:57 +02:00
Mason Remaley 87fb7df257 Updates stack trace vs error return trace in more places 2026-04-12 04:01:30 -07:00
Andrew Kelley edfc4727e2 Merge pull request 'init objdump subcommand' (#31827) from objdump into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31827
2026-04-12 10:38:19 +02:00
Andrew Kelley f7dabba561 objdump: recognize some file types 2026-04-11 18:56:51 -07:00
Andrew Kelley 1809a19c27 add objdump subcommand
does nothing so far
2026-04-11 18:56:51 -07:00
Andrew Kelley 5149128d22 update translate-c to latest
upstream commit 46b5609b5ac4c0a896217d1d984f3ae50e4810b5
2026-04-11 15:17:46 -07:00
Ryan Liptak 67c6ac947a Update resinator for latest aro 2026-04-11 15:17:46 -07:00
Andrew Kelley 68bf81432c update aro to latest
upstream commit 5f5a050569a95ecc40a426f0c3666ae7ef987ede
2026-04-11 15:17:46 -07:00
murtaza 4a1383d987 process.Child: use std.posix.SIG instead of u32 for Child.Term stopped field 2026-04-07 10:27:21 +02:00
murtaza 07b49c61ff audit: handle process.Child.Term exhaustively and give useful exit information 2026-04-07 10:27:01 +02:00
nektro e73257dec2 lib/std: BitSet,EnumSet: replace initEmpty/initFull with decl literals (#31469)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31469
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: nektro <hello@nektro.net>
Co-committed-by: nektro <hello@nektro.net>
2026-04-05 05:12:13 +02:00
Kendall Condon d8ba173e5e multiprocess fuzzing
- New Features

-- Multiprocess Fuzzing

The fuzzer now is able to utilize multiple cores. This is controllable
with the `-j` build option. Limited fuzzing still uses one core.

-- Fuzzing Infinite Mode

When provided multiple tests, the fuzzer now switches between them and
prioritizes the most effective and interesting ones. Over time already
explored tests will become barely run compared to tests yielding new
inputs.

-- Crash Dumps

Crashing inputs are now saved to a file indicated by the crash message.
It is recommended to use these files to reproduce the crash using
`std.testing.FuzzInputOptions.corpus` and @embedFile.

- Design

Each fuzzing process is assigned an instance id which has the following
uses:
* In conjunction with the pc hash and running test index, they uniquely
  identify input files in the case of a crash.
* It is combined with the test seed for a unique rng seed.
* Instance 0 is solely responsible for syncing the filesystem corpus.

When new inputs are found, they are sent to the build server. It then
distributes the new input to the other instances. Each instance has a
concurrent poller managed by the test runner which sends received
inputs to libfuzzer. (note that this is affected by #31718 and so can
(rarely) deadlock)

For fuzzing infinite mode, the test runner now receives a list of tests
from the build server. The fuzzer runs tests in batches of one second,
approximated in cycles by the previous batch's run speed. Tests finding
new inputs or with few runs are given a higher run chance. The baseline
run chance is based off the recency of the last find and the number of
pcs the test has hit.
2026-04-03 12:27:34 +02: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
Kendall Condon 02e8339ca7 zig build fmt 2026-03-12 17:44:03 -04:00
Kendall Condon 5ecef2934a rerun fuzz tests from name instead of index
The indexes can change between recompilation due to conditional
compilation and compiler quirks. While unit test names are still not a
perfect solution, they are better than indexes.
2026-03-11 21:19:22 -04:00
Kendall Condon c3e6ff7206 libfuzzer: use error.SkipZigTest 2026-03-11 21:14:46 -04:00
Meghan Denny bd5dc75068 std: remove GeneralPurposeAllocator alias 2026-03-11 01:55:49 +01:00
Alex Rønne Petersen 502cab9ae3 test_runner: actually print the error that caused a runner failure
part of the Stop Throwing Away Useful Information initiative
2026-03-10 11:28:36 +00:00
Matthew Lugg 5ec3a0cd54 std: update for language changes
Now that zig1.wasm is updated, apply the matching standard library
changes.

The main one is in `std.builtin.Type`, where `alignment` fields now have
type `?usize` rather than `comptime_int`.

Additionally, we need to add explicit backing integers to some packed
unions, because (due to https://github.com/ziglang/zig/issues/24714)
they need explicit backing integers to be used in `extern` contexts.
This change could not happen before now, because prior to this branch,
packed unions did not allow explicit backing integer types (that is,
this branch implemented https://github.com/ziglang/zig/issues/25350).
2026-03-10 10:38:50 +00:00
Matthew Lugg 4eb8360911 compiler: various lil' fixes 2026-03-10 10:26:14 +00:00
Matthew Lugg 82be338964 aro: stop depending on ArrayList default field values 2026-03-10 10:26:13 +00:00
Andrew Kelley 80625990d5 std: different mechanism for disabling network dependency
On Windows, it is sometimes problematic to depend on ws2_32.dll. Before,
users of std.Io.Threaded would have to call ioBasic() rather than io()
in order to avoid unnecessary dependencies on ws2_32.dll. Now, the
application can disable networking with std.Options.

This change is necessary due to moving networking functionality to
be based on Io.Operation, which is a tagged union.
2026-03-08 19:20:34 -07:00
Ryan Liptak f16eb18ce8 Use / as path separator when writing tar files
The tar format expects `/`, although some untar implementations do seem to handle Windows-style `\` path separators (7-Zip at least).

The tar.Writer API can't really enforce this, though, as doing so would effectively make `\` an illegal character when it's really not. So, it's up to the user to provide paths with the correct path separators.

`Build/WebServer.zig` will still output tars with `\` as a path separator on Windows, but that's currently only used during fuzzing which is not yet implemented on Windows.
2026-03-08 02:10:00 +01:00
Andrew Kelley e0173c2ce0 Merge pull request 'rework fuzz testing to be smith based' (#31205) from gooncreeper/zig:integrated-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31205
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-25 20:23:36 +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
Kendall Condon 5d58306162 rework fuzz testing to be smith based
-- On the standard library side:

The `input: []const u8` parameter of functions passed to `testing.fuzz`
has changed to `smith: *testing.Smith`. `Smith` is used to generate
values from libfuzzer or input bytes generated by libfuzzer.

`Smith` contains the following base methods:
* `value` as a generic method for generating any type
* `eos` for generating end-of-stream markers. Provides the additional
  guarantee `true` will eventually by provided.
* `bytes` for filling a byte array.
* `slice` for filling part of a buffer and providing the length.

`Smith.Weight` is used for giving value ranges a higher probability of
being selected. By default, every value has a weight of zero (i.e. they
will not be selected). Weights can only apply to values that fit within
a u64. The above functions have corresponding ones that accept weights.
Additionally, the following functions are provided:
* `baselineWeights` which provides a set of weights containing every
  possible value of a type.
* `eosSimpleWeighted` for unique weights for `true` and `false`
* `valueRangeAtMost` and `valueRangeLessThan` for weighing only a range
  of values.

-- On the libfuzzer and abi side:

--- Uids

These are u32s which are used to classify requested values. This solves
the problem of a mutation causing a new value to be requested and
shifting all future values; for example:

1. An initial input contains the values 1, 2, 3 which are interpreted
as a, b, and c respectively by the test.

2. The 1 is mutated to a 4 which causes the test to request an extra
value interpreted as d. The input is now 4, 2, 3, 5 (new value) which
the test corresponds to a, d, b, c; however, b and c no longer
correspond to their original values.

Uids contain a hash component and type component. The hash component
is currently determined in `Smith` by taking a hash of the calling
`@returnAddress()` or via an argument in the corresponding `WithHash`
functions. The type component is used extensively in libfuzzer with its
hashmaps.

--- Mutations

At the start of a cycle (a run), a random number of values to mutate is
selected with less being exponentially more likely. The indexes of the
values are selected from a selected uid with a logarithmic bias to uids
with more values.

Mutations may change a single values, several consecutive values in a
uid, or several consecutive values in the uid-independent order they
were requested. They may generate random values, mutate from previous
ones, or copy from other values in the same uid from the same input or
spliced from another.

For integers, mutations from previous ones currently only generates
random values. For bytes, mutations from previous mix new random data
and previous bytes with a set number of mutations.

--- Passive Minimization

A different approach has been taken for minimizing inputs: instead of
trying a fixed set of mutations when a fresh input is found, the input
is instead simply added to the corpus and removed when it is no longer
valuable.

The quality of an input is measured based off how many unique pcs it
hit and how many values it needed from the fuzzer. It is tracked which
inputs hold the best qualities for each pc for hitting the minimum and
maximum unique pcs while needing the least values.

Once all an input's qualities have been superseded for the pcs it hit,
it is removed from the corpus.

-- Comparison to byte-based smith

A byte-based smith would be much more inefficient and complex than this
solution. It would be unable to solve the shifting problem that Uids
do. It is unable to provide values from the fuzzer past end-of-stream.
Even with feedback, it would be unable to act on dynamic weights which
have proven essential with the updated tests (e.g. to constrain values
to a range).

-- Test updates

All the standard library tests have been updated to use the new smith
interface. For `Deque`, an ad hoc allocator was written to improve
performance and remove reliance on heap allocation. `TokenSmith` has
been added to aid in testing Ast and help inform decisions on the smith
interface.
2026-02-13 22:12:19 -05:00
Kendall Condon e40557b1f7 allow specifying mode in --debug-rt
The motivation is that libfuzzer is slow in Debug mode and bugs usually
manifest late into fuzzing, which makes testing it in ReleaseSafe
useful.
2026-02-13 17:58:09 -05:00
Jacob Young b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley e661e78256 store the Manifest in the fork set 2026-02-06 13:21:13 -08:00
Andrew Kelley 3d33735d73 zig build: add --fork CLI argument
closes #31124
2026-02-06 12:36:29 -08:00
Andrew Kelley 922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -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
Ryan Liptak 05346e123b Add process.Child.Cwd, use it for cwd and remove cwd_dir field
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
2026-02-02 01:41:35 -08:00
Jake Greenfield aacf8ce03d Use MultiReader in zig std 2026-02-01 22:22:47 -05:00
Andrew Kelley b1d1806fef std.process: currentDir -> currentPath
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
2026-01-29 18:47:58 -08:00
Andrew Kelley 649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
murtaza b5770541bd testing: ability to read environment variables from unit tests 2026-01-17 00:40:22 +01:00
Ryan Liptak 9d1a39c50f resinator: Sync with upstream
No functional differences, just some shuffling things around and the removal of the now-obsolete `utils.openFileNotDir`.
2026-01-14 01:04:24 +01:00
Sertonix 47cc233f22 aro: define arch macros for riscv
Fixes some test failure:

test
+- test-standalone
   +- standalone_test_cases
      +- standalone_test_cases.glibc_compat
         +- CheckObject
            +- compile exe native-linux-gnu.2.38 Debug native-linux-gnu.2.38 64 errors
test/standalone/glibc_compat/glibc_runtime_check.zig:11:18: error: C import failed
const c_malloc = @cImport(
                 ^~~~~~~~
referenced by:
    checkReallocarray: test/standalone/glibc_compat/glibc_runtime_check.zig:46:27
    main: test/standalone/glibc_compat/glibc_runtime_check.zig:112:26
    4 reference(s) hidden; use '-freference-trace=6' to see all references
error: translation failure
build/stage3/lib/zig/libc/include/riscv-linux-gnu/bits/wordsize.h:22:3: error: unsupported ABI
2026-01-13 20:01:52 +01:00
Matthew Lugg aebd84b525 build runner: refactor step evaluation logic
The previous logic was made really messy by the fact that upon entry to
the step eval worker, the step may not be ready to run, we may be racing
with other workers doing the same check, and we had already acquired our
RSS requirement even though we might not run. It also required iterating
all dependencies each time we were called to check whether we were even
ready to run yet.

A much better strategy is for each step to have an atomic counter
representing how many of its dependencies are yet to complete. When a
step completes (successfully or otherwise), it decrements this value for
all of its dependants, and if it drops any to 0, it schedules that step
to run. This means each step is scheduled exactly once, and only when
all of its dependencies have finished, reducing redundant checks and
hence contention. If the step being scheduled needs to claim RSS which
isn't available, then it is instead added to `memory_blocked_steps`,
which is iterated by the step worker after a step with an RSS claim
finishes.

This logic is more concise than before, simpler to understand, generally
more efficient, and fixes a bug in the RSS tracking. Also, as a nice
side effect, it should also play a little bit nicer with `Io.Threaded`'s
scheduling strategy, because we no longer spawn extremely short-lived
tasks all the time as we previously did.

Resolves: https://codeberg.org/ziglang/zig/issues/30742
2026-01-09 03:16:39 +01:00
Andrew Kelley 7248b4a4e4 std.fs: deprecate base64 APIs
100% of std.fs is now deprecated.
2026-01-07 17:33:06 -08:00
Andrew Kelley 1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00