Commit Graph

13561 Commits

Author SHA1 Message Date
Andrew Kelley 3e6bebbbca configure runner: serialization of Module 2026-05-25 18:54:33 -07:00
Andrew Kelley 648e0e0cc0 configure runner: serialization of compile step 2026-05-25 18:54:33 -07:00
Andrew Kelley 6b040d631f configure runner: add Step.Run serialization 2026-05-25 18:54:33 -07:00
Andrew Kelley 83a3475887 configure runner: implement serialization of InstallArtifact 2026-05-25 18:54:33 -07:00
Andrew Kelley 0b3ca11520 std.Io.Writer: placeholder code for new {q} format character
intendend to print something with double quotes, escaped the same as a
zig string literal.
2026-05-25 18:54:33 -07:00
Andrew Kelley 2e88ac8842 zig build: configure runner basics implemented 2026-05-25 18:54:33 -07:00
Andrew Kelley e10cbf08ee configure/make phase process separation sketch
`zig build` CLI kicks off async task to compile optimized make runner
executable, does fetch, compiles configure process in debug mode, then
checks cache for the CLI options that affect configuration only. On hit,
skips building/running the configure script. On miss, runs it, saves
result in cache.

The cached artifact is a "configuration" file - a serialized build step
graph, which also includes unlazy package dependencies and additional
file system dependencies.

Next, awaits task for compiling optimized make runner executable, passes
configuration file to it. Make runner is responsible for the CLI after
that point.

For the use case of detecting when `git describe` needs to be rerun, we
can allow the configure process to manually add a file system mtime
dependencies, in this case it would be on `.git/index` and `.git/HEAD`.

This will enable two optimizations:

1. The bulk of the build system will not be rebuilt when user changes
   their configure script.

2. The user logic can be completely bypassed when the CLI options
   provided do not affect the configure phase - even if they affect the
   make phase.

Remaining tasks in the branch:

* some stuff in `zig build` CLI is `@panic("TODO")`.
* configure runner needs to implement serialization of build graph using
  std.zig.Configuration
* build runner needs to be transformed into make runner, consuming
  configuration file as input and deserializing the step graph.
* introduce depending only on a file's metadata and *not* its contents
  into the cache system, and add a std.Build API for using it.
2026-05-25 18:54:33 -07:00
Kendall Condon 65819004f3 workaround surfaced backend bugs
self-hosted wasm workaround provided by pavelverigo in #31991

powerpc workarounds provided by alexrp in #31991
2026-05-25 18:38:01 -07:00
Kendall Condon c805c72289 upgrade most uses of DebugAllocator to SafeAllocator 2026-05-25 18:37:24 -07:00
Kendall Condon a9423234a6 add SafeAllocator
Implements a thread-safe allocator with the following guarantees:
* `deinit` reports all leaks and frees all backing memory.
* All allocation mismatches result in either a panic or segmentation
  fault.
* Allocations from other `SafeAllocator` instances cause a panic (if
  `Options.canary` differ).
* Double frees and operation (resize, remap, and free) races panic or
  segmentation fault.

Given the backing allocator does not reuse memory, it does not reuse
memory either and
* Most writes after free will segmentation fault or are eventually
  detected and panic.

`std.heap.DebugAllocator` has been deprecated (I have also deprecated
`std.heap.Check` since this was its last usage and returning a `usize`
leak count is a much cleaner approach).

- General Design

Every allocation is trailed by an `AllocFooter` which contains metadata
for the allocation and stack traces. It is protected by a checksum to
catch corruption from allocation overwrites and report canary
mismatches. An allocation's memory has a minimum alignment of
`AllocFooter` so that the footer is at a fixed offset determined from
the allocation size. An allocation's memory is stored either:
* Inside linearly-filled buckets for small allocations.
* Inside an allocation directly from the backing allocator.

To track allocations, each thread maintains a table of backing
allocations. The table may be modified by other threads in the case of
a producer-consumer operation, so the table is a linked list only
expanded by creating new segments. Each thread maintains a linked list
of free entries, which may contain entries from other threads' tables.

In the case of producer-consumer operations, acquire/release ordering
is assumed to be provided externally. This is also assumed by all other
thread-safe allocators that reuse memory as otherwise there would be
data races on reuse of allocated memory.

- Fuzz Tests

Two fuzz tests have also been added for the allocator. They check that
there is no memory reuse, that returned memory is writable, and that
it is not overwritten. The multi-threaded fuzz test spawns a number of
worker threads which are used for all the test runs. I have run these
tests extensively under TSAN.

- Performance Measurements

Building the standard library tests with a RelaseSafe compiler build
and `-Ddebug-allocator`:

