| Age | Commit message (Collapse) | Author |
|
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.
|
|
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.
|
|
|
|
follow-up to 56bdd0127f806da8b617eb82be444a4624aa5685
|
|
|
|
stage1 is available behind the -fstage1 flag.
closes #89
|
|
This is one of the final remaining TODOs for the LLVM backend.
|
|
|
|
I encountered this error today when testing the self-hosted compiler on
Windows.
|
|
|
|
|
|
Dynamically link `libc++` if integrating with system LLVM
|
|
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"
|
|
|
|
|
|
|
|
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.
|
|
Co-authored-by: Veikka Tuominen <git@vexu.eu>
|
|
|
|
|
|
Stage2 point to error location using spans
|
|
std.fs: split `Dir` into `IterableDir`
|
|
|
|
|
|
Also adds safety check for attempting to iterate directory not opened with `iterate = true`.
|
|
|
|
|
|
```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 {
^
```
|
|
* 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.
|
|
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
|
|
|
|
|
|
|
|
|
|
Clang accepts `-weak-lx`, `-weak_library x` and `-weak_framework x`.
|
|
Parse `-weak-lx` and `-weak_framework x` in the CLI.
|
|
|
|
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`.
|
|
|
|
|
|
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.
|
|
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.
|
|
|
|
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
|
|
This matches the behavior of other linkers out there including
`ld64` and `lld`.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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`.
|