aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2025-03-08Compilation: Fix `-fno-rtlib-defaultlib` unused argument warning in ReleaseSafe.Alex Rønne Petersen
Closes #23138.
2025-03-08zig cc: Don't pass -mabi for assembly files when targeting arm.Alex Rønne Petersen
Clang's integrated Arm assembler doesn't understand -mabi yet, so this results in "unused command line argument" warnings when building musl code and glibc stubs, for example.
2025-03-02link: make sure MachO closes the damn filesmlugg
Windows is a ridiculous operating system designed by toddlers, and so requires us to close all file handles in the `tmp/xxxxxxx` cache dir before renaming it into `o/xxxxxxx`. We have a hack in place to handle this for the main output file, but the MachO linker also outputs a file with debug symbols, and we weren't closing it! This led to a fuckton of CI failures when we enabled `.whole` cache mode by default for self-hosted backends. thanks jacob for figuring this out while i sat there
2025-02-28Revert "Merge pull request #22898 from kristoff-it/deprecated-proposal"Andrew Kelley
This reverts commit dea72d15da4fba909dc3ccb2e9dc5286372ac023, reversing changes made to ab381933c87bcc744058d25a876cfdc0d23fc674. The changeset does not work as advertised and does not have sufficient test coverage. Reopens #22822
2025-02-27Move the compiler's LLVM bitcode builder to std.zig.llvm.Alex Rønne Petersen
2025-02-26initial implementation of `@deprecated`Loris Cro
2025-02-26Compilation: disable ubsan_rt for spirv targetAli Cheraghi
2025-02-25ubsan: don't create ubsan in every static lib by defaultAndrew Kelley
Problem here is if zig is asked to create multiple static libraries, it will build the runtime multiple times and then they will conflict. Instead we want to build the runtime exactly once.
2025-02-25correct some bugsDavid Rubin
2025-02-25Compilation: correct when to include ubsanDavid Rubin
2025-02-25Compilation: always import ubsan if a ZCU existsDavid Rubin
Unlike `compiler-rt`, `ubsan` uses the standard library quite a lot. Using a similar approach to how `compiler-rt` is handled today, where it's compiled into its own object and then linked would be sub-optimal as we'd be introducing a lot of code bloat. This approach always "imports" `ubsan` if the ZCU, if it exists. If it doesn't such as the case where we're compiling only C code, then we have no choice other than to compile it down to an object and link. There's still a tiny optimization we can do in that case, which is when compiling to a static library, there's no need to construct an archive with a single object. We'd only go back and parse out ubsan from the archive later in the pipeline. So we compile it to an object instead and link that to the static library. TLDR; - `zig build-exe foo.c` -> build `libubsan.a` and links - `zig build-obj foo.c` -> doesn't build anything, just emits references to ubsan runtime - `zig build-lib foo.c -static` -> build `ubsan.o` and link it - `zig build-exe foo.zig bar.c` -> import `ubsan-rt` into the ZCU - `zig build-obj foo.zig bar.c` -> import `ubsan-rt` into the ZCU - `zig build-lib foo.zig bar.c` -> import `ubsan-rt` into the ZCU
2025-02-25move libubsan to `lib/` and integrate it into `-fubsan-rt`David Rubin
2025-02-25Compilation: use the minimal runtime in `ReleaseSafe`David Rubin
2025-02-25ubsan: add a basic runtimeDavid Rubin
2025-02-22link.MachO: Add support for the -x flag (discard local symbols).Alex Rønne Petersen
This can also be extended to ELF later as it means roughly the same thing there. This addresses the main issue in #21721 but as I don't have a macOS machine to do further testing on, I can't confirm whether zig cc is able to pass the entire cgo test suite after this commit. It can, however, cross-compile a basic program that uses cgo to x86_64-macos-none which previously failed due to lack of -x support. Unlike previously, the resulting symbol table does not contain local symbols (such as C static functions). I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty
2025-02-21fix `-fsanitize-coverage-trace-pc-guard` and fuzzer support for C compile unitsXavier Bouchoux
- allow `-fsanitize-coverage-trace-pc-guard` to be used on its own without enabling the fuzzer. (note that previouly, while the flag was only active when fuzzing, the fuzzer itself doesn't use it, and the code will not link as is.) - add stub functions in the fuzzer to link with instrumented C code (previously fuzzed tests failed to link if they were calling into C): while the zig compile unit uses a custom `EmitOptions.Coverage` with features disabled, the C code is built calling into the clang driver with "-fsanitize=fuzzer-no-link" that automatically enables the default features. (see https://github.com/llvm/llvm-project/blob/de06978ebcff5f75913067b019d2d522d0be0872/clang/lib/Driver/SanitizerArgs.cpp#L587) - emit `-fsanitize-coverage=trace-pc-guard` instead of `-Xclang -fsanitize-coverage-trace-pc-guard` so that edge coverrage is enabled by clang driver. (previously, it was enabled only because the fuzzer was)
2025-02-17std.Target: Remove functions that just wrap component functions.Alex Rønne Petersen
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
2025-02-11Compilation: disable error return tracing in rt libsAndrew Kelley
2025-02-10std.ArrayList: popOrNull() -> pop() [v2] (#22720)Meghan Denny
2025-02-06Merge pull request #22777 from mlugg/some-bugsMatthew Lugg
Fix a bunch of frontend bugs
2025-02-06Merge pull request #19614 from jedisct1/wasi-libc-updateAlex Rønne Petersen
Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5
2025-02-05incremental: fix crash when introducing syntax errormlugg
Clearing the analysis roots was very clever and all, but not actually valid. We need to avoid *any* reference to the analysis errors if there were any fatal files, and that includes sorting the errors! Resolves: #22774
2025-02-04compiler: integrate importing ZON with incremental compilationmlugg
The changes from a few commits earlier, where semantic analysis no longer occurs if any Zig files failed to lower to ZIR, mean `file` dependencies are no longer necessary! However, we now need them for ZON files, to be invalidated whenever a ZON file changes.
2025-02-04compiler: integrate ZON with the ZIR caching systemmlugg
This came with a big cleanup to `Zcu.PerThread.updateFile` (formerly `astGenFile`). Also, change how the cache manifest works for files in the import table. Instead of being added to the manifest when we call `semaFile` on them, we iterate the import table after running the AstGen workers and add all the files to the cache manifest then. The downside is that this is a bit more eager to include files in the manifest; in particular, files which are imported but not actually referenced are now included in analysis. So, for instance, modifying any standard library file will invalidate all Zig compilations using that standard library, even if they don't use that file. The original motivation here was simply that the old logic in `semaFile` didn't translate nicely to ZON. However, it turns out to actually be necessary for correctness. Because `@import("foo.zig")` is an AstGen-level error if `foo.zig` does not exist, we need to invalidate the cache when an imported but unreferenced file is removed to make sure this error is triggered when it needs to be. Resolves: #22746
2025-02-04compiler: a few renamesmlugg
This is mainly in preparation for integrating ZonGen into the pipeline properly, although these names are better because `astGenFile` isn't *necessarily* running AstGen; it may determine that the current ZIR is up-to-date, or load cached ZIR.
2025-02-04compiler: don't perform semantic analysis if there are files without ZIRmlugg
2025-02-04Zcu: remove `*_loaded` fields on `File`mlugg
Instead, `source`, `tree`, and `zir` should all be optional. This is precisely what we're actually trying to model here; and `File` isn't optimized for memory consumption or serializability anyway, so it's fine to use a couple of extra bytes on actual optionals here.
2025-02-03compiler,std: implement ZON supportMason Remaley
This commit allows using ZON (Zig Object Notation) in a few ways. * `@import` can be used to load ZON at comptime and convert it to a normal Zig value. In this case, `@import` must have a result type. * `std.zon.parse` can be used to parse ZON at runtime, akin to the parsing logic in `std.json`. * `std.zon.stringify` can be used to convert arbitrary data structures to ZON at runtime, again akin to `std.json`.
2025-01-29Add libdl shims from wasi-libcFrank Denis
2025-01-27frontend: use main Compilation code_model when building libxxAndrew Kelley
as well as libtsan, libunwind, and libc files
2025-01-26Merge pull request #22602 from mlugg/incr-embedfileMatthew Lugg
incremental: handle `@embedFile`
2025-01-25Compilation: Remove the _tls_index hack for MinGW.Alex Rønne Petersen
No longer needed since we disable LTO for mingw32.
2025-01-25compiler: Rework LTO settings for some Zig-provided libraries.Alex Rønne Petersen
* compiler-rt and mingw32 have both run into LLD bugs, and LLVM disables LTO for its compiler-rt, so disable LTO for these. * While we haven't run into any bugs in it, LLVM disables LTO for its libtsan, so follow suit just to be safe. * Allow LTO for libfuzzer as LLVM does.
2025-01-25incremental: handle `@embedFile`mlugg
Uses of `@embedFile` register dependencies on the corresponding `Zcu.EmbedFile`. At the start of every update, we iterate all embedded files and update them if necessary, and invalidate the dependencies if they changed. In order to properly integrate with the lazy analysis model, failed embed files are now reported by the `AnalUnit` which actually used `@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`. An incremental test is added covering incremental updates to embedded files, and I have verified locally that dependency invalidation is working correctly.
2025-01-24Compilation pipeline: repeat failed prelink tasksAndrew Kelley
and remove faulty assertion. When a prelink task fails, the completed_prelink_tasks counter will not decrement. A future improvement will be needed to make the pipeline fully robust and handle failed prelink tasks, followed by updates in which those tasks succeed, and compilation proceeds like normal. Currently if a prelink task fails, the Compilation will be left in a state unrecoverable by an incremental update.
2025-01-23compiler: Fix computation of Compilation.Config.any_unwind_tables.Alex Rønne Petersen
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-22std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.Alex Rønne Petersen
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-20embrace the future slightly lessAndrew Kelley
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-20reject crti.o/crtn.o, embrace the futureAndrew Kelley
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-20Compilation: take advantage of `@splat`Andrew Kelley
2025-01-20Compilation pipeline: linker input producing Job representationAndrew Kelley
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-20compilation pipeline: do glibc jobs earlierAndrew Kelley
2025-01-20Compilation pipeline: do musl jobs earlierAndrew Kelley
This means doing more work in parallel which is already good, but it's also a correctnes fix because we need link_task_wait_group.wait() to ensure that no more linker inputs will be generated.
2025-01-16x86_64: rewriteJacob Young
2025-01-15Compilation: windows doesn't prelink yetAndrew Kelley
2025-01-15wasm linker: implement hidden visibilityAndrew Kelley
2025-01-15Compilation.saveState implement saving wasm linker stateAndrew Kelley
2025-01-15frontend: don't increment remaining_prelink_tasks for windows implibsAndrew Kelley
yet because they aren't hooked up to the new linker API
2025-01-15wasm object parsing: fix handling of weak functions and globalsAndrew Kelley
2025-01-15wasm linker: improve error messages by making source locations more lazyAndrew Kelley