aboutsummaryrefslogtreecommitdiff
path: root/lib/std
AgeCommit message (Collapse)Author
2025-10-04std.debug: consider FP-based unwinding on hexagon and powerpc safeAlex Rønne Petersen
The ABIs make this safe and reliable due to their backchain requirements.
2025-10-04std.debug: fix FP-based unwinding on powerpc64Alex Rønne Petersen
This just needs to do the same thing as powerpc64le. Note that the saved LR is at the same position in both ELF v1 and v2.
2025-10-03std.coff: Set default values for ImportHeader sig1/sig2 fieldsRyan Liptak
Just makes this a bit nicer to work with since those fields only have 1 intended value.
2025-10-03std.coff: Add sizeOf function to WeakExternalDefinitionRyan Liptak
Convenience function similar in nature to Symbol.sizeOf
2025-10-03std.coff: Fix SectionHeader.setAlignment (off by 1)Ryan Liptak
Previously, `setAlignment` would set the value to 1 fewer than it should, so if you were intending to set alignment to 8 bytes, it would actually set it to 4 bytes, etc.
2025-10-03Add depth function to `Walker.Entry`Ryan Liptak
This enables depth-related use cases without any dependency on the Walker's internal stack which doesn't always pertain to the actual depth of the current entry (i.e. recursing into a directory immediately affects the stack).
2025-10-03std.mem: Add `countScalar`Ryan Liptak
2025-10-03test: enter after check to preserve depthHenry Kupty
2025-10-03test: Include expected depth testHenry Kupty
2025-10-03feat: Reintroduce depthHenry Kupty
Some decision-making might depend on the level of the traversal, so it makes sense to expose depth here since it's stable, and not in the automatic walker where it's not.
2025-10-03Add SelectiveWalker/walkSelectively and implement Walker in terms of itRyan Liptak
This is a breaking change, since the fields of Walker have changed. The function APIs are unchanged, though.
2025-10-03std.debug: Add unwind support for serenityLinus Groh
2025-10-03std.c: Also make Sigaction flags a c_uint for serenityLinus Groh
This matches all other platforms. Even if this field is defined as 'int' in the C definition, the expectation is that the full 32-bit unsigned integer range can be used. In particular this Sigaction initializer in the new std.debug code was causing a build failure: ```zig .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND) ```
2025-10-03std.c: Add missing SIG constants for serenityLinus Groh
2025-10-03Merge pull request #25430 from jacobly0/x86_64-winJacob Young
Coff2: create a new linker from scratch
2025-10-03std.debug.Dwarf.SelfUnwinder: default some s390x registers to the same-value ↵Alex Rønne Petersen
rule
2025-10-03std.debug: add s390x-linux unwind supportAlex Rønne Petersen
2025-10-03std.os.linux: improve the s390x mcontext_t definitionAlex Rønne Petersen
The old one was correct in terms of layout but very user-hostile.
2025-10-03std.debug: use correct return address offset for s390xAlex Rønne Petersen
Makes FP-based unwinding work.
2025-10-02Coff2: create a new linker from scratchJacob Young
2025-10-02std.debug.Dwarf.Unwind: deal with invalid def_cfa_reg by GNU toolchainsAlex Rønne Petersen
2025-10-01std.debug: add riscv32-linux and riscv64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: add loongarch64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: some adjustments to target handlingAlex Rønne Petersen
* driverkit handling missing in a few places. * x86-solaris is a dead target. * aarch64_be does not exist on Darwin, FreeBSD, Windows.
2025-10-01std.debug.SelfInfo: rename Darwin to MachOAlex Rønne Petersen
2025-10-01std.debug: don't use SelfInfo.Windows for UEFIAlex Rønne Petersen
It is, in fact, Windows-only.
2025-10-01std.debug: select SelfInfo using ObjectFormat.default()Alex Rønne Petersen
2025-09-30ArrayHashMapWithAllocator: add `sortUnstable` fn alongside `sort`Ryan Liptak
2025-09-30add deflate compression, simplify decompressionKendall Condon
Implements deflate compression from scratch. A history window is kept in the writer's buffer for matching and a chained hash table is used to find matches. Tokens are accumulated until a threshold is reached and then outputted as a block. Flush is used to indicate end of stream. Additionally, two other deflate writers are provided: * `Raw` writes only in store blocks (the uncompressed bytes). It utilizes data vectors to efficiently send block headers and data. * `Huffman` only performs Huffman compression on data and no matching. The above are also able to take advantage of writer semantics since they do not need to keep a history. Literal and distance code parameters in `token` have also been reworked. Their parameters are now derived mathematically, however the more expensive ones are still obtained through a lookup table (expect on ReleaseSmall). Decompression bit reading has been greatly simplified, taking advantage of the ability to peek on the underlying reader. Additionally, a few bugs with limit handling have been fixed.
2025-09-30std.debug.SelfInfo: remove shared logicmlugg
There were only a few dozen lines of common logic, and they frankly introduced more complexity than they eliminated. Instead, let's accept that the implementations of `SelfInfo` are all pretty different and want to track different state. This probably fixes some synchronization and memory bugs by simplifying a bunch of stuff. It also improves the DWARF unwind cache, making it around twice as fast in a debug build with the self-hosted x86_64 backend, because we no longer have to redundantly go through the hashmap lookup logic to find the module. Unwinding on Windows will also see a slight performance boost from this change, because `RtlVirtualUnwind` does not need to know the module whatsoever, so the old `SelfInfo` implementation was doing redundant work. Lastly, this makes it even easier to implement `SelfInfo` on freestanding targets; there is no longer a need to emulate a real module system, since the user controls the whole implementation! There are various other small refactors here in the `SelfInfo` implementations as well as in the DWARF unwinding logic. This change turned out to make a lot of stuff simpler!
2025-09-30Dwarf.Unwind: fix typomlugg
2025-09-30typomlugg
2025-09-30Dwarf.Unwind: handle macOS deviation from standardmlugg
Apparently the `__eh_frame` in Mach-O binaries doesn't include the terminator entry, but in all other respects it acts like `.eh_frame` rather than `.debug_frame`. I have no idea.
2025-09-30std.debug: significantly speed up capturing stack tracesmlugg
By my estimation, these changes speed up DWARF unwinding when using the self-hosted x86_64 backend by around 7x. There are two very significant enhancements: we no longer iterate frames which don't fit in the stack trace buffer, and we cache register rules (in a fixed buffer) to avoid re-parsing and evaluating CFI instructions in most cases. Alongside this are a bunch of smaller enhancements, such as pre-caching the result of evaluating the CIE's initial instructions, avoiding re-parsing of CIEs, and big simplifications to the `Dwarf.Unwind.VirtualMachine` logic.
2025-09-30std.debug.SelfInfo: mark ARM unwinding as unsupportedmlugg
We need to parse the `.ARM.exidx` section to be able to reliably unwind the stack on ARM.
2025-09-30typomlugg
2025-09-30std: clarify cpu_context register order rationalemlugg
2025-09-30std.debug: cap total stack trace framesmlugg
...just in case there is broken debug info and/or bad values on the stack, either of which could cause stack unwinding to potentially loop forever.
2025-09-30std.debug: don't assume return address register is defined if not specifiedmlugg
This logic was causing some occasional infinite looping on ARM, where the `.debug_frame` section is often incomplete since the `.exidx` section is used for unwind information. But the information we're getting from the compiler is totally *valid*: it's leaving the rule as the default, which is (as with most architectures) equivalent to `.undefined`!
2025-09-30std.debug.SelfInfo: thread safetymlugg
This has been a TODO for ages, but in the past it didn't really matter because stack traces are typically printed to stderr for which a mutex is held so in practice there was a mutex guarding usage of `SelfInfo`. However, now that `SelfInfo` is also used for simply capturing traces, thread safety is needed. Instead of just a single mutex, though, there are a couple of different mutexes involved; this helps make critical sections smaller, particularly when unwinding the stack as `unwindFrame` doesn't typically need to hold any lock at all.
2025-09-30ElfModule: fix assertion failuremlugg
2025-09-30std: don't get CPU context when using CBE targeting MSVCmlugg
Calling `current` here causes compilation failures as the C backend currently does not emit valid MSVC inline assembly. This change means that when building for MSVC with the self-hosted C backend, only FP unwinding can be used.
2025-09-30std.posix.abort: only trigger breakpoint on Windows if being debuggedmlugg
Processes should reasonably be able to expect their children to abort with typical exit codes, rather than a debugger breakpoint signal. This flag in the PEB is what would be checked by `IsDebuggerPresent` in kernel32, which is the function you would typically use for this purpose. This fixes `test-stack-trace` failures on Windows, as these tests were expecting exit code 3 to indicate abort.
2025-09-30std.debug: go back to storing return addresses instead of call addressesmlugg
...and just deal with signal handlers by adding 1 to create a fake "return address". The system I tried out where the addresses returned by `StackIterator` were pre-subtracted didn't play nicely with error traces, which in hindsight, makes perfect sense. This definition also removes some ugly off-by-one issues in matching `first_address`, so I do think this is a better approach.
2025-09-30std: work around crash parsing LLVM PDBmlugg
This crash exists on master, and seems to have existed since 2019; I think it's just very rare and depends on the exact binary generated. In theory, a stream block should always be a "data" block rather than a FPM block; the FPMs use blocks `1, 4097, 8193, ...` and `2, 4097, 8194, ...` respectively. However, I have observed LLVM emitting an otherwise valid PDB which maps FPM blocks into streams. This is not a bug in `std.debug.Pdb`, because `llvm-pdbutil` agrees with our stream indices. I think this is arguably an LLVM bug; however, we don't really lose anything from just weakening this check. To be fair, MSF doesn't have an explicit specification, and LLVM's documentation (which is the closest thing we have) does not explicitly state that FPM blocks cannot be mapped into streams, so perhaps this is actually valid. In the rare case that LLVM emits this, previously, stack traces would have been completely useless; now, stack traces will work okay.
2025-09-30std.debug: fix typomlugg
2025-09-30update to new std.debug changesmlugg
2025-09-30std: allow disabling stack tracingmlugg
This option disables both capturing and printing stack traces. The default is to disable if debug info is stripped.
2025-09-30std.debug: update support checksmlugg
2025-09-30std.debug: miscellaneous fixesmlugg
Mostly on macOS, since Loris showed me a not-great stack trace, and I spent 8 hours trying to make it better. The dyld shared cache is designed in a way which makes this really hard to do right, and documentation is non-existent, but this *seems* to work pretty well. I'll leave the ruling on whether I did a good job to CI and our users.