132 Commits

Author SHA1 Message Date
Vexu
7e30e83900
small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Andrew Kelley
7dd4afb224 stage2: link: properly implement passthrough mode for LLD child proc
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-08 22:37:01 -07:00
Andrew Kelley
72f6c6e634 invoke LLD as a child process rather than a library
Closes #3825
2020-12-08 20:00:16 -07:00
Andrew Kelley
a482b82e2d stage2: only patch up LLD binaries on aarch64-macos
The code is a bit fragile so it was causing CI failures on x86_64-macos.
Also the patch up code is only needed for aarch64-macos, so we were
doing unnecessary work.
2020-12-08 12:47:48 -07:00
Jakub Konka
b390ced356 macho: specify -install_name as full dylib's name
This then allows for proper resolution of names via runpath search
path list, i.e., `-rpath @loader_path` will correctly resolve
to `@rpath/libxxx.dylib (...)` in the linked binary.
2020-12-04 12:23:49 -08:00
Jakub Konka
c4853ba7ea Version-gate appending -syslibroot flag to lld
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-04 11:37:55 -08:00
Andrew Kelley
ecf7dfcd3a
Merge pull request #7273 from kubkon/lld-codesig-poc
lld+macho: patch lld output on Apple Silicon by calculating and embedding adhoc code signature
2020-12-03 13:41:31 -08:00
Jakub Konka
d3be499270 lld+macho: address review comments 2020-12-03 21:57:26 +01:00
Andrew Kelley
5b6cbd2e7c stage2: don't pass -l arguments when building .a or .o files
See #7094
2020-12-02 20:17:51 -07:00
Jakub Konka
5cba16c707 macho:use mem.asBytes and meta.eql in commands.zig
This commit addresses comments suggesting a cleaner approach
at converting an `extern` struct to its byte representation using
`mem.asBytes`, and to use `meta.eql` in place of more fragile
`mem.eql(u8, ...)` for comparison of two `extern` structs.

Thanks LemonBoy!
2020-12-02 18:40:31 +01:00
Jakub Konka
0fba2f7175 lld: fix using incorrect path for the final artefact 2020-12-02 11:21:52 +01:00
Jakub Konka
3e2d1ccaad lld+macho: rename final artefact in main.zig 2020-12-02 00:03:07 +01:00
Jakub Konka
b58a2a4de6 lld+macho: move parsing logic into MachO 2020-12-01 23:39:07 +01:00
Jakub Konka
ed18046518 macho: dynamically calculate code signature padding 2020-12-01 18:03:31 +01:00
Jakub Konka
abb697e751 macho: unify code signature between stage1 and stage2 2020-12-01 18:03:04 +01:00
Jakub Konka
1f7fb560ab lld: use commands.LoadCommand in self-hosted linker 2020-12-01 10:49:31 +01:00
Jakub Konka
de66b65677 lld: start unifying load command logic 2020-12-01 10:49:31 +01:00
Jakub Konka
0ef3071db6 lld: copy+rename to please the kernel 2020-12-01 10:49:31 +01:00
Jakub Konka
c25b3593e7 lld: add code signature to lld output 2020-12-01 10:49:31 +01:00
Jakub Konka
545721ccd1 lld: add code signature padding 2020-12-01 10:49:31 +01:00
Jakub Konka
e8ffae60a2 lld: parse output lld file 2020-12-01 10:49:31 +01:00
Andrew Kelley
8c9919ec7b fix regression on wasm targets
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-30 17:46:10 -07:00
Andrew Kelley
ff9798eb26 rework the bundle compiler-rt feature
* 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-30 16:35:00 -07:00
Andrew Kelley
c3b0182f31 restore sonames by default when using zig cli
Before this commit, the branch regressed this case:

zig build-lib foo.zig -dynamic
readelf -d libfoo.so
 x000000000000000e (SONAME) Library soname: [libfoo.so]

Now it works again, but it preserves the property that using `zig cc`
has the SONAME off by default to match C compilers.
2020-11-27 17:49:55 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00
Jakub Konka
12efefeba5 stage2 elf: make -soname an opt-in and not opt-out
As discussed with LemonBoy, it makes more sense to have the `-soname`
an opt-in option rather than opt-out, which is especially true if
we are to align `zig cc` with `cc` to a greater degree.
2020-11-27 15:42:39 -07:00
Jakub Konka
5ed76268c9 stage2 macho: apply more review comments 2020-11-27 20:55:34 +01:00
Jakub Konka
64eae8f392 stage2 macho: move PIE fixups to link file; fix tests 2020-11-26 11:50:09 +01:00
Jakub Konka
c749b78df5 stage2 macho: add orr and orn instructions 2020-11-26 11:50:09 +01:00
Jakub Konka
10942e3f86 stage2 macho: Hello, Silicon! 2020-11-26 11:50:09 +01:00
Jakub Konka
2cd84b1b3f stage2 macho: refactor PIE generation on x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
ef5132c508 stage2 macho: first, rough draft at trampolining 2020-11-26 11:50:09 +01:00
Jakub Konka
80b1041c21 stage2 macho: use RIP-relative for memory-set regs x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
59fe3d447d stage2 macho: make file structure compatible with codesign tool 2020-11-26 11:50:09 +01:00
Jakub Konka
e7db372864 stage2 macho: cleanup logs 2020-11-26 11:50:09 +01:00
Jakub Konka
cd79c6dda1 stage2 macho: fix issues with codesigning 2020-11-26 11:50:09 +01:00
Jakub Konka
a6e93da717 stage2 macho: generate a code sig (not valid yet) 2020-11-26 11:50:09 +01:00
Jakub Konka
9dcf7ee9c9 stage2 macho: add info about __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
79381dc4fb stage2 macho: add empty CodeDirectory blob 2020-11-26 11:50:09 +01:00
Jakub Konka
d14cd59ef0 stage2 macho: move code signature logic into struct 2020-11-26 11:50:09 +01:00
Jakub Konka
3ac804628f stage2 macho: write out constants in CS 2020-11-26 11:50:09 +01:00
Jakub Konka
2bd963ad6a stage2 macho: don't pad out holes between sections 2020-11-26 11:50:09 +01:00
Jakub Konka
403dc50ff7 stage2 macho: preallocate empty code sig space 2020-11-26 11:50:09 +01:00
Jakub Konka
bbc4ee3f17 stage2 macho: refactor 2020-11-26 11:50:09 +01:00
Jakub Konka
a2e0e33249 stage2 macho: bring back incremental symbol commits 2020-11-26 11:50:09 +01:00
Jakub Konka
e1b65ff8d2 stage2 macho: cleanup minimum version command 2020-11-26 11:50:09 +01:00
Jakub Konka
be0d5571d2 stage2 macho: revert required alignment always at 4 2020-11-26 11:50:09 +01:00
Jakub Konka
2972f630a4 stage2 macho: start reverting some tweaks 2020-11-26 11:50:09 +01:00
Jakub Konka
4e3520a2f7 stage2 macho: make page size target cpu arch dependent 2020-11-26 11:50:09 +01:00
Jakub Konka
8450e6f156 stage2 macho: pages need to be 16kb aligned! 2020-11-26 11:50:09 +01:00