Commit Graph

1090 Commits

Author SHA1 Message Date
Andrew Kelley 5784631fab update the default macos version min to 10.14 2019-06-07 12:20:02 -04:00
LemonBoy 80cd142c96 Propagate DIFlags to LLVM 2019-06-04 09:05:33 +02:00
LemonBoy ebe921e48f Make void a signed type
Follow the convention set by C so that lldb stops complaining about it.
2019-06-04 09:05:12 +02:00
tgschultz f9e7bd2682 std.meta/trait: def/definition => decl/declaration
TypeInfo: defs/Definition => decls/Declarations
2019-05-29 20:43:07 -04:00
Andrew Kelley 3819654c39 codegen: initialize subsystem 2019-05-29 16:55:02 -04:00
Andrew Kelley 1ab0ac3ea2 cleanups for windows subsystem in builtin.zig 2019-05-29 16:55:02 -04:00
emekoi b461e600e2 set subsystem to null if not on windows or uefi 2019-05-29 16:55:01 -04:00
emekoi 6bc5b07e3e try to resolve TargetSubSystemAuto to actual subsystem 2019-05-29 16:55:01 -04:00
emekoi fb5dc28921 added subsystem to builtin.zig 2019-05-29 16:54:59 -04:00
Andrew Kelley b66438eb80 no "use of undeclared identifer" in dead comptime branches 2019-05-28 18:19:27 -04:00
Andrew Kelley 9d16839420 fix invalid LLVM IR generated for ?*void const casts
closes #2578
2019-05-28 16:11:36 -04:00
LemonBoy e2c2263434 Move __zig_fail_unwrap locals on stack 2019-05-28 13:02:45 -04:00
emekoi 3f302594b8 respect subsystem flag in all cases 2019-05-27 22:15:33 -04:00
Andrew Kelley f924fbddcf Merge pull request #2552 from Sahnvour/issue-2543
gen-h: do not output visibility macros when the build is static
2019-05-27 21:51:34 -04:00
Andrew Kelley 2c0280ba08 improve the stack check CLI options
See #2526
2019-05-27 20:59:19 -04:00
Andrew Kelley 269a53b6af introduce @hasDecl builtin function
closes #1439
2019-05-26 16:21:03 -04:00
Sahnvour 99ee0608f7 gen-h: do not output visibility macros when the build is static 2019-05-25 14:17:59 +02:00
LemonBoy 0a3aec020a Fix load/store of non-integer fields in packed struct 2019-05-18 19:59:47 -04:00
Andrew Kelley 80983ca1ca fixups to the previous commit 2019-05-16 16:37:58 -04:00
Shawn Landden 1fdb24827f breaking changes to all bit manipulation intrinsics
* `@clz`, `@ctz`, `@popCount`, `@bswap`, `@bitreverse` now
   have a type parameter
 * rename @bitreverse to @bitReverse
 * rename @bswap to @byteSwap

Closes #2119
Closes #2120
2019-05-16 16:37:58 -04:00
Andrew Kelley 81e960eb74 improvements to build-lib use case of WebAssembly
* build-exe does include the startup code that supplies _start for the
   wasm32-freestanding target. Previously this did not occur because
   of logic excluding "freestanding".
 * build-lib for wasm32-freestanding target gets linked by LLD. To avoid
   infinite recursion, compiler_rt and zig libc are built as objects
   rather than libraries.
   - no "lib" prefix and ".wasm" extension instead of ".a". Rather than
   build-lib foo.zig producing "libfoo.a", now it produces "foo.wasm".
 * go back to using `.o` extension for webassembly objects
 * zig libc only provides _start symbol for wasm when linking libc.
2019-05-16 13:56:56 -04:00
Andrew Kelley 6b36b756eb fix static builds of zig from requiring c compiler
to be installed when linking libc.

When zig links against libc, it requires a dynamic linker path.
Usually this can be determined based on the architecture and operating
system components of the target. However on some systems this is not
correct; because of this zig checks its own dynamic linker.

When zig is statically linked, this information is not available, and so
it resorts to using cc -print-filename=foo to find the dynamic linker
path.

Before this commit, Zig incorrectly exited with an error if there was
no c compiler installed. Now, Zig falls back to the dynamic linker
determined based on the arch and os when no C compiler can be found.
2019-05-15 21:50:56 -04:00
Andrew Kelley df4f77024e else value when switching on error set has
optional capture value which is subset.

see #769
2019-05-14 18:06:57 -04:00
LemonBoy 6536b409df Don't emit DW_TAG_lexical_block for VarDecls 2019-05-14 14:34:49 -04:00
Andrew Kelley 7330a6102f cache_add_dep_file: handle ErrorFileNotFound specially 2019-05-13 12:15:55 -04:00
LemonBoy a038ef3570 Assemble asm files using CC
Stuffing all the files together and compiling the resulting blob with
the main program is a terrible idea.

