| Age | Commit message (Collapse) | Author |
|
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 for d5233ee85ce13cba3dd03e4c0c938cee193b9b19.
|
|
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.
|
|
stage1 is available behind the -fstage1 flag.
closes #89
|
|
This is one of the final remaining TODOs for the LLVM backend.
|
|
|
|
Shared libraries can be provided on the command line as if they were
objects, as a path to the ".so" file. The "each-lib-rpath" functionality
was ignoring these shared libraries accidentally, causing missing rpaths
in the output executable.
|
|
* 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
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
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`.
|
|
elf+macho: use explicit alignment on Decl if specified
|
|
|
|
|
|
closes #3047
|
|
Warnings about non-implemented `-z nocopyreloc` are common when
compiling go code (including Go's tests themselves). Let's just
make it stop complaining.
|
|
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.
This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
|
|
Instead, just return ChildProcess directly. This structure does not
require a stable address, so we can put it on the stack just fine. If
someone wants it on the heap they should do.
const proc = try allocator.create(ChildProcess);
proc.* = ChildProcess.init(args, allocator);
|
|
Rather than allocating Decl objects with an Allocator, we instead allocate
them with a SegmentedList. This provides four advantages:
* Stable memory so that one thread can access a Decl object while another
thread allocates additional Decl objects from this list.
* It allows us to use u32 indexes to reference Decl objects rather than
pointers, saving memory in Type, Value, and dependency sets.
* Using integers to reference Decl objects rather than pointers makes
serialization trivial.
* It provides a unique integer to be used for anonymous symbol names,
avoiding multi-threaded contention on an atomic counter.
|
|
This gives us insight as to what is happening when we are waiting for
things such as LLVM emit object and LLD linking.
|
|
|
|
elf: support `--strip` option and set symtab size when writing globals
|
|
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly
doing element casting for slice element types. This required an
enhancement both to stage1 and stage2.
* stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that
abused this is fixed.
* Make some parameters comptime to support functions in switch
expressions (as opposed to making them function pointers).
* Avoid relying on local temporaries being mutable.
* Workarounds for when stage1 and stage2 disagree on function pointer
types.
* Workaround recursive formatting bug with a `@panic("TODO")`.
* Remove unreachable `else` prongs for some inferred error sets.
All in effort towards #89.
|
|
|
|
Without this, it may happen we write the globals without extending
the symtab section header's size. This can potentially lead to
clobbering some data in the file, or simply omitting the globals
from the symtab when displaying with support tooling such as `readelf`.
|
|
When the user passes `--strip` option on the command line, we do
not emit any debug info by skipping initializing the internal `Dwarf`
module.
|
|
Fixes #11353
The renderer treats comments and doc comments differently since doc
comments are parsed into the Ast. This commit adds a check after getting
the text for the doc comment and trims whitespace at the end before
rendering.
The `a = 0,` in the test is here to avoid a ParseError while parsing the
test.
|
|
|
|
Avoids many pitfalls connected with premature/early return in case
there are errors with Decl, etc. This is effectively bringing back
the old design however in a much nicer packaging, where every
mechanism related to tracking Decl's debug info is now nicely
wrapped in a single struct (aka the `DeclState`). This includes
relocation table, type arena, etc. It is now the caller's
responsibility to deinit the state (so that no memory is leaked)
after `Decl` has been analysed (or errored out). The caller here
is typically a linker such as `Elf` or `MachO`.
|
|
The init()/commit() API of this field leads to the type of bug that this
commit fixes by defering an uncomfortably complex expression. I didn't
bother doing the equivalent fix in link/MachO.zig because instead I
think the `decl_state` field should be entirely removed from Dwarf.
|
|
|
|
|
|
|
|
|
|
This reverts commit 8e7b1a74ac4568a2b806026f210ae59e52d2768d.
Sorry, I should have put up a PR and ran that one by Jakub and done some
more inspection.
This causes problems with gdb:
BFD: /home/andy/dev/zig/build-release/test: invalid string offset 3254779904 >= 153524 for section `.shstrtab'
|
|
This makes Valgrind happier because it results in the program headers
being sorted by VirtAddr in the ELF file.
|
|
Hook up Elf and MachO linkers to the new solution.
|
|
|
|
This requires generating an addend for the target relocation as
the field pointer might point at a field inner to the container.
|
|
|
|
|
|
|
|
In `getDeclVAddr`, it may happen that the target `Decl` has not
been allocated space in virtual memory. In this case, we store a
relocation in the linker-global table which we will iterate over
when flushing the module, and fill in any missing address in the
final binary. Note that for optimisation, if the address was resolved
at the time of a call to `getDeclVAddr`, we skip relocating this
atom.
This commit also adds the glue code for lowering const slices in
the ARM backend.
|