93 Commits

Author SHA1 Message Date
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
Jakub Konka
4a3d757f3e stage2 MachO: reduce size of __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
7a407246ed stage2 MachO: remove discontinuities between segments 2020-11-26 11:50:09 +01:00
Jakub Konka
6ac7e99dad Write local symbols when flushing 2020-11-26 11:50:09 +01:00
Jakub Konka
b3fdfe5ca0 stage2 MachO: clean up segment protection flags 2020-11-26 11:50:09 +01:00
Jakub Konka
7dd5ce2527 stage2 macOS: make exe flagged as pie 2020-11-26 11:50:09 +01:00
Jakub Konka
1bec531cf2 stage2 MachO: add source version load cmd 2020-11-26 11:50:09 +01:00
Jakub Konka
72310db1da stage2 MachO: add min OS version load cmd 2020-11-26 11:50:09 +01:00
Andrew Kelley
abc717f203 modernize the PIE patch for the latest master branch
This is the part of #3960 that has to be rewritten to apply to latest
master branch code.
2020-11-22 17:28:11 -07:00
LemonBoy
8eaaa905f7
stage2: Make zig cc more verbose (#7166)
* stage2: Make zig cc more verbose

Make `zig cc` print more info from Clang itself and from our own linker
invocation, this is needed for CMake to properly discover all the
include directories and library search paths.

Closes #7110

* Update `update_clang_options`

* Typo fixes

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-19 23:30:16 +01:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
tgschultz
48d60834fd
Move leb128 and remove trivial *mem functions as discussed in #5588 (#6876)
* Move leb128 out of debug and remove trivial *mem functions as discussed in #5588

* Turns out one of the *Mem functions was used by MachO. Replaced with trivial use of FixedBufferStream.
2020-11-16 18:51:54 -05:00
Alex Cameron
a2582df5b2 Prevent double file close in MachO linking 2020-11-16 13:59:27 -08:00
Andrew Kelley
e78e0f57be macos: avoid --export-dynamic when using system linker 2020-11-08 23:04:38 -08:00
Jakub Konka
ab69b89d52 Address review comments 2020-11-06 11:57:53 +01:00
Jakub Konka
b7c3ebcb9e Rely on ZIG_SYSTEM_LINKER_HACK instead of input flags 2020-11-06 11:34:51 +01:00
Jakub Konka
e0e3ceac19 Re-enable system linker hack
It is now possible to force linking with system linker `ld` instead
of the LLVM `lld` linker when building natively on the target. This
can be done at each stage by specifying `--system-linker-hack` flag,
and can be useful on platforms where `lld` fails to operate properly
such as macOS 11 Big Sur on ARM64 where every binary/dylib is expected
to be codesigned.

Some example invocations for each stage of compilation of Zig
toolchain:

```
cmake .. -DCMAKE_PREFIX_PATH=/path/to/llvm -DSYSTEM_LINKER_HACK=1
```

```
build/zig build test --system-linker-hack
```

```
build/zig build --prefix $(pwd)/stage2 -Denable-llvm
--system-linker-hack
```

```
build/zig build-exe hello.zig --system-linker-hack
```
2020-11-05 18:35:51 +01:00
Jakub Konka
317c555a5c Fix linking issues on BigSur
This commit fixes linking issue on macOS 11 BigSur by appending
a prefix path to all lib and framework search paths known as
`-syslibroot`.

The reason this is needed is that in macOS 11, the system libraries
and frameworks are no longer readily available in the filesystem.
Instead, the new macOS ships with a built-in dynamic linker cache
of all system-provided libraries, and hence, when linking with either
`lld.ld64` or `ld64`, it is required to pass in `-syslibroot [dir]`.
The latter can usually be obtained by invoking `xcrun --show-sdk-path`.
With this commit, Zig will do this automatically when compiling natively
on macOS. However, it also provides a flag `-syslibroot` which can be
used to overwrite the automtically populated value.

To summarise, with this change, the user of Zig is not required to
generate and append their own syslibroot path. Standard invocations
such as `zig build-exe hello.zig` or `zig build` for projects will
work out of the box. The only missing bit is `zig cc` and `zig c++`
since the addition of the `-syslibroot` option would be a mismatch
between the values provided by `clang` itself and Zig's wrapper.
2020-11-02 17:06:09 +01:00
zhaozg
72343ffd06 fix #3237: resolve undefined symbol _DllMainCRTStartup 2020-10-29 20:09:22 -04:00
Timon Kruiper
ad6e095ef6 stage2.Elf: fix off by one error in writeOffsetTableEntry
The code was using the length of the local symbols, which also
includes the null symbol. Fix this by using the offset table instead,
which only keeps track of the symbols that end up in the got.
2020-10-29 14:38:48 -04:00
Andrew Kelley
919dcc5104 coff: link in CRT for DLLs that want -lc
see #5748
closes #5870
2020-10-17 20:35:44 -07:00
Andrew Kelley
05b1a7414e code cleanups
* in selfExePath, return errors instead of defaulting to bogus data
 * less invasive edits to the logic of link/Elf.zig
 * less indentation
2020-10-17 17:52:09 -07:00
Sebastien Marie
35a7247a2c
Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
LemonBoy
d44486b274 std: Add libssp implementation for GNU/Windows targets
Unlike glibc and musl, MinGW provides no libssp symbols leading to
countless compile errors if FORTIFY_SOURCE is defined.

Add a (incomplete) implementation of libssp written in Zig so that
linking succeeds.

Closes #6492
2020-10-16 21:22:14 -04:00
Andrew Kelley
d87bd3d8af fixups regarding windows wide strings
* remove GetModuleHandleA from kernel32.zig. use of A functions
   considered harmful.
 * make it a compile error to expose WinMain instead of wWinMain. same
   thing.
 * start code declares wWinMainCRTStartup instead of WinMainCRTStartup
   when it has the choice.
2020-10-15 19:37:55 -07:00
Jakub Konka
adfd298e44 Do not rewrite paths to dyld and libSystem unless changed 2020-10-13 08:38:17 +02:00
Jakub Konka
951721343f Reuse text blocks; enable all incremental tests 2020-10-13 08:38:17 +02:00
Jakub Konka
ecd480fe93 Fix writing of load cmds headers *after* symtab update 2020-10-13 08:38:17 +02:00
Jakub Konka
fc660af077 Update allocateTextBlock to use node free list 2020-10-13 08:38:17 +02:00
Jakub Konka
78ec7b671d Add mechanism for growing/shrinking text blocks 2020-10-13 08:38:17 +02:00
Jakub Konka
0b77152faa Add local and offset free lists 2020-10-13 08:38:17 +02:00
Vignesh Rajagopalan
2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Sébastien Marie
9ff51f22b4 openbsd: address link/Elf.zig comments
- restore correct behaviour on Android target for appending "crtend_android.o"
- some nits
2020-10-11 10:12:40 +00:00
Sébastien Marie
f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Andrew Kelley
9f8f446435 fixups to previous commit
* std.fs.Dir.readFile: add doc comments to explain what it means when
   the returned slice has the same length as the supplied buffer.
 * introduce readSmallFile / writeSmallFile to abstract over the
   decision to use symlink or file contents to store data.
2020-10-09 16:45:39 -07:00
mlarouche
57912964af Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows
Fix #6500
2020-10-09 16:50:43 -04:00
Jakub Konka
04b0ffdd13
Merge pull request #6577 from kubkon/macho-trie
stage2: add export trie generation in MachO linker
2020-10-09 17:41:52 +02:00
Jakub Konka
8dc4023615
Apply nitpick: top-level doc comments
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-09 17:40:37 +02:00
Josh Wolfe
bc6904eccc include compiler_rt and c for wasm static libraries 2020-10-09 01:54:42 -04:00
Jakub Konka
ba41e599bf
Clean up writing the trie into ULEB128 byte stream
Prealloc as much as possible to improve alloc performance.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-08 19:53:23 +02:00