Commit Graph

34869 Commits

Author SHA1 Message Date
taylor.fish
9f2a200a3f Fix PowerPC restore_rt
Clang fails to compile the CBE translation of this code ("non-ASM
statement in naked function"). Similar to the implementations of
`restore_rt` on x86 and ARM, when the CBE is in use, this commit employs
alternative inline assembly that avoids using non-immediate input
operands.
2025-09-25 03:58:58 +02:00
Jacob Young
a430be097b x86_64: support more in/out forms
Closes #25303
2025-09-25 01:11:05 +02:00
taylor.fish
427f0025db Fix PowerPC syscalls causing invalid code from CBE
Fixes #25209.

On PowerPC, some registers are both inputs to syscalls and clobbered by
them. An example is r0, which initially contains the syscall number, but
may be overwritten during execution of the syscall.

musl and glibc use a `+` (read-write) constraint to indicate this, which
isn't supported in Zig. The current implementation of PowerPC syscalls
in the Zig standard library instead lists these registers as both inputs
and clobbers, but this results in the C backend generating code that is
invalid for at least some C compilers, like GCC, which doesn't support
the specifying the same register as both an input and a clobber.

This PR changes the PowerPC syscall functions to list such registers as
inputs and outputs rather than inputs and clobbers. Thanks to jacobly0
who pointed out that it's possible to have multiple outputs; I had
gotten the wrong idea from the documentation.
2025-09-24 03:50:34 +02:00
Kyle Schwarz
1f0cf7c551 glibc: guard inet-fortified.h 2025-09-24 03:50:29 +02:00
rpkak
bc567312bf use copy_file_range syscall on linux 2025-09-24 03:50:22 +02:00
Carter Snook
6069f908e9 std: always allow spawning processes when an env map is explicitly provided (#25092)
In a library, the two `builtin.link_libc` and `builtin.output_mode ==
.Exe` checks could both be false. Thus, you would get a compile error
even if you specified an `env_map` at runtime. This change turns the
compile error into a runtime panic and updates the documentation to
reflect the runtime requirement.
2025-09-24 03:50:16 +02:00
alexrp
e526d65f5e compiler: don't use self-hosted backend on any BSD yet
There are some blocking bugs in the self-hosted ELF linker.
2025-09-24 01:11:42 +02:00
alexrp
0e673fdab2 std.posix: remove bogus assert that SIGRTMAX < NSIG 2025-09-24 01:11:33 +02:00
alexrp
d6d1fefae9 test: disable test-link on FreeBSD
https://github.com/ziglang/zig/issues/25323
2025-09-24 01:11:27 +02:00
alexrp
a569c7d664 test: disable some stack trace tests on FreeBSD 2025-09-24 01:11:20 +02:00
Alex Rønne Petersen
b8f2fec0f2 std.pie: fix register constraint in getDynamicSymbol() for s390x (#25327)
If the compiler happens to pick `ret = r0`, then this will assemble to
`ag r0, 0` which is obviously not what we want. Using `a` instead of `r` will
ensure that we get an appropriate address register, i.e. `r1` through `r15`.

Re-enable pie_linux for s390x-linux which was disabled in
ed7ff0b693037078f451a7c6c1124611060f4892.
2025-09-24 01:11:02 +02:00
Alex Rønne Petersen
9694c83b95 Revert "frontend: another packedStructFieldPtrInfo fix"
This reverts commit 3ab845e028.
2025-09-22 04:56:46 +02:00
Alex Rønne Petersen
d07b67a55c Revert "x86_64: fix safety crashes in storeRegs"
This reverts commit 37985613c7.
2025-09-21 21:42:39 +02:00
Jacob Young
e647d1a570 x86_64: rewrite vector element pointer access 2025-09-21 21:36:23 +02:00
Alex Rønne Petersen
92b0ec989c ci: temporarily disable riscv64-linux
GitHub sucks:

    Sep 20 20:49:21 ganymede runsvc.sh[82817]: An error occured: Runner version v2.326.0 is deprecated and cannot receive messages.
    Sep 20 20:49:21 ganymede runsvc.sh[82817]: Runner listener exited with error code 1
    Sep 20 20:49:21 ganymede runsvc.sh[82817]: Runner listener exit with terminated error, stop the service, no retry needed.
2025-09-21 21:12:20 +02:00
Jacob Young
ab3e34b09b standalone: fix misaligned stack crash 2025-09-21 21:08:52 +02:00
Jacob Young
80eacd6003 aarch64: fix behavior failures 2025-09-21 21:08:52 +02:00
Frank Denis
798acd932e aarch64/zonCast: don't return a pointer to a stack element
Elements are computed at comptime, so don't declare them as "var".
2025-09-21 21:08:52 +02:00
Andrew Kelley
3da6a19011 x86 codegen: handle spilled tuples 2025-09-21 21:08:52 +02:00
Jacob Young
37985613c7 x86_64: fix safety crashes in storeRegs 2025-09-21 21:08:52 +02:00
Andrew Kelley
670c4fae61 frontend: additionally handle C pointers in ptrOptPayload 2025-09-21 21:08:52 +02:00
Andrew Kelley
4d102751b6 frontend: fix too strict assertion
field ptr can be based on C pointer
2025-09-21 21:08:52 +02:00
Andrew Kelley
3ab845e028 frontend: another packedStructFieldPtrInfo fix
it was calculating host integer size in a wrong way. just use integer
abi size
2025-09-21 21:08:52 +02:00
mlugg
b4394412bb Zcu: fix analysis of type of decl with inferred type
If the `nav_ty` is resolved by the `nav_val`, then we need to also mark
the `nav_ty` as in progress when we begin resolving the `nav_val`.
2025-09-21 21:08:51 +02:00
Andrew Kelley
582b96c361 std.zon.parse: fix not initializing array sentinel 2025-09-21 21:08:51 +02:00
Ryan Liptak
8d5b651c3a Reader.defaultReadVec: Workaround bad r.end += r.vtable.stream() behavior
If `r.end` is updated in the `stream` implementation, then it's possible that `r.end += ...` will behave unexpectedly. What seems to happen is that it reverts back to its value before the function call and then the increment happens. Here's a reproduction:

```zig
test "fill when stream modifies `end` and returns 0" {
    var buf: [3]u8 = undefined;
    var zero_reader = infiniteZeroes(&buf);

    _ = try zero_reader.fill(1);
    try std.testing.expectEqual(buf.len, zero_reader.end);
}

pub fn infiniteZeroes(buf: []u8) std.Io.Reader {
    return .{
        .vtable = &.{
            .stream = stream,
        },
        .buffer = buf,
        .end = 0,
        .seek = 0,
    };
}

fn stream(r: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) std.Io.Reader.StreamError!usize {
    @memset(r.buffer[r.seek..], 0);
    r.end = r.buffer.len;
    return 0;
}
```

When `fill` is called, it will call into `vtable.readVec` which in this case is `defaultReadVec`. In `defaultReadVec`:

- Before the `r.end += r.vtable.stream` line, `r.end` will be 0
- In `r.vtable.stream`, `r.end` is modified to 3 and it returns 0
- After the `r.end += r.vtable.stream` line, `r.end` will be 0 instead of the expected 3

Separating the `r.end += stream();` into two lines fixes the problem (and this separation is done elsewhere in `Reader` so it seems possible that this class of bug has been encountered before).

Potentially related issues:

- https://github.com/ziglang/zig/issues/4021
- https://github.com/ziglang/zig/issues/12064
2025-09-21 21:08:51 +02:00
Frank Denis
c15f8b9fc9 Fix duplicate LC_RPATH entries on macOS Tahoe
When building on macOS Tahoe, binaries were getting duplicate LC_RPATH
load commands which caused dyld to refuse to run them with a
"duplicate LC_RPATH" error that has become a hard error.

The duplicates occurred when library directories were being added
to rpath_list twice:

- from lib_directories
- from native system paths detection which includes the same dirs
2025-09-19 16:39:56 +02:00
Alex Rønne Petersen
90c1123d1c std.mem: work around LoongArch inline asm bug in doNotOptimizeAway()
https://github.com/llvm/llvm-project/issues/159200
2025-09-19 12:13:21 +02:00
Frank Denis
7d8a954578 zig fmt help: mention that the argument can be a directory
I’ve been typing `zig fmt **/.zig` for a long time, until I discovered
that the argument can actually be a directory.

Mention this feature explicitly in the help message.
2025-09-19 12:12:49 +02:00
Frank Denis
91eab35e08 std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)
* std.sort.pdq: fix out-of-bounds access in partialInsertionSort

When sorting a sub-range that doesn't start at index 0, the
partialInsertionSort function could access indices below the range
start. The loop condition `while (j >= 1)` didn't respect the
arbitrary range boundaries [a, b).

This changes the condition to `while (j > a)` to ensure indices
never go below the range start, fixing the issue where pdqContext
would access out-of-bounds indices.

Fixes #25250
2025-09-18 12:47:18 +02:00
rohlem
ac56257738 langref: mention union support of @fieldParentPtr 2025-09-18 12:47:18 +02:00
Ryan Liptak
72017d4bd5 mem.replace: Document that input/output cannot overlap 2025-09-18 12:47:18 +02:00
Andrew Kelley
35de86906d Merge pull request #25201 from jacobly0/x86_64-addsat
x86_64: fix strictness edge cases in `+|`
2025-09-18 12:47:18 +02:00
Jacob Young
b8bf2780a0 Elf: implement linksection
Closes #24330
2025-09-18 12:47:18 +02:00
Silver
e14540399c fix handling of comptime-only union fields in Type.getUnionLayout (#25182)
Fixes #25180
2025-09-18 12:47:17 +02:00
mlugg
87ca304a02 llvm: fix tagged union payload size in debug info
Resolves: #24415
2025-09-18 00:01:28 +01:00
mlugg
83a3365bfd std.math.big.int: normalize zero result for small multiplications
Resolves: #25221
2025-09-16 13:50:33 +02:00
George Huebner
05b7ca6356 bpf: use bitCast instead of intCast in ld_imm_impl
Any 32 bit immediate is allowed in a BPF instruction, including those
greater than the largest positive i32 value.
2025-09-16 13:50:08 +02:00
mlugg
4cfb58342a frontend: fix reference tracking through coerced function bodies
This bug was manifesting for user as a nasty link error because they
were calling their application's main entry point as a coerced function,
which essentially broke reference tracking for the entire ZCU, causing
exported symbols to silently not get exported.

I've been a little unsure about how coerced functions should interact
with the unit graph before, but the solution is actually really obvious
now: they shouldn't! `Sema` is now responsible for unwrapping
possibly-coerced functions *before* queuing analysis or marking unit
references. This makes the reference graph optimal (there are no
redundant edges representing coerced versions of the same function) and
simplifies logic elsewhere at the expense of just a few lines in Sema.
2025-09-15 11:29:54 +01:00
Alex Rønne Petersen
965b2ab6c3 compiler-rt: export __aeabi_read_tp for arm-freebsd
FreeBSD normally provides this symbol in libc, but it's in the
FBSDprivate_1.0 namespace, so it doesn't get included in our abilists file.
Fortunately, the implementation is identical for Linux and FreeBSD, so we can
just provide it in compiler-rt.

It's interesting to note that the same is not true for NetBSD where the
implementation is more complex to support older Arm versions. But we do include
the symbol in our abilists file for NetBSD libc, so that's fine.

closes #25215
2025-09-12 02:35:41 +02:00
LukaTD
38185ee10f langref: added missing newlines to destructuring tuples example
langref: added missing newlines to destructuring tuples example
2025-09-12 02:35:22 +02:00
Andrew Kelley
f06c3d8be7 std.debug.assertAligned: support const pointers 2025-09-12 02:33:35 +02:00
kcbanner
cbe1b4571b webui: fixup build errors in fuzz / time_report 2025-09-12 02:32:06 +02:00
Andrew Kelley
52eb9e84fb langref: update "Choosing an Allocator" section
and delete "Implementing an Allocator" section because it is out of
scope.
2025-09-12 02:30:20 +02:00
Luna Schwalbe
30ec163d14 BitcodeReader: parse blockinfo inside block
Call start/endBlock before/after `parseBlockInfoBlock` in order to not
use the current block context, which is wrong and leads to e.g. incorrect
abbrevlen being used.
2025-09-07 00:34:14 +02:00
Ryan Liptak
76e2764eb1 Fix -M and --dep splitting on every = instead of just the first
Before this commit, -Mfoo=bar=baz would be incorrectly split into mod_name: `foo` and root_src_orig: `bar`
After this commit, -Mfoo=bar=baz will be correctly split into mod_name: `foo` and root_src_orig: `bar=baz`

Closes #25059
2025-09-02 22:35:01 +02:00
Tadej Gašparovič
dcddbcaa60 Fix regression: std.http.Client basic authorization sending user:user instead of user:password when passed in URI 2025-09-02 22:34:51 +02:00
Brandon Mercer
b72a02c592 Populate MSG struct for OpenBSD (#25076)
* update the MSG struct with the correct values for openbsd

* add comment with link to sys/sys/socket.h

---------

Co-authored-by: Brandon Mercer <bmercer@eutonian.com>
2025-09-02 22:34:35 +02:00
Alex Rønne Petersen
d8d497ffe4 std.Thread: make unreachable errors in sleep() clearer 2025-09-02 22:33:35 +02:00
Alex Rønne Petersen
00fb5e34df std.Target: fix alignment for int/long types on m68k 2025-09-02 22:32:17 +02:00