Commit Graph

31606 Commits

Author SHA1 Message Date
Alex Rønne Petersen
d89cf3e7d8
test: Add the ability to skip specific modules for a target. 2024-11-03 09:29:33 +01:00
Alex Rønne Petersen
3a2647b7d3
glibc: Don't build CRT objects that won't be used. 2024-11-03 09:29:33 +01:00
Alex Rønne Petersen
4c70aea460
Compilation: Use the regular module mechanism for setting PIC on CRT objects.
addCCArgs() will then pass the appropriate flag to Clang.
2024-11-03 09:29:33 +01:00
Alex Rønne Petersen
39abcc303c
Compilation: Pass -fno-PIC to clang if PIC is disabled.
Let's not implicitly rely on whatever Clang's default is.
2024-11-03 09:29:33 +01:00
Alex Rønne Petersen
c9e67e71c1
std.Target: Replace isARM() with isArmOrThumb() and rename it to isArm().
The old isARM() function was a portability trap. With the name it had, it seemed
like the obviously correct function to use, but it didn't include Thumb. In the
vast majority of cases where someone wants to ask "is the target Arm?", Thumb
*should* be included.

There are exactly 3 cases in the codebase where we do actually need to exclude
Thumb, although one of those is in Aro and mirrors a check in Clang that is
itself likely a bug. These rare cases can just add an extra isThumb() check.
2024-11-03 09:29:30 +01:00
Alex Rønne Petersen
4e843b4e2b
llvm: Remove extraneous commas for branch hint metadata in textual IR output. 2024-11-02 11:06:33 +01:00
Alex Rønne Petersen
e27b4647d8
Merge pull request #21617 from alexrp/target-dyld-stuff
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
Improve the `DynamicLinker` API and fix `detectAbiAndDynamicLinker()` for non-Linux/Hurd ELF hosts
2024-11-02 10:29:41 +01:00
Alex Rønne Petersen
8abbdb56a4
Merge pull request #21729 from alexrp/target-cpu-baseline
`std.Target.Cpu.Model`: Further refinements to `generic()` and `baseline()`
2024-11-02 10:27:03 +01:00
Alex Rønne Petersen
fccf15fc9f std.Target: Remove armv7k/armv7s.
Like d1d95294fd, this is more Apple nonsense where
they abused the arch component of the triple to encode what's really an ABI.

Handling this correctly in Zig's target triple model would take quite a bit of
work. Fortunately, the last Armv7-based Apple Watch was released in 2017 and
these targets are now considered legacy. By the time Zig hits 1.0, they will be
a distant memory. So just remove them.
2024-11-02 10:25:40 +01:00
Alex Rønne Petersen
ab89af3d39
Merge pull request #21860 from alexrp/llvm-triple-stuff
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
More support for OS/libc version ranges in `std.Target` and improvements to LLVM target triple construction
2024-11-02 02:00:25 +01:00
Andrew Kelley
aaf54ce6a7 link.File.Wasm.Archive: simplify
Don't use the reader interface
Avoid unnecessary heap allocations

