Commit graph

37274 commits

Author SHA1 Message Date
lzm-build
ef13a373bc fix assertion argument order in acos/asin/atan 2026-02-14 13:33:55 +08: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
5b9bb0a404 add -Dfuzz-only
Runs only one configuration suitable for fuzzing.
2026-02-13 17:58:09 -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
Andrew Kelley
d2c862e6ff Merge pull request 'Io.Dispatch: introduce grand central dispatch io impl' (#31198) from dispatch into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-13 23:19:32 +01:00
Andrew Kelley
e262a32ad1 Merge branch 'std.math.atan: Add @Vector(?,f32) and @Vector(?,f64) support'
Add SIMD support for atan (f32 and f64), based on the [ARM
impl](https://github.com/ARM-software/optimized-routines/blob/master/math/aarch64/advsimd/atanf.c).
To reduce branching, more polynomial approximation is used.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31195
2026-02-13 12:26:11 -08:00
Andrew Kelley
12e6ac2e8f std.math.atan: simplify type logic 2026-02-13 12:25:53 -08:00
lzm-build
8901d38b7d std.math.atan: Add @Vector(?,f32) and @Vector(?,f64) support 2026-02-13 12:20:53 -08:00
Chris Boesch
07b08b9638 compiler_rt: Implemented missing handling of denormal numbers when dividing f128 (#30198)
Replaces the "flush denormals to zero" placeholder in divtf3.zig with IEEE 754 denormal support including rounding.

fixes #30179

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Chris Boesch <chrboesch@noreply.codeberg.org>
Co-committed-by: Chris Boesch <chrboesch@noreply.codeberg.org>
2026-02-13 20:49:14 +01:00
hubidubi
fd74c5742d std.Io.Threaded: fix FreeBSD Futex max_waiters (#30094)
On FreeBSD, the maximum waiters should be Cs INT_MAX instead of the maximum of a u32. Waiting for the Io.Event in the broadcast test triggers this bug.

Resolves #30715

Co-authored-by: Simon Galli <hubi@hubidubi.net>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30094
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: hubidubi <hubidubi@noreply.codeberg.org>
Co-committed-by: hubidubi <hubidubi@noreply.codeberg.org>
2026-02-13 20:39:38 +01:00
Andrew Kelley
dbfe34167d Merge branch 'jeffective-jeff/libzigc-acosf'
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30996
2026-02-13 11:31:15 -08:00
kj4tmp@gmail.com
004872baec zig libc: acosf: fix fp exceptions
some fp exceptions are prohibited by zig test-libc (libc-test).
Promoting to f64 prevents vectorization of some floating point
divisions. The vectorization has unused lanes which contain zero. On
division the lanes containing zero are divided and trigger the INVALID
fp flags.
2026-02-13 11:30:19 -08:00
kj4tmp@gmail.com
3dc2a1f9ac zig libc: acosf 2026-02-13 11:30:14 -08:00
rpkak
4ea9904923 remove some unused libc files 2026-02-13 19:57:59 +01:00
Jacob Young
0eb1e0c30a crash_report: finish reverting panic changes better
I missed that the types were `pub`.
2026-02-13 12:29:40 -05:00
Jacob Young
2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00
IntegratedQuantum
0bed4fb384 crypto: Allow arbitrary types for secureZeroes
also removed some related ptrCasts
2026-02-13 17:07:03 +01:00
Andrew Kelley
469bf6af07 Merge branch std.Deque: add *Ptr and *Slice functions
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31179
2026-02-12 21:46:19 -08:00
Andrew Kelley
13e42b16cd std.deque: fix typo in unit test 2026-02-12 21:45:52 -08:00
Justus Klausecker
623723507f std.Deque: add peek and *Ptr functions to Iterator
The iterator should be as powerful as manual access via `as` and `asPtr`
to justify its existence.
2026-02-12 21:45:13 -08:00
Justus Klausecker
527e97b252 std.Deque: add *Slice variants of push functions
This mirrors the `*Slice` variants e.g. `std.ArrayList` already provides.
2026-02-12 21:45:13 -08:00
Justus Klausecker
35c5611f07 std.Deque: add *Ptr variants of getter functions
This makes it practical to store large items or items that are meant to
be mutable directly inside of the deque.
It is the responsibility of the user to stop using the returned pointers
after calling a function that could invalidate them.
2026-02-12 21:45:13 -08:00
kineye
f36d0573cd zig libc: add rint 2026-02-12 21:42:38 -08:00
Neel
5132d78e83 libc: implement insque and remque in Zig
Implements insque() and remque() doubly-linked list functions
in lib/c/search.zig and removes musl C implementation.
Contributes to #30978
2026-02-12 21:35:36 -08:00
Andrew Kelley
4a3adaaa23 Merge pull request 'zig libc: implement malloc' (#31177) from libc-malloc into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31177
2026-02-13 06:30:42 +01:00
Karel Marek
37109fa4ef Fix IpAddress.setPort 2026-02-13 06:09:47 +01:00
Andrew Kelley
0957761d5c std.heap.BrkAllocator: fix incorrect assumptions 2026-02-12 16:30:27 -08:00
Andrew Kelley
6296924214 build: bump behavior max_rss 2026-02-12 16:30:24 -08:00
Andrew Kelley
6d52678a6c zig libc malloc: skip export when unit testing
These functions can only be exported when external libc components are
available due to the errno location dependency. Note that even when zig
libc is complete, on Windows, errno location will always be external (in
ucrtbase.dll).
2026-02-12 13:14:51 -08:00
Andrew Kelley
ec02571a30 zig libc malloc: set errno when returning null 2026-02-12 13:14:51 -08:00
Andrew Kelley
0de7668c01 test harness: refmt for readability 2026-02-12 13:14:51 -08:00
Andrew Kelley
21829a5b4a zig libc: export all symbols weak
Normally, libc goes into a static archive, making all symbols
overrideable. However, Zig supports including the libc functions as part
of the Zig Compilation Unit, so to support this use case we make all
symbols weak.
2026-02-12 13:14:51 -08:00
Andrew Kelley
f5d5dbd166 wasi libc: remove malloc defines 2026-02-12 13:14:51 -08:00
Andrew Kelley
e2fccd8dd5 musl: remove macro redefinitions of malloc 2026-02-12 13:14:51 -08:00
Andrew Kelley
6ccabbd4e5 std: brk allocator for single-threaded mode 2026-02-12 13:14:51 -08:00
Andrew Kelley
6744160211 zig libc: implement malloc 2026-02-12 13:14:51 -08:00
Andrew Kelley
5c59a46238 std.heap.PageAllocator: fix not respecting alignments
in remap and resize, alignments larger than page size were incorrectly ignored.
2026-02-12 13:14:51 -08:00
Andrew Kelley
0a61eca22c bump max_rss for module tests 2026-02-12 13:14:51 -08:00
Jacob Young
251f54d1d7 crash_report: finish reverting panic changes 2026-02-12 13:13:45 -05:00
Alex Rønne Petersen
381e231468 Merge pull request 'fix(codegen/llvm): teach llvm to not dllexport hidden exports' (#31180) from GasInfinity/zig:fix-hidden-dllexport into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31180
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-02-12 08:36:15 +01:00
Meghan Denny
13f31bb3c3 std/c: glibc has supported arc4random_buf since 2.36 2026-02-11 15:29:51 -08:00
Andrew Kelley
b600b6e5e0 std.posix: remove close function 2026-02-11 23:37:31 +01:00
Andrew Kelley
ea30f86113 bump maxrss for compiler_rt, libc, and c-abi tests 2026-02-11 23:37:31 +01:00
Andrew Kelley
ba293eb820 Revert "compiler: override debug_io in release + evented mode"
This reverts commit 6840326711.

The commit bungled deinitialization in main.
2026-02-11 10:44:04 -08:00
Pivok
d4217e2119 zig libc: exp10, exp10f, pow10, pow10f (#31163)
See #30978.

Commands i run:
```
$ stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=../../libc-test -Dtest-filter=exp10 -fqemu -fwasmtime --summary line
Build Summary: 725/737 steps succeeded (12 skipped)
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31163
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Pivok <pivoc@protonmail.com>
Co-committed-by: Pivok <pivoc@protonmail.com>
2026-02-11 19:39:40 +01:00
GasInfinity
a6f64096a1
chore(test/standalone): test linking libc in a shared library 2026-02-11 15:48:18 +01:00
GasInfinity
87fa61bdd1
fix(codegen/llvm): teach llvm to not dllexport hidden exports 2026-02-11 10:51:26 +01:00