Commit Graph

270 Commits

Author SHA1 Message Date
Corentin Kerisit 07f05426fc Support ld64.ldd STABS layout in MachOFile.load
Apple's ld emit N_BNSYM and N_ENSYM to mark the start and end of
functions, while ld64.lld doesn't.

This resulted in MachOFile.load bailing out on unsupported STABS
layout when the linker used is ld64.lld.

This commit supports both layouts.
2026-04-12 01:23:17 +02:00
Andrew Kelley e9df86aed0 Merge pull request 'std.heap.ArenaAllocator: decrease fuzz test workload per run' (#31596) from justusk/zig:fuzz-arena-2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31596
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:57:41 +02:00
Jonathan Marler f4eecf8d7d handle EROFS in create/open file
I hit an unexpected errno 30 on macos attempting to call createFile on a
directory in PATH.  errno 30 is EROFS, this change propagates that error
as error.ReadOnlyFileSystem.
2026-04-02 15:05:31 +02:00
Justus Klausecker 79f8cf1326 std.debug.Info: make Mach-O source location resolution more resilient
`resolveAddresses` now also works if some calls to `getDwarfForAddress`
fail with `error.MissingDebugInfo`; the affected source location is set
to `.invalid`.

This makes fuzzing work with `ReleaseSafe` for Mach-O.
2026-03-20 17:19:28 +01:00
Alex Rønne Petersen 30de1678a6 Merge pull request 'basic loongarch32-linux support' (#31587) from alexrp/zig:loongarch32 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31587
2026-03-20 02:04:25 +01:00
Alex Rønne Petersen eeb62ef346 std.debug.cpu_context: add loongarch32-linux support 2026-03-19 19:53:03 +01:00
Jacob Young 9ac1386c10 std.Io.Threaded: windows networking without ws2_32 2026-03-18 20:13:59 -04:00
Matthew Lugg 8eefe86939 std: remove default values from ArrayList
These were deprecated in the 0.14.0 release cycle almost a year ago, so
they can definitely be deleted now.
2026-03-10 10:26:08 +00:00
Andrew Kelley ba293eb820 Revert "compiler: override debug_io in release + evented mode"
This reverts commit 6840326711.

The commit bungled deinitialization in main.
2026-02-11 10:44:04 -08:00
Andrew Kelley 6840326711 compiler: override debug_io in release + evented mode
to avoid a dependency on std.Io.Threaded in such case
2026-02-11 00:27:06 +01:00
Jacob Young b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley 4c4e9d054e std.Io: add RwLock and Semaphore sync primitives
and restore usage by std.debug.SelfInfo.Elf
2026-02-02 20:18:14 -08:00
Andrew Kelley 550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
Andrew Kelley 18c6abc0ba std: finish moving os.windows.ReadLink logic to Io.Threaded
- remove error.SharingViolation from all error sets since it has the
  same meaning as FileBusy
- add error.FileBusy to CreateFileAtomicError and ReadLinkError
- update dirReadLinkWindows to use NtCreateFile and NtFsControlFile and
  integrate with cancelation properly.
- move windows CTL_CODE constants to the proper namespace
- delete os.windows.ReadLink
2026-01-28 17:02:17 -08:00
Andrew Kelley 4d6d2922b8 std: move memory locking and memory protection to process
and introduce type safety for posix.PROT (mmap, mprotect)

progress towards #6600
2026-01-09 13:52:00 -08:00
Andrew Kelley ca5c5ade5f std.Options: work around not lazy enough compiler 2026-01-04 00:27:08 -08:00
Andrew Kelley 69d07472a1 std lib tests passing on linux 2026-01-04 00:27:08 -08:00
Andrew Kelley d6a1e73142 std: start wrangling environment variables and process args
this commit is unfinished. It marks a spot where I wanted to start
moving child process stuff below the std.Io.VTable
2026-01-04 00:27:07 -08:00
Matthew Lugg e57c557ad4 std.Io.Threaded: hugely improve Windows and NetBSD support
The most interesting thing here is the replacement of the pthread futex
implementation with an implementation based on thread park/unpark APIs.
Thread parking tends to be the primitive provided by systems which do
not have a futex primitive, such as NetBSD, so this implementation is
far more efficient than the pthread one. It is also useful on Windows,
where `RtlWaitOnAddress` is itself a userland implementation based on
thread park/unpark; we can implement it ourselves including support for
features which Windows' implementation lacks, such as cancelation and
waking a number of waiters with 1<n<infinity.

Compared to the pthread implementation, this thread-parking-based one
also supports full robust cancelation. Thread parking also turns out to
be useful for implementing `sleep`, so is now used for that on Windows
and NetBSD.

This commit also introduces proper cancelation support for most Windows
operations. The most notable omission right now is DNS lookups through
`GetAddrInfoEx`, just because they're a little more work due to having
a unique cancelation mechanism---but the machinery is all there, so I'll
finish gluing it together soon.

As of this commit, there are very few parts of `Io.Threaded` which do
not support full robust cancelation. The only ones which actually really
matter (because they could block for a prolonged period of time) are DNS
lookups on Windows (as discussed above) and futex waits on WASM.
2026-01-03 15:45:10 +00:00
Andrew Kelley fd0c324cb0 std.debug: fix simple_panic 2025-12-23 22:15:11 -08:00
Andrew Kelley 77d2ad8c92 std: consolidate all instances of std.Io.Threaded into a singleton
It's better to avoid references to this global variable, but, in the
cases where it's needed, such as in std.debug.print and collecting stack
traces, better to share the same instance.
2025-12-23 22:15:11 -08:00
Ryan Liptak f96ef9780a SelfInfo.Windows: a few fixes for std.Io 2025-12-23 22:15:10 -08:00
Ryan Liptak f078c7138f std: Update/fix some usages/implementations of std.Io APIs 2025-12-23 22:15:10 -08:00
Andrew Kelley 608145c2f0 fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
Andrew Kelley 22afd168d9 fix build runner compilation errors on macOS 2025-12-23 22:15:09 -08:00
Andrew Kelley e68ae8d7a1 update uses of std.debug.lockStdErr 2025-12-23 22:15:09 -08:00
Andrew Kelley bee8005fe6 std.heap.DebugAllocator: never detect TTY config
instead, allow the user to set it as a field.

this fixes a bug where leak printing and error printing would run tty
config detection for stderr, and then emit a log, which is not necessary
going to print to stderr.

however, the nice defaults are gone; the user must explicitly assign the
tty_config field during initialization or else the logging will not have
color.

related: https://github.com/ziglang/zig/issues/24510
2025-12-23 22:15:08 -08:00
Andrew Kelley 314c906dba std.debug: simplify printLineFromFile 2025-12-23 22:15:08 -08:00
Andrew Kelley f53248a409 update all std.fs.cwd() to std.Io.Dir.cwd() 2025-12-23 22:15:08 -08:00
Andrew Kelley 877032ec6a std: reorganize realpath and process executable APIs 2025-12-23 22:15:08 -08:00
Andrew Kelley 8328de24f1 update all occurrences of openFile to receive an io instance 2025-12-23 22:15:08 -08:00
Andrew Kelley 3204fb7569 update all occurrences of std.fs.File to std.Io.File 2025-12-23 22:15:07 -08:00
Andrew Kelley aafddc2ea1 update all occurrences of close() to close(io) 2025-12-23 22:15:07 -08:00
Andrew Kelley 814480db7c std: all File functions moved to std.Io 2025-12-23 22:15:07 -08:00
Alex Rønne Petersen aa0249d74e Merge pull request 'std.ascii: rename indexOf functions to find' (#30101) from adria/zig:indexof-find into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30101
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2025-12-22 12:50:46 +01:00
Jacob Young c13857e504 windows: type safety improvements and more ntdll functions 2025-12-12 01:58:21 -05:00
Matthew Lugg 65922a2d43 std: make stack unwinding faster on macOS
https://github.com/ziglang/zig/issues/26027#issuecomment-3571227050
tracked some bad performance in `DebugAllocator` on macOS down to a
function in dyld which `std.debug.SelfInfo` was calling into. It turns
out `dladdr`'s symbol lookup logic is horrendously slow (looking at its
source code, it appears to be doing a *linear scan* over all symbols in
the image?!). However, we don't actually need the symbol, so we want to
try and avoid this logic.

Luckily, dyld has more precise APIs for what we need! Unluckily, Apple,
in their infinite wisdom, decided they should be deprecated in favour of
`dladdr`, despite the latter being several times slower (and by "several
times", I have measured a 50x slowdown on repeated calls to `dladdr`
compared to the other API). But luckily again, the deprecated APIs are
still exposed.

So, after a careful analysis of the situation (reading dyld code and
cursing Apple engineers), I think it makes sense to just use these
deprecated APIs for now. If they ever go away, we can write our own
cache for this data to bypass Apple's awfully slow code, but I suspect
these functions will stick around for the foreseeable future.

Uh, and if `_dyld_get_image_header_containing_address` goes away,
there's also `dyld_image_header_containing_address`, which is a
seemingly identical function, exported by dyld just the same, but with a
separate (functionally identical) implementation, and not documented in
the public header file. Apple work in mysterious ways, I guess.
2025-12-06 10:41:42 +00:00
Adrià Arrufat 02c5f05e2f std: replace usages of std.mem.indexOf with std.mem.find 2025-12-05 14:31:27 +01:00
Benjamin Jurk 4b5351bc0d update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Matthew Lugg 0f06b5b583 std.debug.MachOFile: handle 'path/to/archive.a(entry.o)' form 2025-11-20 10:42:21 +00:00
Matthew Lugg 010dcd6a9b fuzzer: account for runtime address slide
This is relevant to PIEs, which are notably enabled by default on macOS.
The build system needs to only see virtual addresses, that is, those
which do not have the slide applied; but the fuzzer itself naturally
sees relocated addresses (i.e. with the slide applied). We just need to
subtract the slide when we communicate addresses to the build system.
2025-11-20 10:42:20 +00:00
Matthew Lugg 0a330d4f94 std.debug.Info: basic Mach-O support 2025-11-20 10:42:20 +00:00
Matthew Lugg 0caca625eb std.debug: split up Mach-O debug info handling
Like ELF, we now have `std.debug.MachOFile` for the host-independent
parts, and `std.debug.SelfInfo.MachO` for logic requiring the file to
correspond to the running program.
2025-11-20 10:42:20 +00:00
Alex Rønne Petersen 9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00
Matthew Lugg 92bc619c49 std.debug: allow fp unwind from context
It's easy to do FP unwinding from a CPU context: you just report the
captured ip/pc value first, and then unwind from the captured fp value.
All this really needed was a couple of new functions on the
`std.debug.cpu_context` implementations so that we don't need to rely on
`std.debug.Dwarf` to access the captured registers.

Resolves: #25576
2025-11-12 21:02:38 +00:00
Alex Rønne Petersen d182c7e3bc Merge pull request #25886 from alexrp/kvx
beginnings of KVX target support (via CBE)
2025-11-10 16:38:23 +01:00
Alex Rønne Petersen 39b5c8ee8a std.debug.Dwarf: add kvx ip/fp/sp register mappings 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen 94b6c7ce5f std.debug.cpu_context: add kvx context implementation 2025-11-10 09:40:44 +01:00
Jacob Young 57889cae80 posix: reduce the number of assumptions made by dl_iterate_phdr
Not yet fully compatible with the new linker, but still progress.

Closes #25786
2025-11-09 03:31:26 -05:00
TibboddiT 62de7a2efd fix typo in std.debug.ElfFile.loadSeparateDebugFile
closes #25667
2025-10-31 09:44:47 +01:00