4645 Commits

Author SHA1 Message Date
LemonBoy
0f7954831a stage1: Initialize single-element union tag correctly
Use the field value instead of defaulting to zero.
2020-12-05 18:58:54 +01:00
LemonBoy
865d6df03e stage1: Fix constant folding of single-element enums
Fill in the correct value instead of leaving everything uninitialized.
This problem can be noticed in behavior/union.zig but it's masked by
some other "optimization" kicking in at the wrong time, the following
commits will address that.
2020-12-05 18:58:37 +01:00
Jakub Konka
b6b7a6401c
Merge pull request #7293 from kubkon/fix-7030
stage1: allow idx 0 err to be put into error_name_table
2020-12-04 16:29:38 +01:00
Andrew Kelley
afaef36194 stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:07:13 -07:00
Andrew Kelley
ddaf915389 add @cImport files to Compilation cache manifest
closes #7007
2020-12-03 16:07:38 -07:00
Jakub Konka
54706dd229 Allow idx 0 err to be put into error_name_table
This way, in the very situation where a function has a return type
an error union such as `anyerror!void` but doesn't have any erroneous
paths, calling `@errorName` on the unpacked error (which will never
be triggered) will not trip up the static analyzer.
2020-12-03 23:31:35 +01: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
Koakuma
5317f00e04
Fix floating point parsing on BE systems (#7256)
* Fix floating point parsing on BE systems

* Load the appropriate endian.h files for macOS and BSD

* Add endian definition for Windows and extra check for ldshape selection

* Fix endian macro definition for macOS

Apparently their macros are defined without a leading __.

* Define new macro for endian checking purposes

This is gross and I really do not like the lack of standardization
around this part, but what can I do?
2020-12-03 15:47:06 -05:00
Timon Kruiper
ac85e1f2c8 stage2: make sure to emit the ZIR instructions of exported functions
Previously the emitted ZIR code would not have the ZIR instructions
of the exported functions.
2020-12-03 11:46:35 -08: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
Andrew Kelley
41387e1822 stage2: linkAsArchive: respect disable_lld_caching
Closes #7274
Closes #6943
2020-12-02 16:37:32 -07:00
Andrew Kelley
6d91ebce45 wire up -Dskip-non-native to stage2 tests 2020-12-02 15:52:07 -07:00
Andrew Kelley
463186e856 stage2: wire up -Dskip-non-native
The purpose of this is to save time in the edit-compile-test cycle when
working on stage2 code.
2020-12-02 14:52:56 -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
LemonBoy
c91c4dc256 stage2: Create cache manifest before calling final
If we enter the `if` because `comp.disable_c_depfile` is false the `man`
object has no manifest and calling .final on it will trip an assertion.

Closes #7096
2020-12-01 16:52:28 -07:00
Andrew Kelley
5b5097a22a stage2: add -femit-foo=bar args to the cache hash
Closes #6979
Closes #7036
2020-12-01 16:35:27 -07: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
Alexandros Naskos
8d6eff5cb9 Add package names and paths to the zig root module cache hash.
Add package names to the stage1 cache hash and package files to the
stage1 manifest file.
2020-12-01 13:56:36 -08:00
Timon Kruiper
8cbcc61c4d Make sure to include the root_name in the cache.
This fixes a bug where the caching system did not notice when the
--name flag changed.
2020-12-01 10:38:33 -08: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
21565ca991 restore -target wasm32-freestanding-musl for C headers
See #5854

Some tiny tweaks too:
 * Use `wasm-freestanding-musl` instead of `wasm32-freestanding-musl`,
   making it pointer-size-agnostic.
 * Fix trying to build non-existent wasm musl start files.
2020-11-30 20:44:36 -07:00
Andrew Kelley
429a219f42 stage2: fix not detecting all dynamic libraries
Positional shared library arguments were not being detected as causing
dynamic linking, resulting in invalid linker lines. LLD did not have an
error message for this when targeting x86_64-linux but it did emit an
error message when targeting aarch64-linux, which is how I noticed the
problem.

This surfaced an error having to do with fifo.pipe() in the cat example
which I did not diagnose but solved the issue by doing the revamp that
was already overdue for that example.

It appears that the zig-window project was exploiting the previous
behavior for it to function properly, so this prompts the question, is
there some kind of static/dynamic executable hybrid that the compiler
should recognize? Unclear - but we can discuss that in #7240.
2020-11-30 20:25:28 -07:00
Andrew Kelley
9d1816111d build system: pass dyn lib artifacts as positionals 2020-11-30 18:12:00 -07:00
Alexandros Naskos
beb9d33d6d Disallow absolute paths passed as system libraries
Added OBJECT_NAME_INVALID handling in faccessatW
2020-11-30 18:08:27 -07: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
Alexandros Naskos
2fae28b6af Added bundle-compiler-rt flag 2020-11-30 14:31:41 -07:00
Andrew Kelley
52b24d5725 stage1: add some code comments for ConstValSpecial 2020-11-29 18:02:13 -07:00
Andrew Kelley
3fb0cc0a14 CLI: add missing usage help text 2020-11-29 16:32:24 -07:00
Andrew Kelley
263f25fea6
Merge pull request #7116 from joachimschmidt557/stage2-arm
stage2 ARM: add basic arithmetic instructions
2020-11-29 10:43:29 -08:00
LemonBoy
df99cfdf1e stage1: Fix typeInfo generation for arrays w/o sentinel
ZigTypeIdOptional types have a different way of specifying their payload
value depending on whether the child type is a pointer or not (plus some
other special cases).

Fixes #7251
2020-11-29 10:39:10 -08:00
LemonBoy
c80d196094 stage1: Add missing bitcast when rendering var ptr
Some types require this extra bitcast, eg. structs or unions with extra
padding fields inserted by the compiler.

Fixes #7250
2020-11-29 10:37:06 -08:00
Andrew Kelley
e701ac1a51
Merge pull request #7237 from koachan/sparc64-longdouble_fork
Add "long double" mapping and implement fork() on Linux/sparc64
2020-11-29 10:33:43 -08:00
joachimschmidt557
2ad2636588
stage2 ARM: use strb + implement genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
f06f0ebcda
stage2 ARM: Implement genNot 2020-11-28 18:19:22 +01:00
joachimschmidt557
85a3991a43
stage2 codegen: use switch in genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
27c5c97f21
stage2 ARM: genAdd, genSub for simple cases 2020-11-28 18:19:19 +01: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
dd522c0c97 stage2 elf: fix glibc to always specify soname 2020-11-27 15:42:39 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00