```
Benchmark 1 (3 runs): ./master-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          29.4s  ±  157ms    29.2s  … 29.5s           0 ( 0%)        0%
  peak_rss           2.24GB ± 3.49MB    2.23GB … 2.24GB          0 ( 0%)        0%
  cpu_cycles          143G  ±  999M      142G  …  144G           0 ( 0%)        0%
  instructions        268G  ± 5.22M      268G  …  268G           0 ( 0%)        0%
  cache_references   13.1G  ± 88.8M     13.0G  … 13.2G           0 ( 0%)        0%
  cache_misses       2.38G  ± 30.7M     2.35G  … 2.41G           0 ( 0%)        0%
  branch_misses       634M  ± 6.22M      629M  …  641M           0 ( 0%)        0%
Benchmark 2 (3 runs): ./branch-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          22.1s  ± 88.6ms    22.0s  … 22.2s           0 ( 0%)        - 24.7% ±  1.0%
  peak_rss           1.11GB ±  799KB    1.11GB … 1.11GB          0 ( 0%)        - 50.3% ±  0.3%
  cpu_cycles          136G  ±  480M      136G  …  137G           0 ( 0%)        -  4.4% ±  1.2%
  instructions        273G  ± 2.07M      273G  …  273G           0 ( 0%)        💩+  1.6% ±  0.0%
  cache_references   12.3G  ± 71.3M     12.2G  … 12.4G           0 ( 0%)        -  6.0% ±  1.4%
  cache_misses       2.02G  ± 11.5M     2.01G  … 2.03G           0 ( 0%)        - 14.9% ±  2.2%
  branch_misses       569M  ± 2.65M      567M  …  572M           0 ( 0%)        - 10.2% ±  1.7%
```
2026-05-25 18:32:36 -07:00
Alex Rønne Petersen ef14d8ad3f std.Target.Query: deprecate allocDescription()
This just delegates to zigTriple() and has no clear reason for existing. It also
isn't used anywhere in the codebase.
2026-05-26 01:57:59 +02:00
Alex Rønne Petersen ea2032fa0f std.Target: remove a TODO that's likely never going to be addressed 2026-05-26 01:57:59 +02:00
Alex Rønne Petersen 31f157d807 std.Target: add win11_br and win11_kr to WindowsVersion 2026-05-24 08:54:21 +02:00
Alex Rønne Petersen b868412444 std.Target: add Abi.call0 for xtensa
closes https://codeberg.org/ziglang/zig/issues/30950
2026-05-23 15:51:46 +02:00
Alex Rønne Petersen d591145f5d Merge pull request 'add m88k-openbsd target info and stack tracing + some bonus commits' (#35429) from alexrp/zig:m88k into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35429
2026-05-23 13:54:35 +02:00
Alex Rønne Petersen dd09f755fe std.atomic: add m88k to cacheLineForCpu() 2026-05-23 11:02:56 +02:00
Alex Rønne Petersen 79e87e5753 std.debug: add m88k-openbsd support
closes https://codeberg.org/ziglang/zig/issues/31817
2026-05-23 11:02:56 +02:00
Alex Rønne Petersen ffb7d76e11 std.start: add m88k support 2026-05-23 11:02:56 +02:00
Alex Rønne Petersen 07262bddd6 std: add basic target information for m88k-openbsd
closes https://codeberg.org/ziglang/zig/issues/31816
2026-05-23 11:02:55 +02:00
Alex Rønne Petersen a439978f05 std.debug.cpu_context: fix alpha-openbsd ucontext_t
These fields need to be wrapped in an mcontext field so the common code in
fromPosixSignalContext() can work with it.
2026-05-23 11:02:38 +02:00
Alex Rønne Petersen b87caa4546 std.Target: fix default calling convention for m68k
Apparently everyone actually just uses the GNU ABI.
2026-05-23 11:02:36 +02:00
Alex Rønne Petersen b9a00fe6aa std.Target: fix default calling convention for ps3 2026-05-23 10:22:40 +02:00
Alex Rønne Petersen 0cafb9b591 std.Target: fix default calling convention for x32 2026-05-23 08:51:32 +02:00
Alex Rønne Petersen 388c0918d6 std.Target: add standard dynamic linker paths for or1k 2026-05-23 08:51:14 +02:00
Alex Rønne Petersen 9a578b7b48 std.Target: glibc doesn't support thumb, so has no standard dynamic linker path 2026-05-23 08:50:25 +02:00
Andrew Kelley a06f23c8ea std.array_list: fix doc comment references
allows autodoc to make these hyperlinks
2026-05-22 22:27:35 -07:00
Stephen Gregoratto ed4303fe59 IoUring: Handle OPNOTSUPP for symlinkat test 2026-05-23 06:15:24 +02:00
Stephen Gregoratto e1fc46fb6d Linux: Add proper constants for Alpha 2026-05-23 06:15:24 +02:00
Stephen Gregoratto a9b7df4ca2 Linux: Map Alpha getx*id to their regularly named versions
These syscalls also store the value of `euid/egid/ppid` in `r20`, but
are otherwise the same.
2026-05-23 06:15:24 +02:00
Mai-Lapyst 7534ac7367 Adding more support for DEC Alpha to std
This adds support to std, primarily for linux, to support the Alpha architecture.

closes #30940
closes #30926
2026-05-23 06:15:24 +02:00
Alex Rønne Petersen 6e6df11027 std.debug: trap on psp in defaultPanic() 2026-05-23 05:47:34 +02:00
Alex Rønne Petersen cece38bc05 Merge pull request 'std.zig.system.loongarch: take HWCAP into consideration' (#31614) from AstraFall/zig:loongarch/cpu-detect into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31614
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-05-23 05:44:14 +02:00
Alex Rønne Petersen 9e3eaa6be7 Merge pull request 'add spacemit_x100 + spacemit_x100 RISC-V CPU models; detect more RISC-V CPU models on Linux' (#35392) from alexrp/zig:more-riscv-models into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35392
2026-05-23 05:43:47 +02:00
xtex 8fe6d5a48e std.os.linux: move HWCAP bits to linux.zig
Change-Id: Ic06feeeec9d04b540cf4efc931df4f4b7e327c5f
2026-05-22 21:15:33 +02:00
xtex 8b220cd746 std.zig.system.loongarch: take HWCAP into consideration
We prefer information from HWCAP than CPUCFG and
assume those features unavailable if HWCAP is not available.
This is because many features require kernel support
(e.g. context switching support).

Follow-up: 37288e53ae ("std.zig.system.loongarch: implement individual cpu feature bit tests (#30915)")
Change-Id: I0a610b2c4fc751f0f159e79e01bb9f6fb7588ccf
Signed-off-by: xtex <xtex@astrafall.org>
2026-05-22 21:15:32 +02:00
xtex 34c2b5e9d1 std.os.linux: add LoongArch HWCAP bits
See also arch/loongarch/include/uapi/asm/hwcap.h in Linux kernel.

SC.Q was added in kernel v7.0.

Change-Id: Ib4ddd451ab16d52b2578f8b97c9c3365286719cd
Signed-off-by: xtex <xtex@astrafall.org>
2026-05-22 21:15:32 +02:00
Alex Rønne Petersen d70b56429c std.zig.system.linux: add detection for more RISC-V CPU models 2026-05-22 21:12:51 +02:00
Alex Rønne Petersen c717b0d08d std.Target: add spacemit_x100 and spacemit_a100 RISC-V CPU models
Backported from LLVM main branch.
2026-05-22 21:12:45 +02:00
Alex Rønne Petersen 3140b375fc std.Target: update a bunch of min/max OS versions 2026-05-22 19:19:52 +02:00
Alex Rønne Petersen 3a6ddce4cf Merge pull request 'libc: Update macOS headers to SDK 26.5' (#35382) from linus/zig:bump-macos-libc into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35382
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-05-22 18:53:47 +02:00
Alex Rønne Petersen 038c0783d4 std.Target: only make v9 the baseline for sparc-linux
NetBSD supports older models, for example.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen 8930bdfeb6 std.Target: make arch11 (z13) the baseline for s390x
arch8 (z10) is from 2008; arch11 (z13) is from 2015. I believe all Linux distros
have already made arch11 the baseline, so let's do the same.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen a8859a6d21 std.Target: make octeon the baseline for mips64-openbsd
From https://www.openbsd.org/octeon.html:

    OpenBSD/octeon is a port intended to run on MIPS64-based systems that
    utilize the Cavium OCTEON, OCTEON Plus, OCTEON II, and OCTEON III system on
    chips.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen 9f6d31c1bf std.Target: make 750 the baseline for powerpc-openbsd
From https://www.openbsd.org/macppc.html:

    OpenBSD/macppc runs on the PowerPC-based Macintosh systems from the
    "New World" family
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen 552c0fe914 std.Target: make pwr9 the baseline for powerpc64-openbsd
From https://www.openbsd.org/powerpc64.html:

    OpenBSD/powerpc64 runs on PowerNV machines using the IBM POWER9 processors.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen 1fd1fadc02 std.Target: make ultrasparc the baseline for sparc64
No OSs actually support CPUs older than this.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen 51962172f7 std.Target: make esp32 the baseline for xtensa
This is the MCU that the overwhelming majority of hobbyists target.
2026-05-22 18:41:03 +02:00
Alex Rønne Petersen c49f7fbffd std.Target: make m68030 the baseline for m68k
It's the oldest model that has an integrated MMU.
2026-05-22 18:41:00 +02:00
Alex Rønne Petersen 0b00adc6fc std.Target: make cortex_a55 the baseline for aarch64-haiku
Haiku's build system targets this.
2026-05-22 03:10:56 +02:00
Linus Groh 761809e793 std.Target: Update supported Apple OS versions 2026-05-22 00:44:16 +01:00