aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2020-12-28stage2: better error message for root zig source file not foundAndrew Kelley
closes #6777 closes #6893
2020-12-28stage2: add extern functionsAndrew Kelley
and improve the C backend enough to support Hello World (almost)
2020-12-28stage2: add initial impl of LLVM backend in self-hosted compilerTimon Kruiper
2020-12-28Revert "stage2: add compile log statement (#7191)"Andrew Kelley
The addition of `addDeclErr` introduced a memory leak at every call site, and I also would like to push back on having more than 1 compilation error per `Decl`. This reverts commit 1634d45f1d53c8d7bfefa56ab4d2fa4cc8218b6d.
2020-12-26stage2: add compile log statement (#7191)g-w1
2020-12-24stage2: re-use compiler runtime libs across opt modes and strip flagAndrew Kelley
Previously Zig would need to recompile runtime libs if you changed the values of --strip or -O. Now, unless the `debug_compiler_runtime_libs` flag is set (which is currently not exposed to the CLI), Zig will always choose ReleaseFast or ReleaseSmall for compiler runtime libraries. When the main application chooses ReleaseFast or ReleaseSmall, that value is propagated to compiler runtime libraries. Otherwise a decision is made based on the target, which is currently ReleaseSmall for freestanding WebAssembly and ReleaseFast for everything else. Ultimately the purpose of this commit is to have Debug and ReleaseSafe builds of applications still get optimized builds of, e.g. libcxx and libunwind, as well as to spend less time unnecessarily rebuilding compiler runtime libraries.
2020-12-24stage2: tsan forces linking libcAndrew Kelley
2020-12-24zig cc: support both ubsan and tsan at the same timeAndrew Kelley
2020-12-24stage2: fix Cache deadlock and build more of TSANAndrew Kelley
* rename is_compiler_rt_or_libc to skip_linker_dependencies and set it to `true` for all sub-Compilations. I believe this resolves the deadlock we were experiencing on Drone CI and on some users' computers. I will remove the CI workaround in a follow-up commit. * enabling TSAN automatically causes the Compilation to link against libc++ even if not requested, because TSAN depends on libc++. * add -fno-rtti flags where appropriate when building TSAN objects. Thanks Firefox317 for pointing this out. * TSAN support: resolve all the undefined symbols. We are still seeing a dependency on __gcc_personality_v0 but will resolve this one in a follow-up commit. * static libs do not try to build libc++ or libc++abi.
2020-12-24WIP start adding support for TSANAndrew Kelley
2020-12-23rework std.ResetEvent, improve std lib Darwin integrationAndrew Kelley
* split std.ResetEvent into: - ResetEvent - requires init() at runtime and it can fail. Also requires deinit(). - StaticResetEvent - can be statically initialized and requires no deinitialization. Initialization cannot fail. * the POSIX sem_t implementation can in fact fail on initialization because it is allowed to be implemented as a file descriptor. * Completely define, clarify, and explain in detail the semantics of these APIs. Remove the `isSet` function. * `ResetEvent.timedWait` returns an enum instead of a possible error. * `ResetEvent.init` takes a pointer to the ResetEvent instead of returning a copy. * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch, which is exposed by libSystem. stage2 changes: * ThreadPool: use a single, pre-initialized `ResetEvent` per worker. * WaitGroup: now requires init() and deinit() and init() can fail. - Add a `reset` function. - Compilation initializes one for the work queue in creation and re-uses it for every update. - Rename `stop` to `finish`. - Simplify the implementation based on the usage pattern.
2020-12-23Add emit_h path to compilation hash.Alex Cameron
2020-12-23Fix memory leakNoam Preil
2020-12-23Remove redundant emit_h member in Compilation struct.Alex Cameron
2020-12-23Implement emit-hAlex Cameron
2020-12-20add an option to compile zig in single-threaded modeAndrew Kelley
And enable it for Drone CI. I hate to do this, but I need to make progress on other fronts.
2020-12-20std.Progress: make the API thread-safeAndrew Kelley
We generally get away with atomic primitives, however a lock is required around the refresh function since it traverses the Node graph, and we need to be sure no references to Nodes remain after end() is called.
2020-12-20use kprotty's ThreadPool implementation (v5)Andrew Kelley
2020-12-20stage2: protect mutable state from data races in updateCObjectAndrew Kelley
2020-12-18std: introduce a thread-local CSPRNG for general useAndrew Kelley
std.crypto.random * cross platform, even freestanding * can't fail. on initialization for some systems requires calling os.getrandom(), in which case there are rare but theoretically possible errors. The code panics in these cases, however the application may choose to override the default seed function and then handle the failure another way. * thread-safe * supports the full Random interface * cryptographically secure * no syscall required to initialize on Linux (AT_RANDOM) * calls arc4random on systems that support it `std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`. I moved some of the Random implementations into their own files in the interest of organization. stage2 no longer requires passing a RNG; instead it uses this API. Closes #6704
2020-12-16stage2: add test_evented_io to cache hashAndrew Kelley
2020-12-13stage2: link musl dynamically by default if nativeIsaac Freund
If targeting the native OS and the system libc is musl, link against it dynamically by default.
2020-12-13stage2: support dynamically linking musl libcIsaac Freund
2020-12-11stage2: proper file extension strippingAndrew Kelley
Previously it used mem.split on "." and took the first iterated item. Now it uses fs.path.extension and strips off that number of bytes. Closes #7404
2020-12-11fix deadlock with build-exe on an object for windowsAndrew Kelley
The steps to repro this issue are: zig build-obj hello.zig -target x86_64-windows-msvc zig build-exe hello.obj -target x86_64-windows-msvc --subsystem console -lkernel32 -lntdll What was happening is that the main Compilation added a work item to produce kernel32.lib. Then it added a sub-Compilation to build zig's libc, which ended up calling a function with extern "kernel32", which caused the sub-Compilation to also try to produce kernel32.lib. The main Compilation and sub-Compilation do not coordinate about the set of import libraries that they will be trying to build, so this caused a deadlock. This commit solves the problem by disabling the extern "foo" feature from working when building compiler_rt or libc. Zig's linker code is now responsible for putting the appropriate import libs on the linker line, if any for compiler_rt and libc. Related: #5825
2020-12-11stage2: detect redundant C/C++ source filesAndrew Kelley
Cache exposes BinDigest. Compilation gains a set of a BinDigest for every C/C++ source file. We detect when the same source/flags have already been added and emit a compile error. This prevents a deadlock in the caching system. Closes #7308
2020-12-08stage2: link: properly implement passthrough mode for LLD child procAndrew Kelley
passthrough mode does not mean always exit - it just means to pass through stdio and exit if the child process exits, without doing any special error reporting.
2020-12-08always use codeview (pdb) when object_format is PE/COFFAndrew Kelley
Previously, when mixing Zig and C/C++ code for windows-gnu targets, zig would get codeview format but the C/C++ code would not get any debug info. Now, C/C++ code properly emits debug info in codeview format and everything just works.
2020-12-04stage2: introduce Module.failed_root_source_fileAndrew Kelley
Use case: zig build-exe non_existent_file.zig Previous behavior: error.FileNotFound, followed by an error return trace Behavior after this commit: error: unable to read non_existent_file.zig: FileNotFound (end of stderr, exit code 1) This turns AllErrors.Message into a tagged union which now has the capability to represent both "plain" errors as well as source-based errors (with file, line, column, byte offset). The "no entry point found" error has moved to be a plain error message.
2020-12-04Version-gate appending -syslibroot flag to lldJakub Konka
This commit version-gates appending `-syslibroot` flag to lld. This is predicated upon the fact that for versions of macOS lower than 11, lld would fail to find and link against frameworks with this flag specified. Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-03add `@cImport` files to Compilation cache manifestAndrew Kelley
closes #7007
2020-12-01stage2: Create cache manifest before calling finalLemonBoy
If we enter the `if` because `comp.disable_c_depfile` is false the `man` object has no manifest and calling .final on it will trip an assertion. Closes #7096
2020-12-01stage2: add -femit-foo=bar args to the cache hashAndrew Kelley
Closes #6979 Closes #7036
2020-12-01Add package names and paths to the zig root module cache hash.Alexandros Naskos
Add package names to the stage1 cache hash and package files to the stage1 manifest file.
2020-12-01Make sure to include the root_name in the cache.Timon Kruiper
This fixes a bug where the caching system did not notice when the --name flag changed.
2020-11-30restore -target wasm32-freestanding-musl for C headersAndrew Kelley
See #5854 Some tiny tweaks too: * Use `wasm-freestanding-musl` instead of `wasm32-freestanding-musl`, making it pointer-size-agnostic. * Fix trying to build non-existent wasm musl start files.
2020-11-30stage2: fix not detecting all dynamic librariesAndrew Kelley
Positional shared library arguments were not being detected as causing dynamic linking, resulting in invalid linker lines. LLD did not have an error message for this when targeting x86_64-linux but it did emit an error message when targeting aarch64-linux, which is how I noticed the problem. This surfaced an error having to do with fifo.pipe() in the cat example which I did not diagnose but solved the issue by doing the revamp that was already overdue for that example. It appears that the zig-window project was exploiting the previous behavior for it to function properly, so this prompts the question, is there some kind of static/dynamic executable hybrid that the compiler should recognize? Unclear - but we can discuss that in #7240.
2020-11-30fix regression on wasm targetsAndrew Kelley
The previous commit broke wasm targets because the linking step would look for the compiler-rt lib in the wrong place. Fixed in this commit.
2020-11-30rework the bundle compiler-rt featureAndrew Kelley
* it is now -fcompiler-rt and -fno-compiler-rt to override the (quite reasonable) default of bundling compiler-rt only for executables and dynamic libraries. - the build.zig API is still called bundle_compiler_rt however it is now an optional bool instead of a bool. leaving it as `null` means to use the compiler default. * renamed some internal identifiers to make the source more readable * additionally support -fcompiler-rt when doing build-obj for ELF files since that target already supports linking multiple objects into one. - includes an error message when attempting this for non-ELF. in the future this could additionally be supported with a more advanced implementation that does not rely on the linker. * properly populate the linker cache hash
2020-11-30Added bundle-compiler-rt flagAlexandros Naskos
2020-11-27stage2 elf: refactor override_soname to sonameJakub Konka
2020-11-22modernize the PIE patch for the latest master branchAndrew Kelley
This is the part of #3960 that has to be rewritten to apply to latest master branch code.
2020-11-10add missing -m<os>-version-min CLI args to clangAndrew Kelley
This fixes some code generation issues when targeting macOS and compiling C/C++ code.
2020-11-08macOS: depend on bundled headers even for nativeAndrew Kelley
This is an alternate fix for #6773. Reverts 872bc787b56f71e53c80f4681523bc8356915b71.
2020-11-06Address review commentsJakub Konka
2020-11-06Rely on ZIG_SYSTEM_LINKER_HACK instead of input flagsJakub Konka
2020-11-05Re-enable system linker hackJakub Konka
It is now possible to force linking with system linker `ld` instead of the LLVM `lld` linker when building natively on the target. This can be done at each stage by specifying `--system-linker-hack` flag, and can be useful on platforms where `lld` fails to operate properly such as macOS 11 Big Sur on ARM64 where every binary/dylib is expected to be codesigned. Some example invocations for each stage of compilation of Zig toolchain: ``` cmake .. -DCMAKE_PREFIX_PATH=/path/to/llvm -DSYSTEM_LINKER_HACK=1 ``` ``` build/zig build test --system-linker-hack ``` ``` build/zig build --prefix $(pwd)/stage2 -Denable-llvm --system-linker-hack ``` ``` build/zig build-exe hello.zig --system-linker-hack ```
2020-11-02Add std.Target.current.isDarwin() to exclude non-macs in comptimeJakub Konka
2020-11-02Update src/Compilation.zigJakub Konka
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-11-02Refactor the code according to Andrew's suggestionsJakub Konka