zig/test
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
..
behavior stage2_wasm: revival, enabling tests 2025-12-07 07:21:15 +01:00
c_abi x86_64: fix abi of a struct that partially fits in registers 2025-11-27 05:05:59 +01:00
cases sema: remove special case check in is_non_err 2025-12-08 14:59:55 +01:00
cli/options test: move standalone/options/ to cli/options/ 2025-10-04 21:55:39 +02:00
incremental Revert "disable flaky test/incremental/add_decl" 2025-11-22 08:09:12 -08:00
link test: disable test-link on big-endian hosts 2025-11-19 01:42:45 +01:00
src stage2_wasm: revival, enabling tests 2025-12-07 07:21:15 +01:00
standalone Linux: Nuke Stat bits in favour of statx 2025-12-14 01:41:47 +01:00
behavior.zig delete behavior test that depends on std.fmt 2025-08-31 12:49:18 -07:00
cases.zig test: remove ad-hoc nvptx tests 2025-10-04 20:51:07 +02:00
compile_errors.zig compiler: refactor Zcu.File and path representation 2025-05-18 17:37:02 +01:00
error_traces.zig test: disable an error trace test on optimized s390x-linux 2025-11-19 01:42:45 +01:00
gen_h.zig all: zig fmt and rename "@XToY" to "@YFromX" 2023-06-19 12:34:42 -07:00
libc.zig libc-test: disable utime.c 2025-10-15 10:58:30 +02:00
llvm_ir.zig test: Add some basic LLVM IR tests for atomics, volatile, and allowzero. 2025-05-12 17:07:50 +02:00
llvm_targets.zig represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
stack_traces.zig std: back out the StackTrace byval changes 2025-10-29 06:20:50 -07:00
tests.zig stage2_wasm: revival, enabling tests 2025-12-07 07:21:15 +01:00