aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
AgeCommit message (Collapse)Author
2022-09-08std.zig.system.NativeTargetInfo: detection ignores self exeAndrew Kelley
Before, native glibc and dynamic linker detection attempted to use the executable's own binary if it was dynamically linked to answer both the C ABI question and the dynamic linker question. However, this could be problematic on a system that uses a RUNPATH for the compiler binary, locking it to an older glibc version, while system binaries such as /usr/bin/env use a newer glibc version. The problem is that libc.so.6 glibc version will match that of the system while the dynamic linker will match that of the compiler binary. Executables with these versions mismatching will fail to run. Therefore, this commit changes the logic to be the same regardless of whether the compiler binary is dynamically or statically linked. It inspects `/usr/bin/env` as an ELF file to find the answer to these questions, or if there is a shebang line, then it chases the referenced file recursively. If that does not provide the answer, then the function falls back to defaults. This commit also solves a TODO to remove an Allocator parameter to the detect() function.
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-09-02stage2: fix panic when the dependency is missingriChar
2022-08-29make 'zig build' respect ZIG_LIB_DIRAndrew Kelley
follow-up to 56bdd0127f806da8b617eb82be444a4624aa5685
2022-08-29implement cache environment variables for `zig build`Meghan
2022-08-19make self-hosted the default compilerAndrew Kelley
stage1 is available behind the -fstage1 flag. closes #89
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-11std: add missing error to windows.WriteFileAndrew Kelley
I encountered this error today when testing the self-hosted compiler on Windows.
2022-08-10add ZIG_GLOBAL_CACHE_DIR env varAndrew Kelley
2022-08-08cc: add support for -M flagJakub Konka
2022-07-29Merge pull request #12085 from topolarity/dyn-link-libcppAndrew Kelley
Dynamically link `libc++` if integrating with system LLVM
2022-07-28Add check to verify libc++ is shared by LLVM/ClangCody Tapscott
This check is needed because if static/dynamic linking is mixed incorrectly, it's possible for Clang and LLVM to end up with duplicate "copies" of libc++. This is not benign: Static variables are not shared, so equality comparisons that depend on pointers to static variables will fail. One such failure is std::generic_category(), which causes POSIX error codes to compare as unequal when passed between LLVM and Clang. I believe this is the cause of https://github.com/ziglang/zig/issues/11168 In order to avoid affecting build times when Zig is repeatedly invoked, we only enable this check for "zig env" and "zig version"
2022-07-28CLI: add error for duplicate packageVeikka Tuominen
2022-07-27std.fmt: add more invalid format string errorsr00ster91
2022-07-26std.fmt: require specifier for unwrapping ?T and E!TInKryption
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-22cli: support --gc-sections and --no-gc-sections for Zig sourcesJakub Konka
2022-07-22cli: parse -dead_strip MachO linker flagJakub Konka
2022-07-16Merge pull request #12121 from Vexu/spanVeikka Tuominen
Stage2 point to error location using spans
2022-07-16Merge pull request #12060 from Vexu/IterableDirVeikka Tuominen
std.fs: split `Dir` into `IterableDir`
2022-07-15zig cc: support `-Wl,--export=<symbol>`Luuk de Gram
2022-07-15Compilation: point caret in error message at the main tokenVeikka Tuominen
2022-07-15std.fs: split `Dir` into `IterableDir`Veikka Tuominen
Also adds safety check for attempting to iterate directory not opened with `iterate = true`.
2022-07-14stage2: point to error location using spansVeikka Tuominen
2022-07-12stage2: handle parser notes in a more general wayVeikka Tuominen
2022-07-12parser: add helpful error for C style container declarationsVeikka Tuominen
```zig // a.zig struct Foo { a: u32, }; ``` before: ``` a.zig:1:1: error: expected test, comptime, var decl, or container field, found 'struct' struct Foo { ^ ``` after: ``` a.zig:1:8: error: 'struct Foo' is invalid struct Foo { ^ a.zig:1:8: note: to declare a container do 'const Foo = struct' struct Foo { ^ ```
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-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-05CLI: add support for -fno-builtinAndrew Kelley
2022-07-01LLD: the driver functions now return "false" to mean "error"Andrew Kelley
2022-07-01stage1: update to LLVM 14 APIAndrew Kelley
2022-06-29clang: add Zig equivalent for -headerpad_max_install_names cli flagJakub Konka
2022-06-28clang: update cmdline options to include weak libs and frameworksJakub Konka
Clang accepts `-weak-lx`, `-weak_library x` and `-weak_framework x`.
2022-06-28macho: discriminate between normal and weak dylibsJakub Konka
Parse `-weak-lx` and `-weak_framework x` in the CLI.
2022-06-28cli: typo `--needed_library` should be `-needed_library` on macosJakub Konka
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-24cli: let the linker resolve libs into dynamic and staticJakub Konka
Unlike targeting ELF-based OSes such as Linux, resolving system libs on Darwin should follow one of two strategies: `-search_paths_first` or `-search_dylibs_first` and hence we defer always forcing linking a static library to the linker.
2022-06-24macho: implement -search_dylibs_first linker optionJakub Konka
2022-06-24zld: ignore -search_paths_firstMotiejus Jakštys
Ignore MachO-specific flag -search_paths_first, since it is the default in zld and ld64. Also see Jakub's comment[1]: Changing topic slightly, @motiejus dunno if you noticed, with this change building arm64 Zig binary fails on macos - it complains about unknown -search_paths_first flag. This one is an easy fix: we should ignore it since this is the default behaviour in both ld64 and zld. [1]: https://github.com/ziglang/zig/pull/11906#issuecomment-1163545849
2022-06-20macho: -pagezero_size is always in hexJakub Konka
This matches the behavior of other linkers out there including `ld64` and `lld`.
2022-06-20macho: round down pagezero size to page sizeJakub Konka
If page aligned requested pagezero size is 0, skip generating __PAGEZERO segment. Add misc improvements to the pipeline, and correctly transfer the requested __PAGEZERO size to the linker.
2022-06-20[MachO] add -pagezero_sizeMotiejus Jakštys
Pass `-pagezero_size` to the MachO linker. This is the final "unsupported linker arg" that I could chase that CGo uses. After this and #11874 we may be able to fail on an "unsupported linker arg" instead of emiting a warning. Test case: zig=/code/zig/build/zig CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="$zig cc -target x86_64-macos" CXX="$zig c++ -target x86_64-macos" go build -a -ldflags "-s -w" cgo.go I compiled a trivial CGo program and executed it on an amd64 Darwin host. To be honest, I am not entirely sure what this is doing. This feels right after reading what this argument does in LLVM sources, but I am by no means qualified to make MachO pull requests. Will take feedback.
2022-06-16[elf] understand -no-pieMotiejus Jakštys
This passes -Wl,-no-pie linker arg. Golang uses that. From the `ld(1)` man page: Create a position dependent executable. This is the default. Not adding to the help text, because this is the default.
2022-06-09linker: remove `-z noexecstack` optionIsaac Freund
Note that the current documentation for the `-z noexecstack` is incorrect. This indicates that an object *does not* require an executable stack. This is actually the default of LLD, and there has never been a way to override this default by passing `-z execstack` to LLD. This commit removes the redundant `-z noexecstack` option from zig build-exe/build-lib/build-obj and ignores the option if passed to zig cc for compatibility. As far as I can tell, there is no reason for code to require an executable stack. This option only exists because the stack was originally executable by default and some programs came to depend on that behavior. Instead, mprotect(2) may be used to make memory pages executable.
2022-06-08linker: Enable full RELRO by defaultIsaac Freund
Full RELRO is a hardening feature that makes it impossible to perform certian attacks involving overwriting parts of the Global Offset Table to invoke arbitrary code. It requires all symbols to be resolved before execution of the program starts which may have an impact on startup time. However most if not all popular Linux distributions enable full RELRO by default for all binaries and this does not seem to make a noticeable difference in practice. "Partial RELRO" is equivalent to `-z relro -z lazy`. "Full RELRO" is equivalent to `-z relro -z now`. LLD defaults to `-z relro -z lazy`, which means Zig's current `-z relro` option has no effect on LLD's behavior. The changes made by this commit are as follows: - Document that `-z relro` is the default and add `-z norelro`. - Pass `-z now` to LLD by default to enable full RELRO by default. - Add `-z lazy` to disable passing `-z now`.