515 Commits

Author SHA1 Message Date
Jakub Konka
cea8a2f500 tapi: apply ast fixes 2021-06-24 15:01:14 +02:00
Jakub Konka
b55a3cefa4 zld: extract path to libc in the linker proper 2021-06-24 14:45:45 +02:00
Jakub Konka
bc78b02c04 zld: introduce Stub.zig which represents parsed stub file
Instead of trying to fit a stub file into the frame of a Dylib struct,
I think it makes more sense to keep them as separate entities with
possibly shared interface (which would be added in the future).

This cleaned up a lot of logic in Dylib as well as Stub. Also, while
here I've made creating actual *Symbols lazy in the sense Dylib and
Stub only store hash maps of symbol names that they expose but we
defer create and referencing given dylib/stub until link time when
a symbol is actually referenced. This should reduce memory usage
and speed things up a bit.
2021-06-24 14:45:45 +02:00
Jakub Konka
09b46198ff zld: move logic unpacking path to libc stub to Compilation 2021-06-24 14:45:45 +02:00
Jakub Konka
a600d41880 zld: apply AST fixes 2021-06-24 14:45:45 +02:00
Jakub Konka
4854c96bc5 zld: create a synthetic ___dso_handle symbol self-referenced 2021-06-24 14:45:45 +02:00
Jakub Konka
96a0479db2 zld: parse lib stubs as tbds on the linker line 2021-06-24 14:45:45 +02:00
Jakub Konka
089577a71d zld: parse libSystem tbd stub when linking 2021-06-24 14:45:45 +02:00
Jakub Konka
fbdc515418 link: add basic TAPI parser for linkers
Parser uses kubkon/zig-yaml gitrev c3eae1e40a02aedd44ad1171e5c8b259896cbda0
2021-06-24 14:45:45 +02:00
Andrew Kelley
06412e04f9 cleanups related to unused params 2021-06-21 17:03:04 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Jacob G-W
641ecc260f std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
Michael Dusan
e006281d79 macho: LC_RPATH: reserve byte for null-terminator 2021-06-18 15:22:10 +02:00
Michael Dusan
79a4da14ad netbsd: add args to limit number of PT_LOAD segs
NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
ld.elf_so fails to load, emitting a general "not found" error.

Workaround issue by adding args `--no-rosegment` and `-znorelro`.

see #9109
2021-06-16 14:46:25 -04:00
Jakub Konka
0f4173c5d8
Merge pull request #9122 from ziglang/zld-proxies
zld: clean up stubs resolution, error messages and use ld64 defaults for system libs resolution
2021-06-15 14:55:12 +02:00
Jakub Konka
6362b82497 zld: map coalesced sections and handle undefines 2021-06-15 12:14:04 +02:00
Jakub Konka
cf26f8c19b zld: handle __eh_frame section 2021-06-15 12:14:04 +02:00
Jakub Konka
15ff0db794 zld: handle __gcc_except_tab section 2021-06-15 12:14:03 +02:00
Jakub Konka
96d3c4f54f zld: clean up parsing section by type and attrs 2021-06-15 12:14:03 +02:00
Jakub Konka
8204763328 zld: use ld64 defaults for searching system libs
By default, `ld64` uses `-search_paths_first` which firstly tries
to find a dylib, followed by an archive in each directory.
2021-06-15 11:52:03 +02:00
Jakub Konka
2034ca82b4 zld: stubs can also be part of unsigned relocs 2021-06-15 11:51:59 +02:00
Jakub Konka
7001bde84c zld: map coalesced sections and handle undefines 2021-06-14 20:21:54 +02:00
Takeshi Yoneda
bc64664a0c add various flags/options, and link libcxxabi.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-15 01:03:25 +09:00
Takeshi Yoneda
c708962386 link/wasm: link libcxx.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-14 23:39:39 +09:00
Jakub Konka
0ca0e88463 zld: handle __eh_frame section 2021-06-14 16:01:58 +02:00
Jakub Konka
5fc25ee8e4 zld: handle __gcc_except_tab section 2021-06-14 13:15:30 +02:00
Jakub Konka
66a93ebfbf zld: clean up parsing section by type and attrs 2021-06-14 12:56:53 +02:00
Andrew Kelley
86ebd4b975
Merge pull request #9106 from Vexu/fmt
Add formatting check to CI pipeline
2021-06-13 20:39:40 -04:00
Veikka Tuominen
e63ff4f1c1 add ast-check flag to zig fmt, fix found bugs 2021-06-14 00:16:40 +03:00
Jacob G-W
df4f11f42f link/Elf: don't use \n in log.debug calls
It already inserts a \n so it produces 2 \n which
is harder to read.
2021-06-13 23:42:57 +03:00
Jakub Konka
6aa9c63f63 zld: throw an error if found unknown section in object
We will silently ignore expected section that are either won't take
part in linking such as any `__DWARF` section, or are known but are
not yet implemented such as `__TEXT,__eh_frame`. For any other
we will throw an error and exit.

