Commit Graph

17901 Commits

Author SHA1 Message Date
Andrew Kelley 5fbfeabd5f compiler: no longer need ThreadSafeArena wrapper 2026-05-25 18:54:34 -07:00
Andrew Kelley b04818644c rename configure_runner to configurer 2026-05-25 18:54:34 -07:00
Andrew Kelley b3d162d6bf build maker: rename files to match type 2026-05-25 18:54:34 -07:00
Andrew Kelley 0505318efe make runner gets compiled and run
and --print-configuration prints some deserialized stuff
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 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 c805c72289 upgrade most uses of DebugAllocator to SafeAllocator 2026-05-25 18:37:24 -07:00
Kendall Condon e1ce81eb54 link.Elf: fix large abi aligned globals 2026-05-25 18:37:23 -07:00
Alex Rønne Petersen e919a0d175 compiler: don't allow statically linking executables on Haiku
Haiku always loads executables through its dynamic linker.
2026-05-24 21:38:04 +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 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 b9a00fe6aa std.Target: fix default calling convention for ps3 2026-05-23 10:22:40 +02:00
Alex Rønne Petersen c00966d11d llvm.FuncGen: fix C ABI zero extension of bool
closes https://codeberg.org/ziglang/zig/issues/35373
2026-05-21 23:03:14 +02:00
Matthew Lugg 4a65cc4aca Zcu: report outdated nav_ty when previous generation had a compile error
This logic existed when actually analyzing a `nav_ty` unit directly; it
was just missing in the code path which resolves a `nav_ty` unit due to
a `nav_val` being resolved.

Resolves: #35307
2026-05-20 16:27:04 +02:00
Matthew Lugg fec502ec67 Elf2: flush ehdr phoff when rodata moves
I should have realised what was going on here sooner, because it was
really simple! We had a file offset which was being flushed in
`flushMoved` instead of `flushFileOffset`, and since `flushMoved` does
not bubble down to the PHDR segment from the "parent" read-only LOAD
segment, we weren't updating `ehdr.phoff` if the rodata segment had to
move. The tricky thing which meant I didn't catch this sooner is that
this wasn't happening on all filesystems, because the behavior of
`link.MappedFile` differs depending on the capabilities of the target
filesystem.

Resolves: https://codeberg.org/ziglang/zig/issues/32123
Resolves: https://codeberg.org/ziglang/zig/issues/35367
2026-05-20 10:40:11 +01:00
Alex Rønne Petersen 0843d3e5f2 compiler: delete llvm-ints and detect-cpu subcommands
* The llvm-ints subcommand hasn't been useful for a while since we're just using
  hardcoded data layout strings based on the target, rather than the old
  approach of building them up piecemeal. We additionally have the
  tools/generate_c_size_and_align_checks.zig script for catching C ABI
  mismatches. So this libLLVM dependency is not justified anymore.
* The detect-cpu subcommand was at least somewhat useful to compare CPU
  detection results between Zig and LLVM. However, its usefulness hinged on
  running it natively on every relevant CPU, which we were not actually doing
  anyway. Besides, I make a point of porting CPU detection changes in LLVM to
  our CPU detection code on every LLVM upgrade - and in some cases, we even do
  it more correctly than LLVM now. So the libLLVM dependency brought by this
  subcommand also isn't really justified anymore.