Some files, namely the .S ones, must be run trough the C preprocessor
before assembling them (#2437).

Beside that the aggregate may be mis-compiled due to the presence of
some flags that affect the following code.

For example let's consider two files, a.s and b.s

a.s
```
fn1:
    ret
.data
data1:
    .word 0
```

b.s
```
fn2:
    ret
```

Now, fn1 and fn2 will be both placed in the .text section as intended if
the two files are compiled separately. But if we merge them the `.data`
flag ends up placing fn2 in the wrong section!

This fixes a nasty crash where musl's memset ended up in the
non-executable data segment, leading to too many hours of
head-scratching.
2019-05-13 16:41:07 +02:00
Andrew Kelley a7346ea49f fix build on macOS
Sadly due to a workaround for LLD linker limitations on macOS
we cannot put libuserland into an .a file; instead we have to use object
files. Again due to linker limitations, bundling compiler_rt.o into
another relocatable object also doesn't work. So we're left with
disabling stack probing on macOS for the stage1 self-hosted code.

These workarounds could all be removed if the macos support in the LLD
linker improved, or if Zig project had its own linker that did not have
these issues.
2019-05-08 22:45:49 -04:00
Andrew Kelley 9bbd71c9ab add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley 0099583bd3 C pointers support .? operator
see #1967
2019-05-08 17:39:00 -04:00
Andrew Kelley 50bbb34594 C pointers support null
See #1967
2019-05-08 16:06:34 -04:00
LemonBoy be7cacfbbe Implement stack probes for x86/x86_64
Enabled on non-Windows systems only since it already requires stack
probes.
2019-05-08 12:36:54 -04:00
Andrew Kelley bd9c629c4c always respect threadlocal for variables with external linkage
Previously if you had, for example:

extern "c" threadlocal var errno: c_int;

This would turn errno into a normal variable for --single-threaded
builds. However for variables with external linkage, there is an ABI
to uphold.

This is needed to make errno work for DragonFly BSD. See #2381.
2019-05-03 14:39:54 -04:00
Andrew Kelley 3552180143 optimize @memset with undefined
When using `@memset` to set bytes to `undefined`, Zig notices this
case and does a single Valgrind client request rather than N.

Speeds up all allocators in safe modes.

Closes #2388
2019-05-03 01:25:03 -04:00
Andrew Kelley e1bf74fca3 translate-c: put -x c back in there, it's necessary 2019-04-25 00:06:58 -04:00
Andrew Kelley 712274997e translate-c: unify API for self-hosted and C++ translate-c
See #1964
2019-04-25 00:06:57 -04:00
Andrew Kelley 976080462c translate-c: a little closer to self-hosted implementation 2019-04-25 00:06:54 -04:00
Shawn Landden 8ef7f6febb remove Shebang (#!) support
Closes:  #2165
2019-04-24 23:34:19 -04:00
Andrew Kelley 89763c9a0d stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.

Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.

Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.

Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.

As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).

This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.

This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.

See #1964
2019-04-16 19:12:20 -04:00
Andrew Kelley 4e2f6ebf39 freestanding target adds -ffrestanding to cc parameters
closes #2287
2019-04-16 12:06:14 -04:00
Andrew Kelley 579dd74114 fix Debug mode when error return tracing is off
Previously the code for generating a panic crash expected
one of the parameters to be the error return trace. Now
it does not expect that parameter when g->have_err_ret_tracing
is false.

Closes #2276
2019-04-15 20:17:06 -04:00
Shritesh Bhattarai a0d2185199 wasm: add wasm-import-module attr to extern 2019-04-15 17:00:04 -05:00
Andrew Kelley 27253f09b6 organize how the single threaded option is passed around 2019-04-14 11:01:01 -04:00
Shritesh Bhattarai 63f2e96eea wasm: use .wasm ext for exe 2019-04-12 13:17:59 -04:00
Shritesh Bhattarai 5f8dbcac06 wasm: disable error ret tracing 2019-04-11 16:37:40 -04:00
Andrew Kelley a71bfc249d compiler-rt: better way to do the ABI required on Windows
This removes the compiler_rt.setXmm0 hack. Instead, for
the functions that use i128 or u128 in their parameter and
return types, we use `@Vector(2, u64)` which generates
the LLVM IR `<2 x i64>` type that matches what Clang
generates for `typedef int ti_int __attribute__ ((mode (TI)))`
when targeting Windows x86_64.
2019-04-10 18:47:14 -04:00
Andrew Kelley 1dc6751721 fix NaN comparing equal to itself
This was broken both in comptime code and in runtime code.

closes #1174
2019-04-04 22:07:15 -04:00
Andrew Kelley be0f656c21 fix @divFloor returning incorrect value and add __modti3
Closes #2152
See #1290
2019-04-04 15:45:37 -04:00
Andrew Kelley e4d595a8ba fix thread local variables for non- position independent code
This fixes comes thanks to Rich Felker from the musl libc project,
who gave me this crucial information:

"to satisfy the abi, your init code has to write the same value
to that memory location as the value passed to the [arch_prctl]
syscall"

This commit also changes the rules for when to build statically
by default. When building objects and static libraries, position
independent code is disabled if no libraries will be dynamically
linked and the target does not require position independent code.

closes #2063
2019-04-04 01:08:26 -04:00
Andrew Kelley d577dde636 passing all tests 2019-04-02 18:31:19 -04:00
Andrew Kelley 4c38a8cce1 more regression fixes. empty test passes again 2019-04-02 18:31:19 -04:00