Also, inform the caller that we currently are unable to handle
frameworks.
2021-06-12 00:03:47 +02:00
Jakub Konka
ac587744e3 zld: allow for existence of __DATA_CONST segments in objects
Up until now, we only expected old-fashioned objects which carried
two basic segments by name: __TEXT and __DATA. Since macOS 11.1,
there is a new segment __DATA_CONST, and we should expect and
correctly parse sections designated to that segment explicitly
as is the case in golang.
2021-06-11 23:06:43 +02:00
Jakub Konka
b93fd4bb73 zld: match all __DATA sections as __data except __const
Examples of such sections include:
* in Go, you will get `__DATA,__noptrdata` or `__DATA,__go_buildinfo`
  which should be mapped to `__DATA,__data`
2021-06-11 16:52:22 +02:00
Jakub Konka
961d556570
Merge pull request #9069 from ziglang/zld-common-syms
zig ld: add common (tentative) symbols support
2021-06-11 10:18:43 +02:00
Jakub Konka
a8116dcc27 zld: fix bug in working out commons total size 2021-06-11 08:34:12 +02:00
Andrew Kelley
138afd5cbf zig fmt 2021-06-10 20:13:43 -07:00
Jakub Konka
e1f1f16183 zld: clean up 2021-06-10 21:05:20 +02:00
Jakub Konka
0e08cd63e2 zld: fix debug info for regulars synthed from tentative 2021-06-10 19:28:11 +02:00
Jakub Konka
c2086efb41 zld: synthetise regular from tentative definition 2021-06-10 17:49:14 +02:00
Jakub Konka
03cda80a63 zld: handle aliasing of tentative into regular global 2021-06-10 11:03:14 +02:00
Jakub Konka
66ff56c58f zld: add Symbol.Tentative to denote common symbol 2021-06-10 10:29:57 +02:00
Jakub Konka
96bb81b6ef zld: moving target seg,sect mapping into Object.Section 2021-06-10 09:13:35 +02:00
Jakub Konka
88aec4a1ee zld: work out size and alignment of commons 2021-06-10 07:15:32 +02:00
Jakub Konka
b82d6422ac link: don't link system libs by the wasm linker
The only allowed system libraries that we can link are libraries
that are part of the sysroot such as libc or WASI emulated
subcomponents. This is required as Wasm allows to defer symbol
resolution until load time.

For example, the following import in Zig

```zig
extern "wasi_snapshot_preview1" fn proc_exit() void;
```

would normally result in appending `-lwasi_snapshot_preview1` flag
to the linker line. However, for Wasm/WASI, the symbol is provided
at load rather than link time, therefore, the linker should not be
concerned with resolving the symbol. As a result, we should not
consider system libs by the Wasm linker.
2021-06-10 06:36:16 +02:00
Jakub Konka
9f8de83d93 cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel 2021-06-09 11:11:55 +02:00
Takeshi Yoneda
bf568ec62a cc,wasi: support WASI reactors via -mexec-model flag.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-09 17:07:06 +09:00
Jakub Konka
2ee1f7898b cc,wasi: store CRTFile enum in wasi_emulated_libs
* then, in `link/Wasm.zig` map `CRTFile` to full emulated libs name
* move logic for removing any mention of WASI snapshot
  `wasi_snapshot_preview1` from `Compilation.zig` into `link/Wasm.zig`
2021-06-09 01:25:38 +02:00
Jakub Konka
dd84ccda5d wasi: clean up linking logic
Do not try to link WASI libc or emulated subcomponents when not
targeting WASI; e.g., when targeting `wasm32-freestanding`.
2021-06-09 01:25:38 +02:00
Jakub Konka
4e4722a65e cc,wasi: build referenced-only emulated components
Move parsing of system libs into `main.zig` next to where we decide
if we should link libC, and, if targeting WASI, if the specified
libname equals one of the emulated components, save it on the side
and remove it from the system libs. Then, build *only* those parts
of WASI libc that were preserved in the previous step.

This also fixes building of different crt1 bits needed to support
reactors and commands.
2021-06-09 01:25:38 +02:00
Jakub Konka
93a4403271 cc,wasi: package emulations as static archives
This replicates the expected behavior when using `clang` with
upstream `wasi-libc` sysroot: linking emulated subcomponents
such as process clocks or signals requires an explicit link flag
in the compiler invocation, for example:

```
zig cc -target wasm32-wasi -lwasi-emulated-process-clocks main.c -o main.wasm
```
2021-06-09 01:25:38 +02:00