Commit graph

33844 commits

Author SHA1 Message Date
Alex Rønne Petersen
9f064dff47
langref: runtime_shrExact_overflow does not work as expected on RISC-V
https://github.com/ziglang/zig/issues/24304
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
b739fec841
test: Disable stack_iterator test on riscv64-linux
https://github.com/ziglang/zig/issues/24310
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
1f2e3b39ae
test: Disable vector division operators on RISC-V with vector support
https://github.com/ziglang/zig/issues/24301
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
1fcabe0bfc
test: Only run coff_dwarf test on aarch64, x86, x86_64
This will just fail if run on architectures like riscv64.
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
80c3de40b3
test: Properly limit glibc_compat versions based on the host 2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
3d7fb4f204
std.zig.system.linux: Add detection for some extra RISC-V CPUs 2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
fd2d4507c8
std.os.linux: Define ucontext_t and mcontext_t for RISC-V
Closes #24239.
2025-07-01 23:03:13 +02:00
Alex Rønne Petersen
07114e6bc6
llvm: Disable the machine outliner pass on RISC-V 2025-07-01 18:16:40 +02:00
Alex Rønne Petersen
aa7b32d781
llvm: Fix alignment of by-ref ptr_elem_val and slice_elem_val 2025-07-01 18:16:36 +02:00
Alex Rønne Petersen
6b6e336e07
std.Build.Step.CheckObject: Truncate st_other before interpreting it
Tools are free to use the upper bits of this field for whatever; thus, tools
that want to interpret the visibility type should truncate to 2 bits.
2025-06-30 12:21:38 +02:00
Alex Rønne Petersen
b64fe53ad5
std.simd: Increase branch quota in suggestVectorLengthForCpu()
This does a bunch of CPU family and feature checks. It would be annoying to have
to @setEvalBranchQuota() at every comptime use site.
2025-06-30 08:01:27 +02:00
Alex Rønne Petersen
197fb26da0
libunwind: Fix return type of DwarfFDECache<A>::findFDE()
https://github.com/llvm/llvm-project/pull/146308
2025-06-30 06:40:17 +02:00
Alex Rønne Petersen
e837765956
zig rc: Fix include directory detection when cross-compiling from certain host archs (#24288)
* resinator: Only preprocess when the input is an .rc file

* resinator: Fix include directory detection when cross-compiling from certain host archs

Previously, resinator would use the host arch as the target arch when looking for windows-gnu include directories. However, Zig only thinks it can provide a libc for targets specified in the `std.zig.target.available_libcs` array, which only includes a few for windows-gnu. Therefore, when cross-compiling from a host architecture that doesn't have a windows-gnu target in the available_libcs list, resinator would fail to detect the MinGW include directories.

Now, the custom option `/:target` is passed to `zig rc` which is intended for the COFF object file target, but can be re-used for the include directory target as well. For the include directory target, resinator will convert the MachineType to the relevant arch, or fail if there is no  equivalent arch/no support for detecting the includes for the MachineType (currently 64-bit Itanium and EBC).

Fixes the `windows_resources` standalone test failing when the host is, for example, `riscv64-linux`.
2025-06-29 09:59:38 +02:00
Ryan Liptak
d3363b7a61 Replace unreachable with error return for non-standard Windows targets
This new error mirrors the error returned from the Elf struct (error.UnsupportedElfArchitecture):

0adcfd60f4/src/link/Lld.zig (L112)

Before:

```
$ zig build-exe -target riscv64-windows-gnu main.zig
thread 543087 panic: reached unreachable code
```

After:

```
$ zig build-exe -target riscv64-windows-gnu main.zig
error: unable to create compilation: UnsupportedCoffArchitecture
```

Closes #24287
2025-06-29 08:32:19 +02:00
Alex Rønne Petersen
6322dbd5bf
compiler: test runner: fix tests never fails on crippled architectures (#24180)
* compiler: test runner: fix tests never fails on crippled architectures

* riscv64: skip failing tests

* riscv64: enable test summary printing
2025-06-29 08:03:59 +02:00
Ryan Liptak
09f4e2d9d1 resinator: Fix include directory detection when cross-compiling from certain host archs
Previously, resinator would use the host arch as the target arch when looking for windows-gnu include directories. However, Zig only thinks it can provide a libc for targets specified in the `std.zig.target.available_libcs` array, which only includes a few for windows-gnu. Therefore, when cross-compiling from a host architecture that doesn't have a windows-gnu target in the available_libcs list, resinator would fail to detect the MinGW include directories.

Now, the custom option `/:target` is passed to `zig rc` which is intended for the COFF object file target, but can be re-used for the include directory target as well. For the include directory target, resinator will convert the MachineType to the relevant arch, or fail if there is no  equivalent arch/no support for detecting the includes for the MachineType (currently 64-bit Itanium and EBC).

Fixes the `windows_resources` standalone test failing when the host is, for example, `riscv64-linux`.
2025-06-28 19:52:18 -07:00
Ryan Liptak
761783f54d resinator: Only preprocess when the input is an .rc file 2025-06-28 19:43:22 -07:00
Bingwu Zhang
ff06de4c89
riscv64: enable test summary printing 2025-06-28 06:47:09 +08:00
Bingwu Zhang
e8d6ecb9ce
riscv64: skip failing tests 2025-06-28 06:47:09 +08:00
Bingwu Zhang
5db395f20b
compiler: test runner: fix tests never fails on crippled architectures 2025-06-27 19:12:16 +08:00
Jonathan Marler
0adcfd60f4
Fix warning WasmMut_toC not all control paths return a value (#24267)
* Fix warning WasmMut_toC not all control paths return a value

This is a follow up to https://github.com/ziglang/zig/pull/24206 where
I had previously submitted different mechanisms to fix this warning.
This PR is a suggestion by Alex to return NULL instead and Andrew
confirmed this is his preference.
2025-06-26 05:39:08 +00:00
Andrew Kelley
8eca338c27 fix zig libc FTBFS 2025-06-25 05:17:46 -07:00
Marc
75d6d4c3f2
add glibc versioning for a number of headers (#24237)
* getrandom was added in glibc 2.25
https://sourceware.org/bugzilla/show_bug.cgi?id=17252

* copy_file_range was added in glibc 2.27
https://sourceware.org/git/?p=glibc.git;a=commit;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f

* threads.h should not exist for glibc < 2.28

* single_threaded.h should not exist for glibc < 2.35

* Apply suggestions from code review

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* 2.35 instead of 35

* before 2.35 instead of 2.34 and before

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-06-24 16:14:00 +00:00
Dacheng
35329b510c
c.darwin: define MSG for macos (#24224)
* c.darwin: define MSG for macos

* darwin: add series os name

* Update lib/std/c.zig

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-06-24 15:07:06 +02:00
Alex Rønne Petersen
342c34d95e
Merge pull request #24238 from taylordotfish/bugfix/ppc64le-syscall 2025-06-24 15:06:31 +02:00
Pat Tullmann
710632b45c lib/std/fs/test.zig: Some filesystems support 8 EiB files
Btrfs at least supports 16 EiB files (limited in practice to 8EiB by the
Linux VFS code which uses signed 64-bit offsets).  So fix the fs.zig test
case to expect either a FileTooBig or success from truncating a file to
8EiB.  And test that beyond that size the offset is interpreted as a
negative number.

Fixes #24242
2025-06-23 15:20:24 +02:00
Kevin Boulain
640a130651 std.Build.Watch: key fanotify file descriptors by mount id
Since marks are limited to a single filesystem.
Context: https://github.com/ziglang/zig/issues/20670
Original pull request: https://github.com/ziglang/zig/pull/20672

Co-authored-by: Maciej 'vesim' Kuliński <vesim809@pm.me>
2025-06-23 06:08:25 +02:00
Ali Cheraghi
1df79ab895 remove spirv cpu arch 2025-06-23 06:03:03 +02:00
Jacob Young
c71bb0f2b6 x86_64: fix pair live-out tracking
Closes #24226
2025-06-23 05:58:14 +02:00
Ali Cheraghi
24bfefa75e std.mem.byteSwapAllFields: support untagged unions 2025-06-23 05:57:56 +02:00
taylor.fish
95b638f613 Update 32-bit PowerPC syscall functions
musl and glibc both specify r0 as an output register because its value
may be overwritten by system calls. As with the updates for 64-bit
PowerPC in the previous commit, this commit brings Zig's syscall
functions for 32-bit PowerPC in line with musl and glibc by adding r0 to
the list of clobbers. (Listing r0 as both an input and a clobber is as
close as we can get to musl, which declares it as a "+r" read-write
output, since Zig doesn't support multiple outputs or the "+"
specifier.)
2025-06-22 16:48:36 -07:00
David Rubin
3034d1e377 minor grammatical mistake 2025-06-22 20:00:17 +02:00
taylor.fish
79807468e7 Fix illegal behavior from syscalls on powerpc64le
On powerpc64le Linux, the registers used for passing syscall parameters
(r4-r8, as well as r0 for the syscall number) are volatile, or
caller-saved. However, Zig's syscall wrappers for this architecture do
not include all such registers in the list of clobbers, leading the
compiler to assume these registers will maintain their values after the
syscall completes.

In practice, this resulted in a segfault when allocating memory with
`std.heap.SmpAllocator`, which calls `std.os.linux.sched_getaffinity`.
The third parameter to `sched_getaffinity` is a pointer to a `cpu_set_t`
and is stored in register r5. After the syscall, the code attempts to
access data in the `cpu_set_t`, but because the compiler doesn't realize
the value of r5 may have changed, it uses r5 as the memory address, which
in practice resulted in a memory access at address 0x8.

This commit adds all volatile registers to the list of clobbers.
2025-06-21 21:47:58 -07:00
Matthew Lugg
75d0ec9c04
Merge pull request #24227 from mlugg/misc-build-stuff
`std.Build`: more miscellaneous bits
2025-06-20 10:28:38 +01:00
Koki Ueha
9e340b3005 This commit enables fmax and fmin to differentiate between 0.0 and
-0.0, making it compatible with musl.
2025-06-20 10:17:24 +02:00
Alex Rønne Petersen
14ad8378a1
Merge pull request #23464 from rootbeer/futex-casts
Linux futex (v1 and v2) API fixes, tests and Ziggification
2025-06-20 10:08:22 +02:00
Jacob Young
cf1a7bbd44
Merge pull request #24193 from jacobly0/x86_64-spring-cleaning
x86_64: increase passing test coverage on windows
2025-06-20 00:20:56 -04:00
mlugg
4a9e8b73aa
std.Build.Step.Run: pass correct relative cache dir to tests
Fixes an additional bug reported in the closed #24216.
2025-06-20 00:33:44 +01:00
mlugg
a02a2219ee
standalone: add accidentally-excluded test 2025-06-20 00:24:57 +01:00
Jacob Young
1f98c98fff x86_64: increase passing test coverage on windows
Now that codegen has no references to linker state this is much easier.

Closes #24153
2025-06-19 18:41:12 -04:00
Jacob Young
ed37a1a33c coff: add hack to build a compiler-rt dynamic library
This is not meant to be a long-term solution, but it's the easiest thing
to get working quickly at the moment. The main intention of this hack is
to allow more tests to be enabled. By the time the coff linker is far
enough along to be enabled by default, this will no longer be required.
2025-06-19 18:41:12 -04:00
Jacob Young
e92b129063 Compilation: fix use after free
Closes #23967
2025-06-19 18:41:11 -04:00
Jacob Young
917640810e Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it
consistently shows up in profiles of the compiler.
2025-06-19 11:45:06 -04:00
Jacob Young
16d78bc0c0 Build: add install commands to --verbose output 2025-06-19 11:45:06 -04:00
Jacob Young
df4068cabd Build: change how the target is printed in step names
e.g. `x86_64-windows.win10...win11_dt-gnu` -> `x86_64-windows-gnu`

When the OS version is the default this is redundant with checking the
default in the standard library.
2025-06-19 11:45:06 -04:00
Jonathan Marler
f5a327cd36 windows: msvc: avoid linking to non-redistributable ucrt 2025-06-19 13:43:27 +02:00
Pat Tullmann
89d15a8d47 linux: futex v2 API updates
* `futex2_waitv` always takes a 64-bit timespec.  Perhaps the
  `kernel_timespec` should be renamed `timespec64`?  Its used in iouring,
  too.

* Add `packed struct` for futex v2 flags and parameters.

* Add very basic "tests" for the futex v2 syscalls (just to ensure the
  code compiles).

* Update the stale or broken comments.  (I could also just delete these
  they're not really documenting Zig-specific behavior.)

Given that the futex2 APIs are not used by Zig's library (they're a bit
too new), and the fact that these are very specialized syscalls, and they
currently provide no benefit over the existing v1 API, I wonder if instead
of fixing these up, we should just replace them with a stub that says 'use
a 3rd party library'.
2025-06-18 19:53:50 -07:00
mlugg
36499c251c std.Build.Step.Run: prefix relative path arguments with './'
This is necessary in two cases:

* On POSIX, the exe path (`argv[0]`) must contain a path separator
* Some programs might treat a file named e.g. `-foo` as a flag, which
  can be avoided by passing `./-foo`

Rather than detecting these two cases, just always include the prefix;
there's no harm in it.

Also, if the cwd is specified, include it in the manifest. If the user
has set the cwd of a Run step, it is clearly because this affects the
behavior of the executable somehow, so that cwd path should be a part of
the step's manifest.

Resolves: #24216
2025-06-18 22:45:05 +01:00
Jonathan Marler
f3940ad858 windows: MSVC: disable extra dubious Microsoft runtime checks
Cmake by default adds the `/RTC1` compiler flag for debug builds.
However, this causes C code that conforms to the C standard and has
well-defined behavior to trap. Here I've updated CMAKE to use the more
lenient `/RTCs` by default which removes the uninitialized variable checks
but keeps the stack error checks.
2025-06-18 16:41:25 +02:00
Pat Tullmann
cfe5defd02 linux: futex v1 API cleanup
* Use `packed struct` for flags arguments.  So, instead of
  `linux.FUTEX.WAIT` use `.{ .cmd = .WAIT, .private = true }`

* rename `futex_wait` and `futex_wake` which didn't actually specify
  wait/wake, as `futex_3arg` and `futex_4arg` (as its the number
  of parameters that is different, the `op` is whatever is specified.

* expose the full six-arg flavor of the syscall (for some of the advanced
  ops), and add packed structs for their arguments.

* Use a `packed union` to support the 4th parameter which is sometimes a
  `timespec` pointer, and sometimes a `u32`.

* Add tests that make sure the structure layout is correct and that the
  basic argument passing is working (no actual futexes are contended).
2025-06-17 22:06:39 -07:00