zig/src
Stephen Gregoratto 6216922a9d Linux: Nuke Stat bits in favour of statx
Maintaining the POSIX `stat` bits for Zig is a pain. The order and
bit-length of members differ between all architectures, and int types
can be signed or unsigned. The libcs deal with this by introducing the
own version of `struct stat` and copying the kernel structure members to
it. In the case of glibc, they did it twice thanks to the largefile
transition!

In practice, the project needs to maintain three versions of `struct
stat`:
- What the kernel defines.
- What musl wants for `struct stat`.
- What glibc wants for `struct stat64`. Make sure to use `fstatat64`!

This isn't as simple as running `zig translate-c`. In #21440 I had to:
- Compile toolchains for each arch+glibc/musl combo.
- Create a test `fstat` program with/without `FILE_OFFSET_BITS=64`.
- Dump the value for `struct stat`.
- Stare at `std.os.linux`/`std.c` and cry.
- Add some missing padding.

The fact that so many target checks in the `linux` and `posix` tests
exist is most likely due to writing to padding bits and failing later.

The solution to this madness is `statx(2)`:
- It takes a single structure that is the same for all arches AND libcs.
- It uses a custom timestamp format, but it is 64-bit ready.
- It gives the same info as `fstatat(2)` and more!
- Unlike `fstatat(2)`, you can request a subset of the info required
  based on passing a mask.

It's so good that modern Linux arches (e.g. riscv) don't even implement
`stat`, with the libcs using a generic `struct stat` and copying from
`struct statx`.

Therefore, this commit rips out all the `stat` bits from `std.os.linux`
and `std.c`. `std.posix.Stat` is now `void`, and calling
`std.posix.*stat` is an compile-time error. A wrapper around `statx` has
been added to `std.os.linux`, and callers have been upgraded to use it.
Tests have also been updated to use `statx` where possible.

While I was here, I converted the mask and file attributes to be packed
struct bitfields. A nice side effect is checking that you actually
recieved the members you asked for via `Statx.mask`, which I have used
by adding `assert`s at specific callsites.
2025-12-14 01:41:47 +01:00
..
Air update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
codegen llvm: fix aliases not having linkage, visibility, etc set 2025-12-10 15:40:30 +01:00
Compilation represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
libs libc: update startup code from freebsd 15 2025-12-07 09:18:38 +01:00
link Linux: Nuke Stat bits in favour of statx 2025-12-14 01:41:47 +01:00
Package fetch: update from std.Thread.Pool to std.Io 2025-11-25 09:40:27 -08:00
Sema compiler: spring cleaning 2025-11-12 16:00:15 +00:00
Zcu frontend: introduce error.Canceled 2025-11-24 14:34:18 -08:00
Air.zig compiler: replace @Type with individual type-creating builtins 2025-11-22 22:42:37 +00:00
Builtin.zig compiler: update for introduction of std.Io 2025-10-29 06:20:49 -07:00
clang_options.zig zig cc: honor all -m and -mno- CPU feature flags 2021-11-26 19:59:33 -07:00
clang_options_data.zig zig cc: update options data to LLVM 21 2025-08-30 06:36:41 +02:00
codegen.zig codegen: fix tuple padding 2025-11-04 06:04:30 -05:00
Compilation.zig Compilation: fix appendFileSystemInput race between main thread and C object workers 2025-12-06 09:54:43 +01:00
crash_report.zig std.debug.lockStderrWriter: also return ttyconf 2025-10-30 09:31:28 +00:00
DarwinPosixSpawn.zig std.c.darwin: cleanup, expose everything in std.c 2025-08-20 18:21:32 +02:00
dev.zig remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
fmt.zig std.debug.lockStderrWriter: also return ttyconf 2025-10-30 09:31:28 +00:00
IncrementalDebugServer.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
InternPool.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
introspect.zig compiler: refactor Zcu.File and path representation 2025-05-18 17:37:02 +01:00
link.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
main.zig Merge pull request 'link: support --dependency-file linker option' (#30073) from alexrp/zig:elf-depfile into master 2025-12-06 08:32:25 +01:00
mutable_value.zig Sema: Improve comptime arithmetic undef handling 2025-08-12 16:33:57 +02:00
Package.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
print_env.zig progress towards compiler building again 2025-10-29 06:20:49 -07:00
print_targets.zig rework std.Io.Writer.Allocating to support runtime-known alignment 2025-08-30 00:48:50 -07:00
print_value.zig frontend: introduce error.Canceled 2025-11-24 14:34:18 -08:00
print_zir.zig detect comptime var references in asm input/output and improve errors 2025-12-06 09:42:51 +01:00
print_zoir.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
RangeSet.zig std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
register_manager.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Sema.zig sema: remove special case check in is_non_err 2025-12-08 14:59:55 +01:00
target.zig compiler: don't use self-hosted backends on big-endian hosts 2025-11-19 01:42:45 +01:00
tracy.zig Update TracyAllocator to new allocator API 2025-07-05 00:24:40 +02:00
Type.zig Return a usize from @abs if given an isize 2025-11-29 21:09:08 +01:00
Value.zig frontend: introduce error.Canceled 2025-11-24 14:34:18 -08:00
Zcu.zig detect comptime var references in asm input/output and improve errors 2025-12-06 09:42:51 +01:00
zig_clang_cc1_main.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_clang_cc1as_main.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_clang_driver.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_llvm-ar.cpp zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
zig_llvm.cpp Support generating import libraries from mingw .def files without LLVM 2025-10-03 18:26:05 -07:00
zig_llvm.h Support generating import libraries from mingw .def files without LLVM 2025-10-03 18:26:05 -07:00