355 Commits
Author SHA1 Message Date
Andrew Kelley 935a3b9c75 Merge pull request 'std: update more ArrayList usages to unmanaged' (#37362) from masabence/zig:more-arraylist-unmanaged into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37362
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-10-24 23:06:14 +02:00
Masa Bence 87528630dd std: update more ArrayList usages to unmanaged 2026-10-22 20:09:32 +02:00
CMDRZero 64e4f9db8f Implement partially ordered operator precedence 2026-10-22 12:21:43 +02:00
Alex Rønne Petersen 1c5c725431 remove mips64el-openbsd support
OpenBSD 8.0 dropped this target.
2026-10-21 19:49:58 +02:00
Alex Rønne Petersen 26500dafe5 std.debug.SelfInfo.MachO: fix xreg/dreg restore logic in compact unwinding
The old logic advanced in the wrong direction and also overwrote one register in
consecutive pairs. I'm not aware of any case where this matters in practice
since macOS mandates the use of an FP register on AArch64, but we should still
get it right.
2026-10-18 17:27:28 +02:00
Alex Rønne Petersen f03e7e318a std.debug.SelfInfo.MachO: handle new UNWIND_ARM64_MODE.FRAME_PAUTH_LR 2026-10-18 17:23:42 +02:00
Alex Rønne Petersen 72e0d1cd27 std.debug.cpu_context: signal context conversion for sparc*-netbsd/openbsd 2026-10-11 15:00:48 +02:00
Alex Rønne Petersen e4c80ae695 std.debug.Dwarf: fix supportsUnwinding() for amdgcn
https://github.com/llvm/llvm-project/pull/183148
2026-10-07 00:30:52 +02:00
whatisaphone 996321250d Fix simple_panic 2026-10-03 19:36:46 +02:00
Ten Eugene 230c63650f std.Io.Reader: add readAllocShort, mirror readAlloc* with readSlice* (#36807)
Closes #36767

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36807
Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>
2026-09-21 07:53:28 +02:00
Alex Rønne Petersen f955266cf7 std.debug.Dwarf.Unwind.VM: handle aarch64 pac-ret opcodes (by ignoring them)
SelfUnwinder already unconditionally strips pointer authentication codes, so for
the self-unwinding case, we just need to make sure that these opcodes don't
cause unwinding to fail due to error.UnimplementedUserOpcode.
2026-09-05 16:32:14 +02:00
Matthew Lugg 1436d488b9 std.debug.Dwarf: basic support for DW_LNE_ZIG_set_decl
This makes stack traces with `-fincremental`, um, sort of work:

```
thread 29999 panic: this is the RIGHT panic
/home/mlugg/panic.zig:15:25: 0x7a1907 in bar (panic.zig)
        1, 2, 3, 123 => @panic("this is the RIGHT panic"),
                        ^
/home/mlugg/panic.zig:7:12: 0x7a138c in foo (panic.zig)
        bar(123);
           ^
/home/mlugg/panic.zig:2:8: 0x7a12fe in main (panic.zig)
    foo(true);
       ^
/home/mlugg/zig/master/lib/std/start.zig:779:64: 0x7a0e3b in callMain (std.zig)

                                                               ^
/home/mlugg/zig/master/lib/std/Target.zig:1651:5: 0x7a0861 in _start (std.zig)
        pub inline fn isSparc(arch: Arch) bool {
    ^
Aborted                    ./panic
```

The last two frames are clearly incorrect. However, we actually agree
with lldb-zig about those source locations, so it seems like that's a
bug in the compiler's `link.Dwarf2` implementation.
2026-09-04 20:57:35 +02:00
Jacob Young d44db8ea0c debug: fix and test Elf2 stack trace printing
- fix corrupt debug info
- fix dwarf unit version handling
- run stack and error trace tests with Elf2
2026-09-03 15:29:46 -04:00
Jacob Young 79bb28aa57 Elf2: implement dwarf unwind info
Other debug info is still in progress.

Closes #25421
2026-09-03 11:00:53 -04:00
Alex Rønne Petersen 9e9047b7e8 std.debug.cpu_context.X86_16: fix register number for ip to match eip on X86 2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 19de614e9d std.debug.cpu_context.Ve: simplify getting ic in current assembly
Turns out the architecture has an instruction that just... gives you the ic.
Revolutionary!
2026-08-09 17:53:04 +02:00
Alex Rønne Petersen f376cbc37b std.debug.cpu_context.Sparc: align to 8 bytes to make std on 32-bit safe
Otherwise we might get SIGBUS due to misalignment.
2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 4a9c642b64 std.debug.cpu_context.Lanai: fix typos 2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 225deb64e9 std.debug.cpu_context.Kvx: fix pc/ra being swapped vs current assembly 2026-08-09 17:53:04 +02:00
Alex Rønne Petersen d9e11f4f31 std.debug.cpu_context.Arm: make current assembly work in Thumb-1 2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 39f0cf90e5 std.debug.cpu_context.Alpha: fix current assembly not saving r31
It's always zero, but we shouldn't leave that element of the array undefined.
2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 0d947ae87a std.debug: use a different register number for pc on sparc
Also report the floating-point registers as unsupported rather than invalid.
2026-08-09 17:53:04 +02:00
Alex Rønne Petersen 3b947932ab std: avoid pointless delay slots and lr writes in inline assembly
And fill in some delay slots where we can't avoid them.
2026-08-09 16:56:23 +02:00
Corentin Kerisit fafbc70ac5 std.debug.MachOFile: support loading DWARF from adjacent dSYM (#35582)
Fixes #31797

I finally had time to work on this.

I've implemented it so that, when an adjacent dSYM exist and its uuid match that of the current binary, we load its DWARF and use that for all getDwarfForAddress requests.
All of this is done eagerly at `MachOFile.load` for simplicity rather than later and lazier. Happy to change that to whatever you think is best.

This implementation is quite minimal and makes dSYM support "best-effort" as in, it treats dSYM parsing error as non-fatal and fallbacks using the current stabs/ofiles mechanism.

You can test it that way on macOS:

```
zig build-exe panic.zig
dsymutil panic -o panic.dSYM
strip -S panic
./panic
```

with panic.zig:
```
pub fn main() void {
    @panic("panic");
}
```

Before:
```
thread 57569166 panic: panic
???:?:?: 0x103071c2b in _panic.main (/private/tmp/panic)
???:?:?: 0x103071bb3 in _main (/private/tmp/panic)
???:?:?: 0x180d5ab97 in start (/usr/lib/dyld)
fish: Job 1, './panic' terminated by signal SIGABRT (Abort)
```

After:
```
thread 57569653 panic: panic
/private/tmp/panic.zig:2:5: 0x1029d771b in main (panic)
    @panic("panic");
    ^
/Users/cerisier/code/codeberg.org/ziglang/zig/lib/std/start.zig:698:59: 0x1029d76a3 in callMain (panic)
    if (fn_info.params.len == 0) return wrapMain(root.main());
                                                          ^
???:?:?: 0x180d5ab97 in start (/usr/lib/dyld)
fish: Job 1, './panic' terminated by signal SIGABRT (Abort)
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35582
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2026-08-07 16:14:05 +02:00
Andrew Kelley f8c6193e4c Merge pull request 'elf: remove deprecated elf.ElfXX_Phdr, elf.Phdr and elf.PR_*' (#36353) from kada49/deprecated-phdr-remove into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36353
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-08-05 03:38:32 +02:00
Meghan Denny e88566253d sema: improve @errorCast safety check message 2026-08-05 03:29:37 +02:00
Matthew Lugg 5f74e4f3f8 Sema: make loading uninstantiable types a runtime safety panic
For generic code, it is far more useful to consider this equivalent to
`unreachable`. Meanwhile, it is difficult to accidentally write concrete
code which performs this operation, so very little is actually lost from
not having a compile error.

If we accept that this operation does not trigger a compile error, then
it already has the potential to invoke Illegal Behavior today, because
uninstantiable types have an unspecified size in memory, so the
dereference always potentially exceeds the pointer's provenance. (That
said, this only means it is *possible* for the operation to invoke IB,
so the langspec should nonetheless explicitly specify that dereferencing
a pointer to an uninstantiable type is itself Illegal Behavior.)

Storing uninstantiable types into memory does not require any specific
language rules, because that operation can never be reached anyway due
to it requiring an operand (the RHS of `a = b`) whose type is the store
type, which is (by definition) impossible for uninstantiable types.

Resolves: https://codeberg.org/ziglang/zig/issues/36247
2026-08-04 22:29:50 +02:00
Theo Fabi 539bdfc46f debug.MachOFile: handle truncated dwarf section names
Some dwarf section names like __debug_str_offsets don't fit in a Mach-O
sectname buffer, so their actual name in Mach-O binaries is truncated.

When searching for sections to load an object file's debug info, we now
compare the section name with the truncated name. Before, the full name
was checked, so we would unconditionally skip __debug_str_offsets dwarf
sections.
2026-08-02 14:18:11 +02:00
Theo Fabi 8331051284 debug.Dwarf: FORM_ref_addr is host address sized in DWARFv2
DW_FORM_ref_addr encoding specification is different in dwarf version 2.
parseFormValue() now accepts a `version` argument so that it can parse
such attributes correctly based on the version.
2026-08-02 12:03:06 +02:00
David Senoner 4843120b4c elf: remove usages of deprecated Elf32_Phdr 2026-07-30 21:23:58 +02:00
Jacob Young 865f329e4f cbe: update for compiler_rt abi changes
* `tools/generate_c_size_and_align_checks.zig`: superceded by any cbe
   output artifact
 * `cTypePreferredAlignment`: no uses, if brought back, cbe should be
   updated to verify `__alignof`

Closes #19991
Closes #20881
Closes #35523
2026-07-27 14:35:12 -04:00
Thibault Leclercq 6c25d2bd58 std.debug.SelfInfo.Elf: clear unwind cache when rebuilding module list 2026-07-20 13:56:43 +02:00
Justus Klausecker 69a26976ed zig fmt
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the
new `@backingInt` and `@fromBackingInt` builtins.
2026-07-17 23:30:26 +02:00
Matthew Lugg 8f7fd5c7f3 std.debug.SelfInfo.Elf: fall back to symtab search more often
Symtab search is always a reasonable fallback if debug information is
absent, invalid, or unsupported. Therefore, by changing the error
handling here to get symbols from the symtab even if `std.debug.Dwarf`
returns an error, we make stack traces slightly better in some cases.

This affects the self-hosted `Elf2` linker: that linker does not yet
understand DWARF sections, so it ends up emitting incomplete (or
sometimes invalid) DWARF. However, it still has a valid symtab, so we
should at least be able to see function symbol names in the stack trace!
Before this patch, we just saw "???" for everything, but after this
patch, we do indeed get the symbol names.
2026-07-17 15:56:36 +02:00
Alex Rønne Petersen f0fdc90989 std.debug.SelfInfo.Elf: enable DWARF unwinding for ARM
It seems like whatever bug was causing this to be unreliable is no longer
present; all module tests work for me with DWARF unwinding enabled. So let's
enable this for now, and if any breakage does pop up later, we can deal with it
then.
2026-07-05 10:39:03 +02:00
Andrew Kelley 3a11c86837 std.hash.crc: fix namespace issues
in accordance with the style guide in the langref
2026-06-26 16:07:53 -07:00
Alex Rønne Petersen 2681d4abc3 std.debug.Dwarf.expression: fix a couple of failing tests on x32/n32
The upper half of the register was left undefined on these ABIs, causing an
@intCast inside the stack machine to fail.
2026-06-18 03:59:15 +02:00
Alex Rønne Petersen 038698738f std.debug.SelfInfo.Elf: enable unwind support on x32/n32
closes https://codeberg.org/ziglang/zig/issues/32056
2026-06-16 12:13:04 +02:00
Alex Rønne Petersen 4261825766 std.debug.Dwarf: fix unwinding when address size is smaller than register size 2026-06-16 12:12:05 +02:00
Alex Rønne Petersen cf13ecab29 std.debug.cpu_context: always declare a Gpr type on Native 2026-06-16 12:09:31 +02:00
David Senoner c91727108e Replace usages of ArrayHashMapUnmanaged with array_hash_map.Custom 2026-06-10 16:14:58 +02:00
David Senoner 37651eea89 Replace usages of AutoArrayHashMapUnmanaged with array_hash_map.Auto 2026-06-10 16:14:58 +02:00
David Senoner d23e22c416 Replace usages of StringArrayHashMapUnmanaged with array_hash_map.String 2026-06-10 16:14:53 +02:00
Alex Rønne Petersen 9cc9779ba0 std.debug.cpu_context: fix compile errors on alpha 2026-05-31 06:17:58 +02:00
Alex Rønne Petersen a4058856a4 std.debug.cpu_context: fix compile error on arc 2026-05-30 18:45:44 +02:00
Alex Rønne Petersen 64958c2b17 std.debug.SelfInfo.Elf: xtensa does not support DWARF CFI 2026-05-29 07:26:21 +02:00
Matthew Lugg 89f86e46d2 std: don't use dyld functions on non-macOS Darwin
65922a2d4 started using some (deprecated but still available) dyld
functions for stack unwinding and debug information on Darwin targets,
because they are significantly faster than `dladdr` (which is the
"correct" thing to use). However, these functions are unavailable on
Darwin targets other than macOS, for instance on iOS. Therefore, on
those targets, we must fall back to the slow `dladdr` path.
2026-05-28 08:54:23 +01:00
mlugg 3f1dead2fc Merge pull request 'Use struct-of-arrays style for std.lang.Type' (#35234) from Der_Teufel/zig:soa-builtin-type into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35234
2026-05-28 09:45:54 +02:00
Alex Rønne Petersen 7ee6e7d61e std.debug.Dwarf.Unwind.VM: deal with negative offsets in unsigned CFI insns
The DWARF spec has CFI instructions that take signed offsets, but at least LLVM
always emits the unsigned variants, even for e.g. `.cfi_def_cfa_offset -4`.
2026-05-28 04:03:47 +02:00
Krzysztof Wolicki 9e80795623 all: update to use new std.lang.Type definitions 2026-05-27 10:03:51 +01:00