2026-05-19 13:15:44 +02:00
linus 30698b03c0 Merge pull request 'std: Remove more deprecated functions' (#35253) from linus/zig:more-deprecations into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35253
2026-05-19 11:41:52 +02:00
Anders Stenberg 9ba4552793 Elf2: avoid overflow in shentsize * shnum calculations 2026-05-17 18:55:27 +01:00
Matthew Lugg 97fe49a80f Elf2: rework the symtab, and fix a bunch of stuff
Sorry for the mega-commit, this diff got a little out of control.

The main thing here is a complete rework of how Elf2 handles the symbol
table. I messed around with the design for a while and landed on
something which is fairly memory-efficient (in particular the overhead
for STB_LOCAL symbols is as low as possible) and fulfils some of the
more awkward constraints of the ELF format. The main such constraint is
that all STB_LOCAL symbols in a symbol table are required to appear
before any STB_GLOBAL/STB_WEAK symbols. This is further complicated by
the fact that when producing a DSO, symbols with STV_HIDDEN or
STV_INTERNAL visibility are required to have STB_LOCAL binding in the
symbol table, even though they are global symbols from the perspective
of the link editor. Plus, when combining multiple symbols with the same
name, the resulting visibility is the strictest of all of the inputs, so
it is possible at any point in compilation to discover an extern/export
symbol which forces an existing STB_GLOBAL symbol to become STB_LOCAL
and therefore requires it to move to an earlier symtab index. Dealing
with all of this was quite awkward.

But I got there! I also implemented a lot of features in the process. I
don't remember everything perfectly, but here's a vague list:

* Multiple definitions of and/or unresolved references to symbols are
  now combined correctly in all cases

* `.bss` sections from inputs are correctly lowered (we don't actually
  emit a `.bss` section of our own yet, but I was able to put that data
  into the `.data` section so that the functionality is correct)

* Relocations in link inputs are now always processed (previously they
  would be silently ignored in most cases)

* Linker errors are triggered if a supported input section has a
  relocation which targets an unsupported input section (previously
  the unsupported section's symbol was dropped and associated
  relocations would be silently ignored)

* When linking a static executable, an error is emitted if a required
  symbol (i.e. an undefined reference with strong linkage) was never
  defined

* Duplicate symbol errors now work correctly

* When emitting a relocatable, the offsets of relocation entries are now
  correct (previously the offsets written were relative to a symbol
  rather than a section, meaning that e.g. almost all text relocations
  were just in a single function)

The changes in all of the other linkers and codegen backends are some
added type-safety at the codegen-linker API boundary. There are now
distinct `u32`-backed types for identifying an "atom" (the thing we're
codegenning) and a "symbol" (the thing which a relocation targets).
Linker implementations can use a couple of private helper functions to
convert between this implementation-agnostic type and their specific
type; for instance, `Elf2` can convert between a `Symbol.Id` and a
`link.File.SymbolId` with `Symbol.Id.fromTypeErased` and
`Symbol.Id.toTypeErased`. I didn't implement this nicely for any other
linker, so right now there's a lot of `@enumFromInt`/`@intFromEnum`
sprinkled all over the place, particularly with the legacy ELF and
Mach-O linkers.

I tested that I could still perform incremental updates to the Zig
compiler using this commit. In terms of the new behaviors, the most
interesting stuff is symbol and relocation resolution, so I ran a few
tests involving building a "Hello World" binary in various different
ways:

* `build-exe` correctly succeeds

* `build-exe -fno-compiler-rt` correctly reports undefined symbols

* `build-obj` linked with `build-exe` correctly succeeds

* `build-obj` linked with `build-exe -fno-compiler-rt` correctly reports
  undefined symbols

* `build-obj -fcompiler-rt` linked with `build-exe -fno-compiler-rt`
  correctly succeeds

* `build-obj -fcompiler-rt` linked with `build-exe` correctly succeeds
  (the compiler-rt symbols are weak so the global symbols are
  arbitrarily resolved to one of the two implementations)

I also manually verified with `readelf` that symbol tables were always
ordered correctly (before this PR, `readelf -s` would usually emit
warnings about incorrectly-ordered symtabs!), and verified that various
visibility attributes worked as expected.

No actual test coverage is added due to the current lack of a useful
linker test harness. Once a good test harness is available I will be
willing to write some tests.
2026-05-17 18:55:26 +01:00
Matthew Lugg e8ef01f222 Elf2: fix expected_nodes_len calculation
I'm not sure what the basis was for the old logic here, but it was
incorrect and caused an assertion failure in some cases. The
dependencies on `maybe_interp` and `any_non_single_threaded` are already
correctly modeled by `phnum`, so do not need to be accounted for a
second time.
2026-05-17 18:08:58 +01:00
Matthew Lugg 65c3a07709 Elf2: don't try to add needed dso in relocatable 2026-05-17 18:08:58 +01:00
Matthew Lugg 2ec0b886a2 Elf2: allow more EI_OSABI values in inputs
On Linux, the OSABI field can be either ELFOSABI_GNU or ELFOSABI_NONE
(aka ELFOSABI_SYSV). Therefore, even if we have chosen ELFOSABI_GNU, we
still need to accept ELFOSABI_NONE in link inputs.

Then, since we're now having to check the ident componentwise anyway, we
may as well give more precise error messages on mismatch.
2026-05-17 18:08:58 +01:00
Matthew Lugg 55cdf6c28b std.elf: add Ident struct
This is much nicer than indexing a raw 16-byte buffer.
2026-05-17 18:08:57 +01:00
Matthew Lugg a76ce77108 llvm: fix lowering of x86 fastcall and vectorcall
LLVM requires these calling conventions to specify `inreg` attributes on
all parameters which are passed via register.
2026-05-09 09:35:44 +02:00
Linus Groh 75c717bd06 std.bit_set, std.enums: Remove .init{Empty,Full}() in favor of .empty/.full 2026-05-08 22:12:27 +01:00
Linus Groh 4590712804 std.ascii: Remove indexOfIgnoreCase*() in favor of findIgnoreCase*() 2026-05-08 21:55:08 +01:00
Justus Klausecker 6d0b887972 Sema: disallow pointer cast from pointer to opaque type to slice
Fixes a regression where this conversion crashes. When the conversion was
still possible it would produce a slice with a length of zero, which doesn't
really make a lot of sense either. There's no way to determine the length
of the destination slice from a pointer to an opaque type, so it's a compile
error now. Users should just cast to a many-item pointer and slice to the
desired length manually instead.
2026-05-07 06:25:43 +02:00
Matthew Lugg fecd28371d Sema: fix crash bitcasting undefined to bitpack type
Resolves: https://codeberg.org/ziglang/zig/issues/31944
2026-05-07 06:22:47 +02:00
Matthew Lugg fc1c83a363 Air: fix legalization of packed struct init with OPV field
I have verified that this fixes *both* of the reproductions given in
https://codeberg.org/ziglang/zig/issues/31837 (they were the same bug).

Resolves: https://codeberg.org/ziglang/zig/issues/31837
2026-05-07 06:21:59 +02:00
Matthew Lugg 0bcf29aff6 compiler: correct ABI size of comptime-only optional type
Resolves: https://codeberg.org/ziglang/zig/issues/31603
2026-05-07 06:21:30 +02:00
Alex Rønne Petersen e445c0d63e zig cc: always enforce -mabi=ieeelongdouble for powerpc
closes https://codeberg.org/ziglang/zig/issues/30976
2026-05-07 05:32:04 +02:00
Andrew Kelley cd23f7a814 Merge pull request 'std.meta: Remove Int/Tuple in favor of @Int/@Tuple' (#35188) from linus/zig:deprecated-std-meta into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35188
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-06 19:35:40 +02:00
Andrew Kelley 3d56df1716 Merge pull request 'std.fmt, std.mem.Allocator: Remove bufPrintZ()/dupeZ() in favor of bufPrintSentinel()/dupeSentinel()' (#35190) from linus/zig:deprecated-std-fmt-mem into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35190
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-06 19:34:52 +02:00
mlugg 7eb79daffb Merge pull request 'std.builtin -> std.lang migration progress' (#32182) from compiler-std-lang into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32182
2026-05-06 10:10:44 +02:00
johan0A 6a37df00ec Config.resolve: don't error on explicit dynamic linker for Lib/Obj outputs 2026-05-05 17:17:15 +02:00
Linus Groh fcc0a5a913 std.mem.Allocator: Remove dupeZ() in favor of dupeSentinel() 2026-05-03 21:42:16 +01:00
Linus Groh 991f56fd6b std.meta: Remove Int in favor of @Int 2026-05-03 21:42:06 +01:00
linus a794287573 Merge pull request 'std.zig.LibCInstallation: Add support for serenity' (#32172) from linus/zig:more-serenity into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32172
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-05-03 21:04:54 +02:00
Matthew Lugg 4c330e053b compiler: use 'std.lang' instead of 'std.builtin' 2026-05-03 12:23:30 +01:00
Matthew Lugg e133f793ee compiler: depend on 'std.lang' instead of 'std.builtin' 2026-05-03 12:23:29 +01:00
Justus Klausecker 1f22b2cbb2 LowerZon: fix packed containers
Since `packed` containers are now internally represented by a `bitpack`,
they need special handling on initialization: they need to be either
bitpacked or bitcasted to their backing integer. `Sema` already did this,
but `LowerZon` didn't yet.
2026-05-02 20:05:33 +02:00
Linus Groh 89b0c634c1 compiler: Enable PIE by default for serenity
See:
- https://github.com/SerenityOS/serenity/blob/727c4a3d1a6748221b383207dac354e564b6150d/Meta/CMake/serenity_compile_options.cmake#L15
- https://github.com/llvm/llvm-project/blob/62418bee5b9679c5b3bd536fb1101913b1c4e4d5/clang/lib/Driver/ToolChains/Serenity.h#L65
2026-05-02 01:28:22 +01:00
Saurabh Mishra d02d0b879c std:ArrayList: Merge getLastOrNull into getLast (#32008)
This PR merges the functionality of the `getLastOrNull` method into `getLast`, which improves consistency as its
based on methods like `front`, `back`, and `peek` in the `Deque` and `PriorityQueue` containers.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32008
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-02 02:26:15 +02:00
pentuppup 845b6a8efe Zcu: remove optimizeMode(), fix usages 2026-05-01 10:39:43 +02:00
Matthew Lugg 72d954e7d3 compiler: remove array multiplication from the language
Resolves: https://github.com/ziglang/zig/issues/24738
2026-04-30 09:03:58 +01:00
Matthew Lugg fdac89d6cd remove uses of array multiplication
In preparation for its removal as accepted in
https://github.com/ziglang/zig/issues/24738.
2026-04-30 08:57:51 +01:00
Matthew Lugg 57634b7809 compiler: remove i0 from the language
Resolves: https://github.com/ziglang/zig/issues/1593
2026-04-30 08:57:51 +01:00
Matthew Lugg d764716cb5 compiler: remove capturing errdefer from the language
Resolves: https://github.com/ziglang/zig/issues/23734
2026-04-30 08:57:50 +01:00
Matthew Lugg e67c344fc0 compiler,tests,tools: remove uses of capturing errdefer
In preparation for its removal, as accepted in
https://github.com/ziglang/zig/issues/23734.
2026-04-29 23:27:58 +01:00