Commit Graph

801 Commits

Author SHA1 Message Date
Mason Remaley 6bf583c4ba Further separation of stack trace and error return trace 2026-04-12 04:01:29 -07: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
Andrew Kelley 2322d45d80 Merge pull request 'Implement variadic functions for Win64 in the x86_64 backend' (#31672) from kcbanner/zig:win64_varargs into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31672
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-12 01:34:16 +02:00
Carl Åstholm 3d48264365 Fix -fwasmtime not inheriting environment variables 2026-04-11 12:23:49 -07:00
Alex Rønne Petersen d6f43caadf Merge pull request 'audit: handle process.Child.Term exhaustively and give useful exit information on process exit' (#31018) from murtaza/zig:child.term-audit into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31018
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-04-11 00:59:11 +02:00
Andrew Kelley c3a862522b std: remove managed array hash map variants
And deprecate all the API names except for:
* `std.array_hash_map.Auto`
* `std.array_hash_map.String`
* `std.array_hash_map.Custom`
2026-04-10 17:39:45 +02:00
Andrew Kelley 0606af509f translate-c build step: remove use_clang field
This no longer does anything.
2026-04-09 14:05:45 -07:00
Jan200101 9fd63daff2 std.Build.Step.ConfigHeader: handle leading whitespace for cmake 2026-04-08 14:24:48 +02: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
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 3e0f55fcc7 Merge pull request 'add an ast smith' (#31635) from gooncreeper/zig:ast-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31635
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:41:05 +02:00
johan0A 022c76fc89 std.Build.Module: fix dangling slice in dynamic linker arg 2026-04-02 15:19:14 +02:00
Andrew Kelley 617979ef26 std.Build.WebServer: use Io.concurrent rather than threads
allows the code to also work in evented mode
2026-04-01 02:54:25 -07:00
Andrew Kelley 9b1eaad13f std.Build.Step.ConfigHeader: add addIdent function
for when you need to emit a bare identifier but from a string
2026-03-30 00:37:39 -07:00
kcbanner 2b72c0d304 - Fixup producesCompilerRtDynLib conditions
- Fixup skipping the new float varags test on .stage2_llvm
2026-03-28 02:51:20 -04: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
Kendall Condon 2aee0cd6b9 add an ast smith
This generates zig ASTs from `testing.Smith` and is based off the
langref's PEG.

The choice to not build the Ast while generating and instead parsing it
afterwards makes the smith more versatile by not being tied to a single
implementation at a cost of efficiency.

Additionally, a new function `boolWeighted` was added to `Smith` due to
its frequent use in `AstSmith`.
2026-03-25 17:27:18 -04:00
kcbanner 4e3fcbea84 - Build: support installing the compiler_rt.dll
This is an extension of the existing hack used for the x86_64 backend combined with the Coff linker
2026-03-25 00:58:37 -04:00
Jacob Young 3c8b96df6d windows: use enums for boolean types 2026-03-20 02:25:16 +01:00
Alex Rønne Petersen 10256e1b81 std.Build.WebServer: fix endianness of written update/exit messages 2026-03-19 10:44:21 +01:00
Jacob Young 9ac1386c10 std.Io.Threaded: windows networking without ws2_32 2026-03-18 20:13:59 -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 bca057afd2 Smith.Weight: do not use of indexOfScalar
In larger fuzz tests this can cause the eval branch quota to be
exceeded.
2026-03-11 21:16:52 -04:00
Kendall Condon c3e6ff7206 libfuzzer: use error.SkipZigTest 2026-03-11 21:14:46 -04:00
Andrew Kelley b4ffb402c0 translate-c build step: handle system libraries
closes #31450
2026-03-11 04:57:25 +01:00
Matthew Lugg 8eefe86939 std: remove default values from ArrayList
These were deprecated in the 0.14.0 release cycle almost a year ago, so
they can definitely be deleted now.
2026-03-10 10:26:08 +00: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
hemisputnik 99229ceb55 std.Io.{Writer|Duration}: move duration formatting to a format method
Remove the `{D}` format specifier. It is moved into `std.Io.Duration` as
a format method.

Migration plan:

```diff
-writer.print("{D}", .{ns});
+writer.print("{f}", .{std.Io.Duration{ .nanoseconds = ns }});
```

All instances where `{D}` was used have been changed to use
`std.Io.Duration` and `{f}`.

Fixes #31281
2026-02-28 02:46:04 +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
Kendall Condon 1a9d75ebe0 fix fuzzing speed with prior runs 2026-02-13 17:58:09 -05:00
Kendall Condon af1e196db3 align end of elf archives
The end of the archive needs to also be aligned to a two-byte boundary,
not just the start of records. This was causing lld to reject archives.

Notably, this was happening with compiler_rt when rebuilding in fuzz
mode, which is why this commit is included in this patchset.
2026-02-13 17:58:09 -05:00
Kendall Condon 3c9024be08 update fuzzing for build system changes 2026-02-13 17:58:09 -05:00
Jacob Young 2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00
Andrew Kelley b600b6e5e0 std.posix: remove close function 2026-02-11 23:37:31 +01:00
antme0 fb18f2096a Allow build.zig scripts to define module definition files (.def) when building win32 dlls. 2026-02-09 07:58:13 +01:00
Jacob Young b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley 2a193a3987 std: move GetFinalPathNameByHandle to Io.Threaded
unfortunately this function calls NtCreateFile so it has to participate
in cancelation
2026-02-04 16:27:13 -08:00
Jacob Young 71156aff80 std.Progress: implement ipc resource cleanup 2026-02-04 15:20:10 -05:00
Jacob Young ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05: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
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
Andrew Kelley a41ee5994d std.Build.Step: evalZigProcess handles EndOfStream
and a happy little info log when the process needs to be restarted
2026-01-30 22:03:14 -08:00
Matthew Lugg f8828e543a std.Build: fully upgrade Step.Run to std.Io timing (and fix a typo) 2026-01-30 22:03:14 -08:00
Andrew Kelley 6a1fd3c69d std.Io.File.MultiReader: make checkAnyError exclude EndOfStream 2026-01-30 22:03:14 -08:00
Andrew Kelley efa502a1cd std.Build.Step.Run: gracefully handle test runner misbehavior
specifically if it misbehaves after sending a message header but not the
body
2026-01-30 22:03:14 -08:00
Andrew Kelley 523aa213c9 std.Io.Threaded: batchWait and batchCancel for Windows 2026-01-30 22:03:14 -08:00
Andrew Kelley 372e8e54d3 compiler: update for std.Io.File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley e56563ce3f std.Io.File.MultiReader: implementation fixes 2026-01-30 22:03:14 -08:00