Commit graph

32901 commits

Author SHA1 Message Date
geemili
6ef2384c07 std.DynLib: add support for DT_GNU_HASH sections in elf files 2025-02-22 17:33:49 -05:00
Chris Covington
b7512c3e5d
Add rapidhash (#22085) 2025-02-22 14:32:48 -08:00
Wyatt Radkiewicz
33ffbb32c9
std.zig.system.NativePaths: Add Homebrew paths (#22738) 2025-02-22 14:22:54 -08:00
David Rubin
36fc2d2607 AstGen: make layout specifiers on opaque containers a compile error 2025-02-22 17:21:34 -05:00
Andrew Kelley
61ee9f9415
Merge pull request #22606 from dweiller/memmove-opt
compiler-rt: memmove optimisation
2025-02-22 17:14:06 -05:00
Andrew Kelley
42438ce8b2
Merge pull request #22929 from schtvn/type_fn_docs_improvements
Autodoc: Improve documentation for common types declared as type functions
2025-02-22 17:10:45 -05:00
Andrew Kelley
0dcba03b67
Merge pull request #22902 from ianprime0509/autodoc-error-reporting
Autodoc: improve error reporting
2025-02-22 17:03:52 -05:00
mlugg
cc64295a63
langref: document modules, root source files, etc 2025-02-22 21:01:44 +00:00
mlugg
f0b331e95a
langref: embrace the term "illegal behavior"
Also standardise the terms "safety-checked" and "unchecked".
2025-02-22 21:01:44 +00:00
mlugg
def7e2f20a
langref: improve description of @fieldParentPtr 2025-02-22 21:01:44 +00:00
Alex Rønne Petersen
21eb757497
llvm: Use inline variants of memcpy/memset intrinsics when using -fno-builtin.
This is a correctness issue: When -fno-builtin is used, we must assume that we
could be compiling the memcpy/memset implementations, so generating calls to
them is problematic.
2025-02-22 15:06:40 +01:00
Alex Rønne Petersen
41b179ca09
llvm.Builder: Update some intrinsic definitions for LLVM 19. 2025-02-22 15:06:37 +01:00
Alex Rønne Petersen
31f353cd92 musl: Fix typo in m68k clone() assembly. 2025-02-22 08:13:44 +01:00
Andrew Kelley
6fe1993d80 fix ArrayHashMap setKey when store_hash=true 2025-02-22 00:44:35 -05:00
Alex Rønne Petersen
f87b443af1 link.MachO: Add support for the -x flag (discard local symbols).
This can also be extended to ELF later as it means roughly the same thing there.

This addresses the main issue in #21721 but as I don't have a macOS machine to
do further testing on, I can't confirm whether zig cc is able to pass the entire
cgo test suite after this commit. It can, however, cross-compile a basic program
that uses cgo to x86_64-macos-none which previously failed due to lack of -x
support. Unlike previously, the resulting symbol table does not contain local
symbols (such as C static functions).

I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty
2025-02-22 06:35:19 +01:00
Andrew Kelley
a7467b9bb2
Merge pull request #22941 from Techatrix/config-header
std.Build.Step.ConfigHeader: improve handling of autoconf style headers
2025-02-22 00:25:09 -05:00
Jacob Young
300cb4881f x86_64: rewrite scalar @bitReverse 2025-02-22 00:05:47 -05:00
Alex Rønne Petersen
fc7a0c4878 Sema: Fix fnptr alignment safety checks to account for potential ISA tag.
As seen on e.g. Arm/Thumb and MIPS (MIPS16/microMIPS).

Fixes #22888.
2025-02-22 04:12:46 +01:00
Kiëd Llaentenn
d31bda13cb std.atomic: make cache_line const a comptime_int
This fixes potential issues and unintended coercions in other areas,
such as std.ArrayList.
2025-02-22 03:48:09 +01:00
Mason Remaley
339b628d4c
Output zig targets as ZON instead of JSON (#22939)
* Adds startTupleField/startStructField, makes pattern in print targets less verbose

* Makes some enums into strings

* Start/finish renamed to begin/end

I feel bad changing this, but I don't know why I named them this way in the first place.
Begin/end is consistent with the json API, and with other APIs in the wild that follow this pattern.
Better to change now than later.
2025-02-21 21:40:57 -05:00
Frank Denis
65e7ede499 crypto.Ed25519.KeyPair: return an error rather than assert
When runtime safety is turned on, `Ed25519.fromSecretKey()` can
currently hit an assertion if the format of the secret key is
invalid.

Return an error instead, so that applications can recover.
2025-02-21 22:45:38 +01:00
Constantin Bilz
af2b6893e2 std.Build.Step.ConfigHeader: Add tests for Autoconf @FOO@ variables 2025-02-21 15:22:39 +01:00
Constantin Bilz
62e388e73e std.Build.Step.ConfigHeader: Add support for Autoconf @FOO@ variables
Add the new style `Style.autoconf_at`. Rename the existing
`Style.autoconf` (which uses `#undef` directives) to
`Style.autoconf_undef`.
2025-02-21 15:22:39 +01:00
Alex Rønne Petersen
05d8b565ad wasi-libc: Deduplicate sources and headers with regards to upstream musl.
Unfortunately some duplicate files must remain in lib/libc/wasi/libc-top-half
because they include internal headers *in the same directory* which have edits
relative to upstream musl. Because C is an amazing language, there is no way to
make it so that e.g. upstream musl's src/stdio/fputc.c includes wasi-libc's
src/stdio/putc.h instead of the upstream putc.h. The preprocessor always
searches the current directory first for quote includes.

Anyway, this still takes us from 2.9M to 1.4M for the combination of
lib/libc/wasi and lib/libc/include/wasm-wasi-musl, so I still call it a win.
2025-02-21 09:23:50 +01:00
Alex Rønne Petersen
31e7c95bd2 std.time: Make tests less flaky.
For the Timer decltest in particular, the margin check is not going to help if
the kernel just decides not to schedule the thread for a while after we call
timer.reset().

Failure observed here: https://github.com/ziglang/zig/actions/runs/13443634035/job/37563803341?pr=22909
2025-02-21 09:03:46 +01:00
Pat Tullmann
8d9bb97461 posix: access/accessZ/faccessat/faccessatZ can return AccessDenied or PermissionDenied
`EACCES` is returned if the file mode bit (i.e., user/group/other rwx
bits) disallow access.  `EPERM` is returned if something else denies
access (immutable bit, SELinux, capabilities, etc).  This somewhat subtle
no-access distinction is part of POSIX.  For now map both to
`error.PermissionDenied` to keep the error signature unchanged.  See
duopoly.

This PR is effecitvely an update/simplification of PR #19193.

Tested locally with an immutable file.

Fixes #22733 and #19162.
2025-02-21 07:29:15 +01:00
Benjamin Thompson
a8d3760c5b
added compile_error test coverage for issue 17166 2025-02-21 07:00:37 +01:00
Xavier Bouchoux
84ece5624a fix -fsanitize-coverage-trace-pc-guard and fuzzer support for C compile units
- allow `-fsanitize-coverage-trace-pc-guard` to be used on its own without enabling the fuzzer.
   (note that previouly, while the flag was only active when fuzzing, the fuzzer itself doesn't use it, and the code will not link as is.)

 - add stub functions in the fuzzer to link with instrumented C code (previously fuzzed tests failed to link if they were calling into C):
   while the zig compile unit uses a custom `EmitOptions.Coverage` with features disabled,
   the C code is built calling into the clang driver with "-fsanitize=fuzzer-no-link" that automatically enables the default features.
	(see de06978ebc/clang/lib/Driver/SanitizerArgs.cpp (L587))

 - emit `-fsanitize-coverage=trace-pc-guard` instead of `-Xclang -fsanitize-coverage-trace-pc-guard` so that edge coverrage is enabled by clang driver. (previously, it was enabled only because the fuzzer was)
2025-02-21 06:06:26 +01:00
Jari Vetoniemi
aa5c6c027c linux: add UDP socket options 2025-02-21 06:05:04 +01:00
Ryan Liptak
bbd13ab961 rescanMac: Avoid overallocating/overreading by millions of bytes
readAtLeast is greedy and will read the entire length of the buffer if it can. However, reading past the end of the cert in this case is useless, so reading the full length of the buffer just puts an increasingly large (due to the growth algorithm of ArrayList) collection of wasted bytes after each cert in cb.bytes.

In practical terms, this ends up saving potentially millions of bytes of wasted reads/allocations. In my testing, after reading the keychain files on my machine, cb.bytes ends up with these capacities:

- Before: cb.bytes.capacity = 32720747
- After: cb.bytes.capacity = 251937

That's a decrease of 99.2%

Additionally, swaps to readNoEof since it should be an error to hit EOF without reading the full cert size.
2025-02-20 22:16:05 +01:00
Alex Rønne Petersen
253e641ea3 test: Disable packet timeout for debugger tests.
On my machine, the defaults are 5 seconds (LLDB) and 2 seconds (GDB). These are
too low on the CI machines during high load, and the CI system itself already
enforces a timeout on jobs anyway, so just disable the timeout altogether.
2025-02-20 21:39:54 +01:00
Gabriel Borrelli
8e293ea8bd std.c: define MADV for darwin 2025-02-20 20:42:24 +01:00
Christian Fillion
dbc886fd04 translate-c: fix division and modulo of >8-bit stdint.h types in macros
Broke in c616141241 and e64eef366c
2025-02-20 13:33:59 +02:00
Frank Denis
84cdb62159
std.crypto: add the ability to explicitly tag a value as secret (#19907)
* std.crypto: add the ability to explicitly tag a value as secret

It turns out that Valgrind can be a very useful tool to check that secrets
are not leaked via side channels involving lookups or conditional jumps.

Valgrind tracks uninitialized data, and memcheck reports operations
involving uninitialized values. By permanently or temporarily telling
Valgrind that a memory region containing secrets is uninitialized, we can
detect common side-channel vulnerabilities.

For example, the following code snippets would immediately report that the
result is not computed in constant time:

```zig
classify(&key);
const len = std.mem.indexOfScalar(u8, &key, 0);
```

```zig
classify(&key);
const idx = key[0];
x += idx;
```

```zig
var x: [4]u8 = undefined;
std.crypto.random.bytes(&x);
classify(&x);
if (std.mem.eql(u8, "test", &x)) return;
```

This is not fool-proof, but it can help a lot to detect unwanted compiler
optimizations.

Also, right now, this is relying on Valgrind primitives, but these
annotations can be used to do more interesting things later, especially with
our own code generation backends.

* Update for Zig 0.14

* Remove checks for Valgrind enablement
2025-02-20 12:32:37 +01:00
Jari Vetoniemi
c41bc20ec7 linux: add IORING_RECVSEND_BUNDLE 2025-02-20 12:09:38 +01:00
Frank Denis
541d54a37d Clarify that ed25519.generateDeterministic() can be used outside tests
Fixes #22946
2025-02-20 09:01:13 +01:00
Pat Tullmann
d0e288ab18 lib/std/posix/test.zig: enable disabled tests using CWD
Four tests in lib/std/posix/test.zig were disabled because they created
fixed-name files in the current working directory, and this caused
problems if tests were running in parallel with other build's tests.

This PR fixes those tests to all use `std.testing.tmpDir` to create unique
temporary names and directories.

Also clean the tests up to more consistently use `defer` to clean up, or
to just rely on tmpDir cleanup to remove individual files.

Working on these tests revealed a bunch of stale WASI code paths in
posix.zig, fixed by replacing stale `wast.AT.FDCWD` references with just
`AT.FDCWD`.

Fixes #14968.
2025-02-20 08:44:09 +01:00
Frank Denis
8d824dfdd0
crypto.pwhash.bcrypt: make silently_truncate_password a member of Params (#22792)
* bcrypt: make silently_truncate_password a member of Params

This removes the need for having both `bcrypt()` and
`bcryptWithTruncation()` in the public API.

And whether truncation happens or not becomes even more explicit.

* Update crypto benchmark
2025-02-19 22:37:51 +01:00
Andrew Kelley
bd237bced4
Merge pull request #22932 from jacobly0/x86_64-rewrite
x86_64: start rewriting bit counting operations
2025-02-19 11:37:40 -08:00
Techatrix
c1c6f08296
std.Build.Step.ConfigHeader: permit inserting enum values 2025-02-19 09:34:46 +01:00
Techatrix
344db9e26b
std.Build.Step.ConfigHeader: skip trailing whitespace in autoconf header 2025-02-19 09:34:26 +01:00
Techatrix
7e548af8b1
std.Build.Step.ConfigHeader: allow using autoconf values multiple times 2025-02-19 09:34:26 +01:00
Techatrix
c390f55e72
add a standalone test for autoconf style addConfigHeader 2025-02-19 09:34:25 +01:00
Nico Elbers
0cf6ae290b zon.stringify: Correctly serialize unions with void fields
Closes #22933
2025-02-19 07:21:59 +01:00
sidharta
59dc15fa0a docs: update old reference from builtin.Type.Struct to builtin.Type.@"struct" 2025-02-18 23:35:16 +01:00
Robin Voetter
4720a79477
Merge pull request #22889 from alichraghi/ali_spv
spirv: miscellaneous stuff
2025-02-18 21:14:02 +01:00
Jacob Young
7d70d7b215 x86_64: rewrite scalar @popCount 2025-02-18 09:47:44 -05:00
Jacob Young
ebea56d279 x86_64: rewrite scalar @ctz 2025-02-18 09:47:44 -05:00
Ali Cheraghi
7872082939
spirv: extend supported c constraint values 2025-02-18 18:08:51 +03:30
Ali Cheraghi
d5e1cb3ea2
spirv: ziggify and remove unknown spirv features
`OpCapability` and `OpExtension` now can also be emitted from inline assembly
2025-02-18 18:08:47 +03:30