aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2024-12-15zig cc: Remove broken CUDA C/C++ support.Alex Rønne Petersen
2024-12-14Compilation: Clean up addCCArgs().Alex Rønne Petersen
The goal of this commit is to get rid of some "unused command line argument" warnings that Clang would give for various file types previously. This cleanup also has the side effect of making the order of flags more understandable, especially as it pertains to include paths. Since a lot of code was shuffled around in this commit, I recommend reviewing the old and new versions of the function side-by-side rather than trying to make sense of the diff.
2024-12-13Compilation: Use Clang dependency file for preprocessed assembly files.Alex Rønne Petersen
2024-12-13Compilation: Use a better canonical file extension for header files.Alex Rønne Petersen
2024-12-13Compilation: Override Clang's language type for header files.Alex Rønne Petersen
Clang seems to treat them as linker input without this.
2024-12-13Compilation: Improve classification of various C/C++/Objective-C files.Alex Rønne Petersen
2024-12-13Merge pull request #22035 from alexrp/unwind-fixesAlex Rønne Petersen
Better unwind table support + unwind protection in `_start()` and `clone()`
2024-12-11std.Build.Cache.hit: work around macOS kernel bugAndrew Kelley
The previous commit cast doubt upon the initial report about macOS kernel behavior, identifying another reason that ENOENT could be returned from file creation. However, it is demonstrable that ENOENT can be returned for both cases: 1. create file race 2. handle refers to deleted directory This commit re-introduces the workaround for the file creation race on macOS however it does not unconditionally retry - it first tries again with O_EXCL to disambiguate the error condition that has occurred.
2024-12-10std.Build.Cache.hit: more discipline in error handlingAndrew Kelley
Previous commits 2b0929929d67e222ca6a9523a3a594ed456c4a51 4ea2f441df36cec61e1017f4d795d4037326c98c had this text: > There are no dir components, so you would think that this was > unreachable, however we have observed on macOS two processes racing to > do openat() with O_CREAT manifest in ENOENT. This appears to have been a misunderstanding based on the issue report #12138 and corresponding PR #12139 in which the steps to reproduce removed the cache directory in a loop which also executed detached Zig compiler processes. There is no evidence for the macOS kernel bug however the ENOENT is easily explained by the removal of the cache directory. This commit reverts those commits, ultimately reporting the ENOENT as an error rather than repeating the create file operation. However this commit also adds an explicit error set to `std.Build.Cache.hit` as well as changing the `failed_file_index` to a proper diagnostic field that fully communicates what failed, leading to more informative error messages on failure to check the cache. The equivalent failure when occuring for AstGen performs a fatal process kill, reasoning being that the compiler has an invariant of the cache directory not being yanked out from underneath it while executing. This could be made a more granular error in the future but I suspect such thing is not valuable to pursue. Related to #18340 but does not solve it.
2024-12-11compiler: Improve the handling of unwind table levels.Alex Rønne Petersen
The goal here is to support both levels of unwind tables (sync and async) in zig cc and zig build. Previously, the LLVM backend always used async tables while zig cc was partially influenced by whatever was Clang's default.
2024-12-10fix unknown file extension with rmetaTravis Lange
2024-12-09Merge pull request #22157 from mlugg/astgen-error-lazyAndrew Kelley
compiler: allow semantic analysis of files with AstGen errors
2024-12-08Compilation: Don't rely on Clang defaults for options that are user-facing.Alex Rønne Petersen
2024-12-05compiler: incremental compilation fixesmlugg
The previous commit exposed some bugs in incremental compilation. This commit fixes those, and adds a little more logging for debugging incremental compilation. Also, allow `ast-check -t` to dump ZIR when there are non-fatal AstGen errors.
2024-12-05Compilation: Consider *.rlib files to be static libraries.Alex Rønne Petersen
These are produced by rustc: https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html#rlib
2024-11-28Merge pull request #22067 from alexrp/pie-testsAlex Rønne Petersen
Add PIC/PIE tests and fix some bugs + some improvements to the test harness
2024-11-26diversify "unable to spawn" failure messagesAndrew Kelley
to help understand where a spurious failure is occurring
2024-11-24std.Target: Add Os.HurdVersionRange for Os.Tag.hurd.Alex Rønne Petersen
This is necessary since isGnuLibC() is true for hurd, so we need to be able to represent a glibc version for it. Also add an Os.TaggedVersionRange.gnuLibCVersion() convenience function.
2024-11-23Compilation: Consider *.lo files to be object files.Alex Rønne Petersen
Fixes musl libc.so compilation with zig cc.
2024-11-13Compilation: Pass -municode on to Clang.Alex Rønne Petersen
This is supposed to define the UNICODE macro; it's not just a linker option. Closes #21978.
2024-11-05musl: Pass -fomit-frame-pointer via CrtFileOptions.Alex Rønne Petersen
2024-11-05musl: Pass -f(function,data)-sections via CrtFileOptions instead of CFLAGS.Alex Rønne Petersen
2024-11-05Compilation: Fix unwind table logic for compiler-rt.Alex Rønne Petersen
This looks to be a refactoring leftover.
2024-11-05Compilation: Also set essential module options when including compiler-rt.o.Alex Rønne Petersen
Closes #21831.
2024-11-05Compilation: Move no_builtin to Package.Module.Alex Rønne Petersen
This option, by its very nature, needs to be attached to a module. If it isn't, the code in a module could break at random when compiled into an application that doesn't have this option set. After this change, skip_linker_dependencies no longer implies no_builtin in the LLVM backend.
2024-11-03glibc: Don't build CRT objects that won't be used.Alex Rønne Petersen
2024-11-03Compilation: Use the regular module mechanism for setting PIC on CRT objects.Alex Rønne Petersen
addCCArgs() will then pass the appropriate flag to Clang.
2024-11-03Compilation: Pass -fno-PIC to clang if PIC is disabled.Alex Rønne Petersen
Let's not implicitly rely on whatever Clang's default is.
2024-11-02Merge pull request #21729 from alexrp/target-cpu-baselineAlex Rønne Petersen
`std.Target.Cpu.Model`: Further refinements to `generic()` and `baseline()`
2024-10-31compiler: remove anonymous struct types, unify all tuplesmlugg
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-26Compilation: Omit Clang CPU model flags for some targets.Alex Rønne Petersen
2024-10-24remove leak from linkerDavid Rubin
2024-10-23avoid unnecessarily building Scrt1.o when cross-compiling glibcAndrew Kelley
which, in this branch causes a miscompilation because it would get sent to the linker.
2024-10-23combine codegen work queue and linker task queueAndrew Kelley
these tasks have some shared data dependencies so they cannot be done simultaneously. Future work should untangle these data dependencies so that more can be done in parallel. for now this commit ensures correctness by making linker input parsing and codegen tasks part of the same queue.
2024-10-23work on compiler_rt and fuzzer libs earlier in the pipelineAndrew Kelley
don't wait for AstGen and C source files to complete before starting to build compiler_rt and libfuzzer
2024-10-23Compilation.create: skip libc_installation on darwinAndrew Kelley
If the "is darwin" check is moved below the libc_installation check below, error.LibCInstallationMissingCrtDir is returned from lci.resolveCrtPaths(). This should be revisited because it makes sense to check libc_installation first even on darwin. Anyway for now this more closely matches logic from master branch.
2024-10-23use deterministic order in relocatable-eh-frame testsAndrew Kelley
This test does not pass in master branch either if you flip the object order around.
2024-10-23also find static libc files on the hostAndrew Kelley
and don't look for glibc files on windows
2024-10-23add missing check for output mode in tsan logicAndrew Kelley
2024-10-23don't create unused musl crt objectsAndrew Kelley
2024-10-23branch fixesAndrew Kelley
2024-10-23move linker input file parsing to the compilation pipelineAndrew Kelley
2024-10-23refactor Compilation.crtFilePathAndrew Kelley
2024-10-23rework linker inputsAndrew Kelley
* Compilation.objects changes to Compilation.link_inputs which stores objects, archives, windows resources, shared objects, and strings intended to be put directly into the dynamic section. Order is now preserved between all of these kinds of linker inputs. If it is determined the order does not matter for a particular kind of linker input, that item should be moved to a different array. * rename system_libs to windows_libs * untangle library lookup from CLI types * when doing library lookup, instead of using access syscalls, go ahead and open the files and keep the handles around for passing to the cache system and the linker. * during library lookup and cache file hashing, use positioned reads to avoid affecting the file seek position. * library directories are opened in the CLI and converted to Directory objects, warnings emitted for those that cannot be opened.
2024-10-23move ld script processing to the frontendAndrew Kelley
along with the relevant logic, making the libraries within subject to the same search criteria as all the other libraries. this unfortunately means doing file system access on all .so files when targeting ELF to determine if they are linker scripts, however, I have a plan to address this.
2024-10-16std.Target: Rename OS version range functions to drop the "get" prefix.Alex Rønne Petersen
2024-10-16incremental: introduce `file` dependencies to handle AstGen failuresmlugg
The re-analysis here is a little coarse; it'd be nice in the future to have a way for an AstGen failure to preserve *all* analysis which depends on the last success, and just hide the compile errors which depend on it somehow. But I'm not sure how we'd achieve that, so this works fine for now. Resolves: #21223
2024-10-16Zcu: cache output of `resolveReferences` between callsmlugg
This not only simplifies the error bundling logic, but also improves efficiency by allowing the result to be cached between, for instance, multiple calls to `totalErrorCount`.
2024-10-12link.Elf: eliminate an O(N^2) algorithm in flush()Andrew Kelley
Make shared_objects a StringArrayHashMap so that deduping does not need to happen in flush. That deduping code also was using an O(N^2) algorithm, which is not allowed in this codebase. There is another violation of this rule in resolveSymbols but this commit does not address it. This required reworking shared object parsing, breaking it into independent components so that we could access soname earlier. Shared object parsing had a few problems that I noticed and fixed in this commit: * Many instances of incorrect use of align(1). * `shnum * @sizeOf(elf.Elf64_Shdr)` can overflow based on user data. * `@divExact` can cause illegal behavior based on user data. * Strange versyms logic that wasn't present in mold nor lld. The logic was not commented and there is no git blame information in ziglang/zig nor kubkon/zld. I changed it to match mold and lld instead. * Use of ArrayList for slices of memory that are never resized. * finding DT_VERDEFNUM in a different loop than finding DT_SONAME. Ultimately I think we should follow mold's lead and ignore this integer, relying on null termination instead. * Doing logic based on VER_FLG_BASE rather than ignoring it like mold and LLD do. No comment explaining why the behavior is different. * Mutating the original ELF symbols rather than only storing the mangled name on the new Symbol struct. I noticed something that I didn't try to address in this commit: Symbol stores a lot of redundant information that is already present in the ELF symbols. I suspect that the codebase could benefit from reworking Symbol to not store redundant information. Additionally: * Add some type safety to std.elf. * Eliminate 1-3 file system reads for determining the kind of input files, by taking advantage of file name extension and handling error codes properly. * Move more error handling methods to link.Diags and make them infallible and thread-safe * Make the data dependencies obvious in the parameters of parseSharedObject. It's now clear that the first two steps (Header and Parsed) can be done during the main Compilation pipeline, rather than waiting for flush().
2024-10-11link: consolidate diagnosticsAndrew Kelley
By organizing linker diagnostics into this struct, it becomes possible to share more code between linker backends, and more importantly it becomes possible to pass only the Diag struct to some functions, rather than passing the entire linker state object in. This makes data dependencies more obvious, making it easier to rearrange code and to multithread. Also fix MachO code abusing an atomic variable. Not only was it using the wrong atomic operation, it is unnecessary additional state since the state is already being protected by a mutex.