6019 Commits

Author SHA1 Message Date
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
xackus
e5750f8c7f translate-c: better numeric type parsing 2021-06-13 16:47:55 +03:00
xackus
aa83cbb697 translate-c: better typename parsing 2021-06-13 16:47:42 +03:00
joachimschmidt557
46b9e061e0 stage2 Sema: enable float multiplication and division 2021-06-13 15:24:28 +03:00
Veikka Tuominen
6664679c8c translate-c: don't bother with unwrapping pointers
Dereferencing a c pointer implicitly includes an unwrap,
manually adding it just causes bugs.
2021-06-13 15:23:31 +03:00
Evan Haas
ea4a25287e translate-c: better support for static local variables
Don't move static local variables into the top-level scope since this
can cause name clashes if subsequently-defined variables or parameters
in different scopes share the name.

Instead, use a variable within a struct so that the variable's lexical
scope does not change. This solution was suggested by @LemonBoy

Note that a similar name-shadowing problem exists with `extern` variables
declared within block scope, but a different solution will be needed since
they do need to be moved to the top-level scope and we can't rename them.
2021-06-12 23:12:37 +03:00
Exonorid
f63338195d Renamed @byteOffsetOf to @offsetOf 2021-06-12 19:16:01 +03:00
Jakub Konka
05b5e49bc0
Merge pull request #9086 from ziglang/fix-9050
zig ld: act as linker for golang
2021-06-12 11:39:23 +02:00
xackus
b5c117d051 translate-c: fix enums that require c_uint type 2021-06-12 11:55:39 +03:00
Andrew Kelley
caad5c4960 zig cc: recognize more pie flags
This is a bug fix.
2021-06-11 15:57:52 -07: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
Evan Haas
45212e3b33 translate-c: Implement flexible arrays
Fixes #8759
2021-06-11 21:31:39 +03:00
Andrew Kelley
b6277a4b1c better awareness of unwind tables
* stage1 backend allows configuring the uwtables function attr
   via a flag rather than its own logic.
 * stage2 defaults to enabling uwtable attr when
   linking libunwind, or always on windows
 * stage2 makes link_eh_frame_hdr true automatically if uwtable
   attr is set to be on for zig functions
 * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to
   override the defaults.
 * hook it up to `zig cc`

closes #9046
2021-06-11 13:23:00 -04: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
LemonBoy
43a09f7efc stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 12:50:25 -04:00
Jakub Konka
c2086efb41 zld: synthetise regular from tentative definition 2021-06-10 17:49:14 +02:00
AODQ
d368fd435f Print path on libc/libc-path fatal error 2021-06-10 12:03:54 +03: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
daurnimator
916b645fc1 Have std.fmt functions take case as an enum 2021-06-10 08:33:42 +03: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
Andrew Kelley
5e63baae8d CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-09 14:38:27 -07:00
Andrew Kelley
d128ec39df native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.

This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.

Closes #8960
2021-06-09 17:26:58 -04:00
joachimschmidt557
96c60bcca5 stage2 codegen: Remove hacks for discontinued SPU II backend 2021-06-09 21:37:23 +03: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
95745f77da wasi: skip adding wasi_snapshot_preview1 as lib dep in stage1 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
Jakub Konka
6f6182a5f3 zig,cc,wasi: include emulated libs in WASI libc
This commit includes emulated libc sublibs that were not included
in the compilation and caching of WASI libc that ships with Zig.
The libs include (emulated): process clocks, getpid, mman, and signal.

With this change, it is now possible to successfully cross-compile
`wasm3` engine to WASI with `zig cc`.

For the future though, it might be worth considering splitting WASI
libc into libc-proper and modularised emulated libs as it is done
in upstream, and then have them included only if the user specifically
requests emulation/parts of it.
2021-06-09 01:25:38 +02:00
jacob gw
b57ac48773 stage2: compile error for ambiguous decl refrences
std: fix compile errors from this change. This is a stage1 bug.
2021-06-08 18:13:12 -04:00
Andrew Kelley
ccfa168284
Merge pull request #9030 from Vexu/stage2
Stage2: implement comptime variables
2021-06-08 14:16:57 -04:00
Matthew Borkowski
9ac6d28614 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 20:58:30 +03:00
Matthew Borkowski
fc956fc110 stage1: fix render_const_value for printing const optional pointers 2021-06-08 20:41:09 +03:00
Veikka Tuominen
d41a5105cd stage2: fix repeat_inline skipping first instruction in block
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-06-08 10:15:34 +03:00