32400 Commits

Author SHA1 Message Date
mlugg
dd334d5ee5
stage1: update zig1.wasm
Oh dear, not again! Sorry, I changed the panic handler...

Signed-off-by: mlugg <mlugg@mlugg.co.uk>
2025-01-24 21:07:14 +00:00
mlugg
b0a8931690
Sema: prepare to remove ?*StackTrace argument from unwrapError and call
Now that we propagate the error return trace to all `callconv(.auto)`
functions, passing it explicitly to panic handlers is redundant.
2025-01-24 20:50:20 +00:00
mlugg
83991efe10
compiler: yet more panic handler changes
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace.
* `root.Panic` -> `root.panic` for the same reason. There are type
  checks so that we still allow the legacy `pub fn panic` strategy in
  the 0.14.0 release.
* `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason.
* `std.debug.NoPanic` -> `std.debug.no_panic`, same reason.
* `std.debug.FormattedPanic` is now a function `std.debug.FullPanic`
  which takes as input a `panicFn` and returns a namespace with all the
  panic functions. This handles the incredibly common case of just
  wanting to override how the message is printed, whilst keeping nice
  formatted panics.
* Remove `std.builtin.panic.messages`; now, every safety panic has its
  own function. This reduces binary bloat, as calls to these functions
  no longer need to prepare any arguments (aside from the error return
  trace).
* Remove some legacy declarations, since a zig1.wasm update has
  happened. Most of these were related to the panic handler, but a quick
  grep for "zig1" brought up a couple more results too.

Also, add some missing type checks to Sema.

Resolves: #22584

formatted -> full
2025-01-24 19:29:51 +00:00
Alex Rønne Petersen
b3d9b0e3f6 musl: Manually inline __tls_get_addr into s390x __tls_get_offset.
See these mailing list threads:

* https://www.openwall.com/lists/musl/2024/11/23/3
* https://www.openwall.com/lists/musl/2025/01/24/1

This supplants cc73d7ad749df8d53da442faa2e7af5d69357b33.
2025-01-24 20:02:30 +01:00
Matthew Lugg
f77e1b8622
Merge pull request #22578 from mlugg/stack-trace-tests-x86_64
tests: enable stack trace tests for x86_64-selfhosted
2025-01-24 05:11:26 +00:00
Alex Rønne Petersen
180db2bf23
std.debug: Fall back to .eh_frame/.debug_frame if .eh_frame_hdr is incomplete.
When using the self-hosted backends, especially in incremental mode, the
.eh_frame_hdr section may be incomplete, so we can't treat it as authoritative.

Instead, if we started out intending to use .eh_frame_hdr but find that it's
incomplete, load .eh_frame/.debug_frame on demand and use that info going
forward.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
41185d297f
Package.Module: Make create() fall back on options.global.root_optimize_mode.
As is done for root_strip and root_error_tracing.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
ef4d7f01a5
compiler: Fix computation of Compilation.Config.any_unwind_tables.
This moves the default value logic to Package.Module.create() instead and makes
it so that Compilation.Config.any_unwind_tables is computed similarly to
any_sanitize_thread, any_fuzz, etc. It turns out that for any_unwind_tables, we
only actually care if unwind tables are enabled at all, not at what level.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
b46a40ff1d
compiler: Handle --no-eh-frame-hdr as a regular zig build-* flag too.
For some reason we accepted --eh-frame-hdr, but not --no-eh-frame-hdr, despite
accepting the latter as a -Wl linker flag.
2025-01-23 23:22:38 +00:00
mlugg
7774287fdc
tests: enable stack trace tests for x86_64-selfhosted
Allows the stack trace tests to be additionally compiled and run with
`.use_llvm = false, .use_lld = false` depending on the host target. This
is currently enabled for x86_64 targets emitting ELF.

Self-hosted backends emit slightly different DWARF info to the LLVM
backend, so the checking logic (and the tests themselves) had to be
tweaked slightly to support both backends at once.
2025-01-23 23:22:13 +00:00
Alex Rønne Petersen
d916954bee
Merge pull request #22098 from alexrp/wasm-generic-baseline
`std.Target`: Use `lime1` as wasm baseline model and `mvp` as generic model
2025-01-23 18:41:11 +01:00
Pierre Tachoire
f3c29dcb24 std.posix.setsockopt: EOPNOTSUPP can be returned
On Linux, set REUSEPORT option on an unix socket returns a EOPNOTSUPP
error.
See 5b0af621c3
2025-01-23 14:35:57 +01:00
John Benediktsson
530335b572
adding std.c.TCP.NODELAY for macos (#22404)
closes #17260
2025-01-23 04:01:05 +00:00
Alex Rønne Petersen
68c6a88770
link.Wasm.Feature: Make fromCpuFeature() and toCpuFeature() less cute.
This is more verbose, but at least we now get a compile error instead of UB when
a new feature is added to std.Target.wasm.Feature but not to link.Wasm.Feature.
2025-01-22 21:18:15 +01:00
Alex Rønne Petersen
35e804bfb8
wasm2c: Implement nontrapping_fptoint support. 2025-01-22 20:56:30 +01:00
Alex Rønne Petersen
ea1502974d
wasm: Add a nontrapping_bulk_memory_len0 feature.
This will mainly be used when targeting our wasm2c implementation which has no
problem with zero-length bulk memory operations, as a non-standard extension.
2025-01-22 20:56:28 +01:00
Matthew Lugg
0e815c652d
Merge pull request #22572 from jacobly0/new-error-trace
compiler: include error trace in all functions, implement for x86_64 backend
2025-01-22 16:48:27 +00:00
Matthew Lugg
61fe307d0f
Merge pull request #22571 from mlugg/various-fixes-again
compiler: a few fixes
2025-01-22 16:47:45 +00:00
Jacob Young
d4b6a53327 x86_64: implement error return traces 2025-01-22 03:44:13 -05:00
mlugg
9b7b240c8e std.builtin: make returnError not take the error trace
It's now unnecessary to explicitly pass this, because it receives an
implicit error trace parameter anyway, so can just use
`@errorReturnTrace()`. The previous commit updated Sema to expect this
new interface. This saves an AIR instruction at all `returnError` call
sites.
2025-01-22 02:22:56 -05:00
mlugg
8b5c4baed8 stage1: update zig1.wasm
Necessary because the API of `std.builtin.returnError` changed.

Signed-off-by: mlugg <mlugg@mlugg.co.uk>
2025-01-22 02:22:56 -05:00
mlugg
1bce01de97 compiler: pass error return traces everywhere 2025-01-22 02:22:56 -05:00
mlugg
e864c38cc3
Sema: fix crash when inline loop condition is not comptime-known 2025-01-22 04:18:43 +00:00
mlugg
8470b6ea37
Zcu: fix switch prong source location resolution
Resolves: #22343
2025-01-22 04:11:02 +00:00
BratishkaErik
941677e083
std.Build: add addLibrary function (#22554)
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:

In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default

const lib = b.addLibrary(.{
    .linkage = linkage,
    .name = "foo_bar",
    .root_module = mod,
});
```