At first I started working on incorporating the Archive fields into the
Wasm data model, however, I realized a better strategy: simply omit
Archive data from the serialized linker state. Those files can be
trivially reparsed on next compiler process start. If they haven't
changed, great. Otherwise if they have, the prelink phase needs to be
restarted anyway.
2024-11-01 14:41:56 -07:00
Andrew Kelley
d30e287543
Merge pull request #21874 from ziglang/wasm-linker
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
link.File.Wasm: unify the string tables
2024-11-01 02:16:36 -07:00
Brook Jeynes
a99449d8be
std.c: Added utsname struct definition for .macos (#21873) 2024-11-01 07:57:00 +00:00
Alex Rønne Petersen
3c1ccbdf39
std.Target: Add support for specifying Android API level. 2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
c5395f7cd9
llvm: Set OS min version and libc version in ~all cases.
Except Windows, because that just doesn't really fit into LLVM's target triple
format currently.
2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
60c0f522d9
llvm: Set vendor type in LLVM target triple for more OSs.
Annoyingly, LLVM and Clang have various checks throughout that depend on these
vendor types being set.
2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
f89982bf53
std.Target: Add semver min/max versions for a bunch of OSs. 2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
ed68083d8f
std.Target: Update known OS max versions. 2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
ace26004a3
std.Target: Remove arch-specific handling for macos in Os.VersionRange.default().
The minimum is now the same for both aarch64 and x86_64.
2024-11-01 06:23:59 +01:00
Alex Rønne Petersen
af48ce6379
std.Target: Sort some OS switches according to the Os enum. 2024-11-01 06:23:59 +01:00
Andrew Kelley
e501cf51a0 link.File.Wasm: unify the string tables
Before, the wasm struct had a string table, the ZigObject had a string
table, and each Object had a string table.

Now there is just the one. This makes for more efficient use of memory
and simplifies logic, particularly with regards to linker state
serialization.

This commit additionally adds significantly more integer type safety.
2024-10-31 22:01:10 -07:00
Andrew Kelley
bf9978a57a link.File.Wasm: conform to naming conventions 2024-10-31 22:01:10 -07:00
Andrew Kelley
2b868bb6dd link.File.Wasm.Archive: remove header field
it's not needed
2024-10-31 22:01:10 -07:00
Robin Voetter
ba5f57616f
Merge pull request #21861 from alichraghi/master
spirv: push constants and small fixes
2024-11-01 03:44:37 +01:00
Matthew Lugg
3f7fac5fff
Merge pull request #21817 from mlugg/no-anon-structs
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
compiler: remove anonymous struct types, unify all tuples
2024-11-01 01:43:08 +00:00
Ali Cheraghi
38345d5909
std.gpu: add instanceIndex 2024-11-01 02:04:27 +03:30
Ali Cheraghi
c07b3c8279
spirv: decorate arrays stride 2024-11-01 02:04:27 +03:30
Ali Cheraghi
a1cb9563f6
spirv: Uniform/PushConstant variables
- Rename GPU address spaces to match with SPIR-V spec.
- Emit `Block` Decoration for Uniform/PushConstant variables.
- Don't emit `OpTypeForwardPointer` for non-opencl targets.
  (there's still a false-positive about recursive structs)

Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
2024-11-01 02:03:33 +03:30
mlugg
24babde746
std.mem.asBytes: fix footgun when passing non-single pointer
I was just bitten by this footgun, where I actually wanted
`sliceAsBytes` but unintentionally used `asBytes`, which in practice
ignored all but the first element. Just add a comptime assertion to
trigger a compile error in this case.
2024-10-31 20:42:53 +00:00
mlugg
d11bbde5f9
compiler: remove anonymous struct types, unify all tuples
This commit reworks how anonymous struct literals and tuples work.

Previously, an untyped anonymous struct literal
(e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type",
which is a special kind of struct which coerces using structural
equivalence. This mechanism was a holdover from before we used
RLS / result types as the primary mechanism of type inference. This
commit changes the language so that the type assigned here is a "normal"
struct type. It uses a form of equivalence based on the AST node and the
type's structure, much like a reified (`@Type`) type.

Additionally, tuples have been simplified. The distinction between
"simple" and "complex" tuple types is eliminated. All tuples, even those
explicitly declared using `struct { ... }` syntax, use structural
equivalence, and do not undergo staged type resolution. Tuples are very
restricted: they cannot have non-`auto` layouts, cannot have aligned
fields, and cannot have default values with the exception of `comptime`
fields. Tuples currently do not have optimized layout, but this can be
changed in the future.

This change simplifies the language, and fixes some problematic
coercions through pointers which led to unintuitive behavior.

Resolves: #16865
2024-10-31 20:42:53 +00:00
Archit Gupta
a916bc7fdd std.fs.File: Fix metadata error check on Linux
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
On Linux, File.metadata calls the statx syscall directly. As such, the
return value is the error code. Previously, it handled the error with
`posix.errno`, which when libc is linked, treats the return value as a
value set to -1 if there is an error with the error code in errno. If
libc wasn't linked, it would be handled correctly.

In the Linux with libc linked case, this would cause the error result to
always be treated as success (err val != -1), even when an error
occurred.
2024-10-31 14:02:42 +01:00
Andrew Kelley
f2dcfe0e40 link.File.Wasm: parse inputs in compilation pipeline
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
Primarily, this moves linker input parsing from flush() into the linker
task queue, which is executed simultaneously with the frontend.

I also made it avoid redundantly opening the same archive file N times
for each object file inside. Furthermore, hard code fixed buffer stream
rather than using a generic stream type.

Finally, I fixed the error handling of the Wasm.Archive.parse function.
Please pay attention to this pattern of returning a struct rather than
accepting a mutable struct as an argument. This ensures function-level
atomicity and makes resource management straightforward.

Deletes the file and path fields from Archive and Object.

Removed a well-meaning but ultimately misguided suggestion about how to
think about ZigObject since thinking about it that way has led to
problematic anti-DOD patterns.
2024-10-30 23:43:53 -07:00
Andrew Kelley
f5ade5e207
Merge pull request #21862 from alexrp/llvm-19-api-break
Reduce our exposure to LLVM API breakage
2024-10-30 22:46:40 -07:00
Andrew Kelley
ba2d006634 link.File.Wasm: remove the "files" abstraction
Removes the `files` field from the Wasm linker, storing the ZigObject
as its own field instead using a tagged union.

This removes a layer of indirection when accessing the ZigObject, and
untangles logic so that we can introduce a "pre-link" phase that
prepares the linker state to handle only incremental updates to the
ZigObject and then minimize logic inside flush().

Furthermore, don't make array elements store their own indexes, that's
always a waste.

Flattens some of the file system hierarchy and unifies variable names
for easier refactoring.

Introduces type safety for optional object indexes.
2024-10-30 19:34:58 -07:00
Alex Rønne Petersen
16b87f7082
link: Fix archive format selection for some OSs.
* AIX has its own bespoke format.
* Handle all Apple platforms.
* FreeBSD and OpenBSD both use the GNU format in LLVM.
* Windows has since been switched to the COFF format by default in LLVM.
2024-10-31 01:33:49 +01:00
Alex Rønne Petersen
33715cb28f
mingw: Fix COFF machine type selection for thumb-windows-gnu import libraries. 2024-10-31 01:31:44 +01:00
Alex Rønne Petersen
f1f804e532
zig_llvm: Reduce our exposure to LLVM API breakage.
LLVM recently introduced new Triple::ArchType members in 19.1.3 which broke our
static assertions in zig_llvm.cpp. When implementing a fix for that, I realized
that we don't even need a lot of the stuff we have in zig_llvm.(cpp,h) anymore.
This commit trims the interface down considerably.
2024-10-31 01:27:22 +01:00
Simon Ekström
17a87d7341
std.fmt: Fix compile error in Parser.peek() (#20532)
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
2024-10-30 07:45:23 +00:00
Roman Frołow
c39ba682e3 typo: will inlined -> will be inlined
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
2024-10-29 17:52:55 -07:00
Jakub Konka
6ff267dc26 link/Elf: ensure we always sort all relocations by r_offset in -r mode
According to a comment in mold, this is the expected (and desired)
condition by the linkers, except for some architectures (RISCV and
Loongarch) where this condition does not have to upheld.

If you follow the changes in this patch and in particular doc comments
I have linked the comment/code in mold that explains and implements
this.

I have also modified `testEhFrameRelocatable` test to now test both
cases such that `zig ld -r a.o b.o -o c.o` and `zig ld -r b.o a.o -o
d.o`. In both cases, `c.o` and `d.o` should produce valid object
files which was not the case before this patch.
2024-10-29 17:27:42 -07:00
Mario Nachbaur
4661705a0e
std.debug: watchOS: fixes for ilp32 ABI (#21765)
Xcode requires target arm64_32 (aarch64-watchos-ilp32) in order to
build code for Apple Watches. This commit fixes compilation errors
that appear when compiling with that target.
2024-10-29 22:12:57 +01:00
Robin Voetter
3450809e3d
Merge pull request #21826 from Snektron/spirv-vulkan
spirv: vulkan setup
2024-10-29 19:58:51 +01:00
Andrew Kelley
7025c06eb6 CLI: don't warn on missing host-detected directories
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
2024-10-29 09:27:38 -07:00
Julian Noble
a03ab9ee01
std.os.windows.WriteFile: Map ERROR_NO_DATA to error.BrokenPipe instead of ERROR_BROKEN_PIPE (#21811)
It appears that ReadFile returns ERROR_BROKEN_PIPE for a broken pipe, but WriteFile returns ERROR_NO_DATA.

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2024-10-29 15:10:19 +01:00
Alex Rønne Petersen
b5cafe223a Revert "cmake: Add a ZIG2_NO_RTLIB option for building zig2 without compiler-rt."
This reverts commit 3dd6456c0f.

We didn't end up using this after all.
2024-10-29 06:48:47 +01:00
JonathanHallstrom
5ce17ecfa7 remove unnecessary cast 2024-10-29 01:48:13 +01:00
Robin Voetter
ae57f6fd07
dwarf: flush wip_nav after emitting anyerror type info
This caused a missing reference for u16 to not be emitted. Triggered
after removing something from start.zig which transitively added u16
to the module.
2024-10-28 20:39:37 +01:00
Alex Rønne Petersen
d22049a987
Merge pull request #21693 from alexrp/wasm2c-endian
`wasm2c`: Add big endian support.
2024-10-28 17:52:10 +01:00
Bruno Franca dos Reis
cdd8e82f0a
closes #21824 (#21832) 2024-10-28 14:54:02 +00:00
Alex Rønne Petersen
4c336705b9
Merge pull request #21807 from Rexicon226/riscv-interupt
implement new interrupt calling conventions in the llvm backend
2024-10-28 13:51:11 +01:00