aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2022-09-11Compilation: handle system C compiler not foundAndrew Kelley
When linking libc and compiling natively, Zig tries to integrate with the system C compiler. However, this caused Zig to fail when no system C compiler is installed, despite the fact that Zig is perfectly capable of compiling & linking libc without one. This commit makes Zig fall back to using its own ability to provide libc in the case that no C compiler is installed. For glibc, it means sometimes getting the warning "zig cannot build new glibc version abc, providing instead xyz". Ideally, Zig would do some more validation about the system libraries being linked against, and report an error in case it could not provide the exact correct libc version of the system libraries (or that the system libraries themselves conflict with each other), however, I think it is fair to call that a separate enhancement.
2022-09-11stage2: no condition on system libs to link native libcAndrew Kelley
Before, Zig tried to use its own libc files (e.g. glibc) when there were no system libs being linked. This prevented building against native glibc on systems that have newer glibc than the ones Zig provides. Closes #12797
2022-09-08[ld] add --print-* for diagnosticsMotiejus Jakštys
This adds the following for passthrough to lld: - `--print-gc-sections` - `--print-icf-sections` - `--print-map` I am not adding these to the cache manifest, since it does not change the produced artifacts. Tested with an example from #11398: it successfully prints the resulting map and the GC'd sections.
2022-08-30avoid exposing supportsTailCall in the standard libraryAndrew Kelley
This is problematic because in practice it depends on whether the compiler backend supports it too, as evidenced by the TODO comment about LLVM not supporting some architectures that in fact do support tail calls. Instead this logic is organized strategically in src/target.zig, part of the internal compiler source code, and the behavior tests in question duplicate some logic for deciding whether to proceed with the test. The proper place to expose this flag is in `@import("builtin")` - the generated source file - so that third party compilers can advertise whether they support tail calls.
2022-08-30coff: set some defaults for PE headersJakub Konka
2022-08-29link: add force_undefined_symbols to cache hashAndrew Kelley
Follow-up for d5233ee85ce13cba3dd03e4c0c938cee193b9b19.
2022-08-25add ability to pass force undefined symbols to the linkerJakub Konka
This commit enables `-u <symbol>` for ELF and `-include:<symbol>` for COFF linkers for use internally. This means we do not expose these flags to the users just yet, however, we make use of them internally whenever required. One such use case is forcing inclusion of `_tls_index` when linking for Windows with mingw and LTO and dead code stripping enabled. This ensures we add `_tls_index` to the symbol resolver as an undefined symbol and force the linker to include an atom that provides it marking it a dead-code-stripping root - meaning it will not be garbage collected by the linker no matter what.
2022-08-25fix order of CLI args passed to clangAndrew Kelley
Commit eb3f7d2f37cab1d3df7c4493b8239e802b83e521 changed the order of CLI args passed to clang, making object-specific "extra flags" passed first. However, these are supposed to be able to override other flags, and this behavior is exploited by workarounds in mingw.zig to disable LTO. This commit rectifies the situation by moving extra flags back to being passed after the call to addCCArgs().
2022-08-24Compilation: move comptime condition firstAndrew Kelley
Avoids compile error on Windows due to not having execv capabilities. Fixup for eb3f7d2f37cab1d3df7c4493b8239e802b83e521. See #6768
2022-08-24compilation: avoid pointless cachingLoris Cro
When the entire purpose of this compilation is to perform a single zig cc operation we could "tail call" clang by doing an execve, and any use of the caching system would actually be problematic since the user is presumably doing their own caching by using dep file flags. Fixes #12317
2022-08-23make LLVM and Clang emit DWARF 4 instead of 5Andrew Kelley
This reverts 6d679eb2bcbe76e389c02e0bb4d4c4feb2847783 and additionally changes the command line parameters passed to Clang to match. Clang 14 defaults to DWARFv5 which is an interesting choice. v5 has been out for 5 years and yet Valgrind does not support it, and apparently neither does either GDB or LLD, I haven't determined which, but I wasn't able to use GDB to debug my LLVM-emitted dwarf 5 zig code that was linked with LLD. A couple years ago when I was working on the self-hosted ELF linker, I emitted DWARFv5 but then downgraded to v4 when I realized that third party tools were stuck in the past. Years later, they still are. Hopefully, Clang 14's bold move will inspire third party tools to get their shit together, however, in the meantime, everything's broken, so we're passing `-gdwarf-4` to clang and instructing LLVM to emit DWARFv4. Note that Zig's std.debug code *does* support DWARFv5 already as of a previous commit that I made today.
2022-08-19LLVM: add DLL export attributeAndrew Kelley
This was present in stage1 but missing from self-hosted.
2022-08-19make self-hosted the default compilerAndrew Kelley
stage1 is available behind the -fstage1 flag. closes #89
2022-08-19build: remove the option to omit stage2Andrew Kelley
2022-08-19stage2: implement stack protectorsAndrew Kelley
This is one of the final remaining TODOs for the LLVM backend.
2022-08-18std.Target gains ObjectFormat fieldAndrew Kelley
2022-08-10better default for use_stage1 when -ofmt=c is providedAndrew Kelley
2022-08-07remove 'builtin.stage2_arch', Sema is smart enough nowMeghan Denny
2022-07-28stage2: ensure 'std', 'builtin', and 'root' is always available to `@import`Meghan
2022-07-26std.fmt: require specifier for unwrapping ?T and E!TInKryption
2022-07-25std.mem: add `first` method to `SplitIterator` and `SplitBackwardsIterator`r00ster
2022-07-24Revert "std.fmt: require specifier for unwrapping ?T and E!T."Andrew Kelley
This reverts commit 7cbd586ace46a8e8cebab660ebca3cfc049305d9. This is causing a fail to build from source: ``` ./lib/std/fmt.zig:492:17: error: cannot format optional without a specifier (i.e. {?} or {any}) @compileError("cannot format optional without a specifier (i.e. {?} or {any})"); ^ ./src/link/MachO/Atom.zig:544:26: note: called from here log.debug(" RELA({s}) @ {x} => %{d} in object({d})", .{ ^ ``` I looked at the code to fix it but none of those args are optionals.
2022-07-24std.fmt: require specifier for unwrapping ?T and E!T.InKryption
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-19delete the stage1 implementation of autodocAndrew Kelley
2022-07-19Autodoc: skip docs when compile errors occurAndrew Kelley
2022-07-19autodocs: add support for indirect decl referencesLoris Cro
2022-07-19autodoc: init workLoris Cro
2022-07-16Merge pull request #12121 from Vexu/spanVeikka Tuominen
Stage2 point to error location using spans
2022-07-16style: add missing commar00ster91
This is really minor but the issue this fixes is that if you copy-paste this output of `--show-builtin` into your `build.zig` for example then the formatter will format ``` pub const os = std.Target.Os{ .tag = .freestanding, .version_range = .{ .none = {} } }; ``` to ``` pub const os = std.Target.Os{ .tag = .freestanding, .version_range = .{ .none = {} } }; ``` which doesn't match the output. With this comma, the output will stay the way it is after a `zig fmt`.
2022-07-15Compilation: point caret in error message at the main tokenVeikka Tuominen
2022-07-14stage2: point to error location using spansVeikka Tuominen
2022-07-11Merge pull request #12044 from Vexu/stage2-compile-errorsAndrew Kelley
Sema: add detailed error notes to `coerceInMemoryAllowed`
2022-07-11Merge pull request #11863 from motiejus/compress-debug-sectionsAndrew Kelley
ELF: understand --compress-debug-sections
2022-07-11stage2: cleanups to --compress-debug-sectionsAndrew Kelley
* make the setting in the linker backend be non-optional; by this time all defaults are supposed to be resolved. * integrate with `zig cc` * change the CLI parsing to match C compiler parsing, allowing `--compress-debug-sections` alone to choose a default encoding of zlib.
2022-07-12Compilation: indent multiline error messages properlyr00ster91
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-11ELF: understand -Wl,--compress-debug-sectionsMotiejus Jakštys
This argument is both a compiler and a linker flag. The linker flag was not understood; now it is. Go likes to use it as a linker flag. Tested with sqlite3. The size difference is significant, and I confirmed gdb understands both binaries. zlib: 3.66MB ------------ CC="zig cc" CFLAGS="-Wl,--compress-debug-sections=zlib -O2" ./configure --disable-tcl make FILE SIZE VM SIZE -------------- -------------- 39.1% 1.43Mi 88.4% 1.43Mi .text 19.6% 734Ki 0.0% 0 .debug_info 16.4% 613Ki 0.0% 0 .debug_loc 13.1% 492Ki 0.0% 0 .debug_line 4.2% 157Ki 9.5% 157Ki .rodata 2.3% 87.6Ki 0.0% 0 .debug_ranges 1.5% 56.2Ki 0.0% 0 .symtab 1.1% 40.2Ki 0.0% 0 .strtab 1.0% 38.2Ki 0.0% 0 .debug_str 0.7% 26.2Ki 0.0% 0 .debug_frame 0.4% 15.3Ki 0.9% 15.3Ki .data 0.1% 4.71Ki 0.3% 4.71Ki .dynsym 0.1% 3.65Ki 0.2% 3.26Ki [16 Others] 0.1% 2.55Ki 0.2% 2.55Ki .rela.plt 0.1% 2.12Ki 0.0% 0 [ELF Section Headers] 0.0% 0 0.1% 2.02Ki .bss 0.0% 1.84Ki 0.1% 1.84Ki .dynstr 0.0% 1.72Ki 0.1% 1.72Ki .plt 0.0% 1.58Ki 0.1% 1.58Ki .hash 0.0% 1.17Ki 0.0% 0 .debug_abbrev 0.0% 1.01Ki 0.1% 1.01Ki .rela.dyn 100.0% 3.66Mi 100.0% 1.62Mi TOTAL none: 8.56MB ------------ CC="zig cc" CFLAGS="-O2" ./configure --disable-tcl make FILE SIZE VM SIZE -------------- -------------- 41.1% 3.52Mi 0.0% 0 .debug_loc 18.5% 1.59Mi 0.0% 0 .debug_info 16.7% 1.43Mi 88.4% 1.43Mi .text 11.8% 1.01Mi 0.0% 0 .debug_line 5.9% 515Ki 0.0% 0 .debug_ranges 1.8% 157Ki 9.5% 157Ki .rodata 1.3% 118Ki 0.0% 0 .debug_frame 1.3% 110Ki 0.0% 0 .debug_str 0.6% 56.2Ki 0.0% 0 .symtab 0.5% 40.2Ki 0.0% 0 .strtab 0.2% 15.3Ki 0.9% 15.3Ki .data 0.1% 4.71Ki 0.3% 4.71Ki .dynsym 0.0% 3.64Ki 0.2% 3.26Ki [16 Others] 0.0% 2.98Ki 0.0% 0 .debug_abbrev 0.0% 2.55Ki 0.2% 2.55Ki .rela.plt 0.0% 2.12Ki 0.0% 0 [ELF Section Headers] 0.0% 0 0.1% 2.02Ki .bss 0.0% 1.84Ki 0.1% 1.84Ki .dynstr 0.0% 1.72Ki 0.1% 1.72Ki .plt 0.0% 1.58Ki 0.1% 1.58Ki .hash 0.0% 1.01Ki 0.1% 1.01Ki .rela.dyn 100.0% 8.56Mi 100.0% 1.62Mi TOTAL
2022-07-11Compilation: do not repeat AstGen error source line for notesVeikka Tuominen
2022-07-10Compilation: do not repeat same source line for notesVeikka Tuominen
2022-07-05stage2: propagate use_stage1 to sub-compilationAndrew Kelley
This makes it so that -fno-stage1 also affects compiler-rt for example.
2022-07-05CLI: add support for -fno-builtinAndrew Kelley
2022-07-04stage2: ELF: improve error reporting when libc is missingAndrew Kelley
Future improvement: make plain error notes actually render as notes rather than errors, but keep them as errors for the case of sub-compilation errors, e.g. when compiler-rt has compilation errors.
2022-06-30stage2: object format affects whether LLVM can be usedAndrew Kelley
2022-06-28Pass -O0 rather than -Og to Clang for Debug buildsKen Micklas
2022-06-27macho: implement and handle `-needed-*` and `-needed_*` family of flagsJakub Konka
MachO linker now handles `-needed-l<name>`, `-needed_library=<name>` and `-needed_framework=<name>`. While on macOS `-l` is equivalent to `-needed-l`, and `-framework` to `-needed_framework`, it can be used to the same effect as on Linux if combined with `-dead_strip_dylibs`. This commit also adds handling for `-needed_library` which is macOS specific flag only (in addition to `-needed-l`). Finally, in order to leverage new linker testing harness, this commit added ability to specify lowering to those flags via `build.zig`: `linkSystemLibraryNeeded` (and related), and `linkFrameworkNeeded`.
2022-06-27macho: implement -dead_strip_dylibs linker flagJakub Konka
2022-06-25macho: implement -headerpad_max_install_namesJakub Konka
2022-06-25macho: implement -headerpad_size optionJakub Konka
Includes both traditiona and incremental codepaths with one caveat that in incremental case, the requested size cannot be smaller than the default padding size due to prealloc required due to incremental nature of linking. Also parse `-headerpad_max_install_names`, however, not actionable just yet - missing implementation.
2022-06-25cache setting macho search strategy flagsJakub Konka
2022-06-24macho: implement -search_dylibs_first linker optionJakub Konka
2022-06-24link:clarification & enable MachO getGlobalSymbolLuuk de Gram
This adds clarification to the getGlobalSymbol doc comments, as well as renames the `addExternFn` function for MachO to `getGlobalSymbol`. This function will now be called from 'src/link.zig' as well. Finally, this also enables compiling zig's libc using LLVM even though the `fno-LLVM` flag is given.