In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
    .target = target,
    .optimize = optimize,
    .linkage = .static // or dynamic
});

mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```

It also matches nicely with `linkLibrary` name.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-22 02:29:21 +00:00
mlugg
6e7ae66871
std.debug: remove errorReturnTraceHelper
This function doesn't do what it says; it's a nop.
2025-01-22 02:02:33 +00:00
Alex Rønne Petersen
280ced66eb
std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.
See: https://github.com/WebAssembly/tool-conventions/pull/235

This is not *quite* using the same features as the spec'd lime1 model because
LLVM 19 doesn't have the level of feature granularity that we need for that.
This will be fixed once we upgrade to LLVM 20.

Part of #21818.
2025-01-22 03:01:05 +01:00
Alex Rønne Petersen
206373ca61
std.Target: Use mvp as the generic CPU model for wasm32/wasm64.
As discussed in #21818, generic is a poor baseline model because that model is a
moving target in LLVM. Instead, use mvp, which has no features enabled.
2025-01-22 03:01:05 +01:00
Alex Rønne Petersen
e800ea0fdd
wasm: Add a check for zero length around uses of memory.copy/memory.fill.
Apparently the WebAssembly spec requires these instructions to trap if the
computed memory access could be out of bounds, even if the length is zero.
Really a rather bizarre design choice.
2025-01-22 03:01:02 +01:00
mlugg
f244c8891a
std.mem.Allocator: remove redundant check
This check doesn't make sense with the modern Allocator API; it's left over
from when realloc could change alignment. It's statically known (but not
comptime-known) to be true always. This check was one of the things
blocking Allocator from being used at comptime (related: #1291).
2025-01-22 02:00:47 +00:00
Alex Rønne Petersen
28a259d4a3 ci: Switch to Wasmtime v29.0.0. 2025-01-21 18:47:08 -05:00
Andrew Kelley
f07bea20da
Merge pull request #21447 from Szwagi/fix-lzma-memcpy-alias
Fix memcpy alias bug in std.compress.lzma
2025-01-21 18:37:28 -05:00
Fabio Arnold
97b97ae620
Package fetch: add executable detection for Mach-O file headers (#21555) 2025-01-21 11:48:19 -08:00
Andrew Kelley
b31a2c9555
Merge pull request #22541 from ziglang/pipeline
Compilation pipeline: spawn Jobs earlier that produce linker inputs
2025-01-21 14:27:05 -05:00
Andrew Kelley
0bacb79c09 Revert "Merge pull request #21540 from BratishkaErik/search-env-in-path"
It caused an assertion failure when building Zig from source.

This reverts commit 0595feb34128db22fbebea843af929de3ede8190, reversing
changes made to 744771d3303e122474a72c8a94b14fe1e9fb480c.

closes #22566
closes #22568
2025-01-21 11:22:28 -08:00
Andrew Kelley
18fcb3b5e8
Merge pull request #18912 from dweiller/memcpy-opt
optimized memcpy
2025-01-21 13:05:14 -05:00
Jacob Young
d652dd0658 x86_64: rewrite @abs for scalar floats 2025-01-21 06:39:24 -05:00
andrewkraevskii
f1ce1aff11 std.debug: fix format on ConfigurableTrace 2025-01-21 10:54:14 +01:00
Alex Rønne Petersen
f1f269c6ee libc: Remove a bunch of code for architectures we don't actually support.
Namely:

* alpha
* hppa
* ia64
* microblaze
* nios2
* or1k
* s390
* sh
2025-01-21 09:30:16 +01:00
Andrew Kelley
09d021c908 add test coverage for previous commit 2025-01-20 21:41:30 -08:00
Kamil T
d50bae4da9 Fix memcpy alias bug in std.compress.lzma 2025-01-20 21:41:12 -08:00
Andrew Kelley
0595feb341
Merge pull request #21540 from BratishkaErik/search-env-in-path
std.zig.system: use both PATH and hardcoded locations to find `env`
2025-01-21 00:16:19 -05:00
Andrew Kelley
744771d330
Merge pull request #22536 from BryceVandegrift/access-er13
std.posix: Fix errno 13 when writing to file
2025-01-21 00:10:05 -05:00
Andrew Kelley
1110950528 std.posix.WriteError: update AccessDenied docs
It can happen on POSIX too.
2025-01-20 21:08:44 -08:00
Bryce Vandegrift
e4d5706957 std.posix: Fix errno 13 when writing to file 2025-01-20 21:07:49 -08:00
Andrew Kelley
874e17fe60 embrace the future slightly less
Turns out that even modern Debian aarch64 glibc libc_nonshared.a has
references to _init, meaning that the previous commit caused a
regression when trying to build any -lc executable on that target.

This commit backs out the changes to LibCInstallation.

There is still a fork in the road coming up when the self-hosted ELF
linker becomes load bearing on that target.
2025-01-20 20:59:52 -08:00
Andrew Kelley
f5485a52bc reject crti.o/crtn.o, embrace the future
crti.o/crtn.o is a legacy strategy for calling constructor functions
upon object loading that has been superseded by the
init_array/fini_array mechanism.

Zig code depends on neither, since the language intentionally has no way
to initialize data at runtime, but alas the Zig linker still must
support this feature since popular languages depend on it.

Anyway, the way it works is that crti.o has the machine code prelude of
two functions called _init and _fini, each in their own section with the
respective name. crtn.o has the machine code instructions comprising the
exitlude for each function. In between, objects use the .init and .fini
link section to populate the function body.

This function is then expected to be called upon object initialization
and deinitialization.

This mechanism is depended on by libc, for example musl and glibc, but
only for older ISAs. By the time the libcs gained support for newer
ISAs, they had moved on to the init_array/fini_array mechanism instead.

For the Zig linker, we are trying to move the linker towards
order-independent objects which is incompatible with the legacy
crti/crtn mechanism.

Therefore, this commit drops support entirely for crti/crtn mechanism,
which is necessary since the other commits in this branch make it
nondeterministic in which order the libc objects and the other link
inputs are sent to the linker.

The linker is still expected to produce a deterministic output, however,
by ignoring object input order for the purposes of symbol resolution.
2025-01-20 20:59:52 -08:00
Andrew Kelley
2391c460b1 fix build failure when llvm not available 2025-01-20 20:59:52 -08:00
Andrew Kelley
77af309cb6 Compilation: take advantage of @splat 2025-01-20 20:59:52 -08:00
Andrew Kelley
28da530271 Compilation pipeline: linker input producing Job representation
Move all the remaining Jobs that produce linker inputs to be spawned
earlier in the pipeline and registered with link_task_wait_group.
2025-01-20 20:59:52 -08:00