Commit Graph

2473 Commits

Author SHA1 Message Date
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 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
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
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 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
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
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
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
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 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 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
GasInfinity 1deb029a66 std: rename bit_set variants and deprecate the managed one.
* aliases and deprecates the previous names.
* also update callsites to use the non-deprecated declarations.
2026-04-27 16:46:26 +02:00
Alex Rønne Petersen 669c066801 llvm: fix sign extension of 32-bit integers in callconv(.c) on mips 2026-04-27 09:42:08 +02:00
Alex Rønne Petersen a83aad152b Merge pull request 'LLVM 22' (#32013) from llvm22 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32013
2026-04-26 07:03:38 +02:00
Alex Rønne Petersen 1be84a39b8 compiler: fix and simplify DllMainCRTStartup handling
See: https://github.com/llvm/llvm-project/pull/171680
2026-04-25 21:54:48 +02:00
Alex Rønne Petersen 4c50c4b6e5 llvm: wire up the xtensa backend
As of LLVM 22, it can produce assembly and object files. No LLD support,
however, so using it is still a bit of a pain.
2026-04-25 21:54:47 +02:00
Alex Rønne Petersen 473df0c106 llvm: switch to wasip<n> for preview wasi versions in triples 2026-04-25 21:54:47 +02:00
Alex Rønne Petersen 593f45ee02 llvm: switch most targets to using half and fp128 IR types
As of LLVM 22, most backends can (finally) handle legalization of these types as
necessary, so we don't need to do it ourselves anymore.

closes https://github.com/ziglang/zig/issues/23674
2026-04-25 21:54:47 +02:00
Alex Rønne Petersen 421d997938 llvm: update data layout strings to LLVM 22 2026-04-25 21:54:47 +02:00
Alex Rønne Petersen ca0b3318a0 std.Target: update CPU and feature data to LLVM 22 2026-04-25 21:54:47 +02:00
Jacob Young 2040f9bfd0 x86_64: fix c abi of f32 struct field followed by padding
Closes #31864
2026-04-25 12:10:35 -04:00
Jacob Young cb1c7319b5 llvm: fix aarch64 c abi HFA detection
Aggregate types do not count as Homogeneous Aggregates if they have
padding gaps between fields or at the end due to field alignments.
2026-04-25 12:01:14 -04:00
Matthew Lugg 31bc385a96 cbe: add missing cast of overflow arithmetic out pointer 2026-04-25 05:22:41 +02:00
Andrew Kelley fb9ba5e4b3 Merge pull request 'llvm: fix multiple_llvm_types handling and aarch64 return types' (#32028) from aarch64-c-abi into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32028
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-25 05:19:18 +02:00
andrew.kraevskii bbab366b78 Audit usages of toOwnedSlice (#32001)
Followup to #30769

I grepped for `try .*toOwnedSlice` and checked all of them by hand.

Fixes a bunch of memory leaks removes usages or `errdefer` and `vars` in some places. I also switched array_list.Managed to ArrayList where it was convenient.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32001
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-22 19:35:46 +02:00
Jacob Young df3aba6cc0 llvm: fix multiple_llvm_types handling and aarch64 return types
Closes #31994
2026-04-22 13:19:44 -04:00
Jacob Young 97ef8f1f8e llvm: pass more c abi tests on aarch64
This is not what clang does, and is definitely wrong on big endian,
but lets at least pass the following simple tests first.
2026-04-22 14:35:22 +02:00
Pavel Verigo 22945fbbdc stage2-wasm: vector, std tests 2026-04-22 00:19:46 +02:00
Ryan Liptak 3252a05531 Prefer <err> => |e| return e over <err> => return <err>
Avoids the potential for a typo on the `return <err>` side of the prong
2026-04-20 18:03:14 -07:00
Pavel Verigo d840583458 remove AIR .bool_or/.bool_and 2026-04-19 21:49:51 +02:00
Mason Remaley e2c3920fb1 Renames buffer first allocator in compiler and std 2026-04-18 14:51:49 -07:00
Mason Remaley 8c96487bb9 Updates all uses of StackFallbackAllocator 2026-04-18 14:51:49 -07:00
Alex Rønne Petersen adb1f3efc2 Merge pull request 'test: reinstate compiler-rt and zigc tests with different LLVM bug workarounds' (#31909) from alexrp/zig:reinstate-tests into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31909
2026-04-17 12:04:30 +02:00
Andrew Kelley bea4ea5ff8 Merge pull request 'zigc: long double: call double function if long double and double are equivalent' (#31775) from rpkak/zig:zigc-long-double into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31775
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-16 19:57:54 +02:00
Sam Connelly 17e0afd0e5 feat: init eZ80 arch via CBE 2026-04-16 19:21:16 +02:00
Alex Rønne Petersen a283ca76fe cbe: don't emit zig_no_builtin on every function with -fno-builtin 2026-04-16 17:46:29 +02:00
Matthew Lugg 84c2d809ec llvm: workaround crash on large inline memset
See https://codeberg.org/ziglang/zig/issues/31701 for details. I am not
re-enabling the disabled compiler-rt module tests here because they are
also affected by https://codeberg.org/ziglang/zig/issues/31702.
2026-04-16 17:00:04 +02:00
rpkak f564a7733c remove code, which is only reached if c_longdouble is only 16 or 32 bits big 2026-04-16 07:05:31 +02:00
Andrew Kelley 67a5b6e5e8 delete @cImport from the language
closes #20630
2026-04-15 17:43:53 -07:00
Andrew Kelley e00b5daa1f Merge pull request 'stage2-wasm: finish bigint support' (#31784) from pavelverigo/zig:wasm-bigint-finish into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31784
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-15 23:07:40 +02:00
Pavel Verigo c32f7a4513 stage2-wasm: support assembly 2026-04-15 22:57:41 +02:00
David Rubin 06ab4f702e llvm: correctly bitcast for memset intrinsic path 2026-04-12 05:28:54 +02: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