Commit Graph

199 Commits

Author SHA1 Message Date
Andrew Kelley c0b4121ff2 libc headers before C language headers, and disable libunwind on arm32 2019-07-16 21:38:18 -04:00
Andrew Kelley d994379173 update bundled musl source to 1.1.23 2019-07-16 19:54:14 -04:00
Andrew Kelley 15ed47921f Merge branch 'msvc-libc-2064' of https://github.com/dimenus/zig into dimenus-msvc-libc-2064 2019-07-16 12:51:02 -04:00
Andrew Kelley 851a7288a9 mingw libc can link against ntdll 2019-07-15 18:25:13 -04:00
Andrew Kelley 39b850c6cf mingw libc: delete dead linker code regarding using system libc 2019-07-12 18:10:53 -04:00
Andrew Kelley 3621d54e57 handle mingw libc defs better
also zig build handles --verbose and linkSystemLibrary better
2019-07-12 17:25:25 -04:00
Andrew Kelley 7b8ba871a9 mingw libc: solve the segfault having to do with destructors
* fixed --verbose-cc printing an extra "zig" before the rest of
   the command line
 * windows-gnu targets use libfoo.a, foo.o extensions to match mingw
   conventions.
2019-07-12 14:44:34 -04:00
Andrew Kelley e0670557b4 fix windows not able to build mingw 2019-07-10 20:20:53 -04:00
Andrew Kelley 3714d524c3 add some more windows defs 2019-07-10 19:40:46 -04:00
Andrew Kelley 2bb93784c6 mingw: build and link mingwex.lib
zig can now cross compile hello.c targeting windows
2019-07-10 17:41:34 -04:00
dimenus 540a40e2d9 fixing non system library linking 2019-07-10 15:37:25 -05:00
Andrew Kelley 67f3bc9101 mingw: building and linking msvcrt-os.lib 2019-07-10 16:19:51 -04:00
Andrew Kelley ea90a3a9a1 mingw: building and linking mingw32.lib 2019-07-10 14:13:00 -04:00
dimenus e9331dc5cf resolved #2064 & fixed hello_world libc build 2019-07-10 11:40:20 -05:00
Andrew Kelley 1c7f21852f ship with mingw-w64 v6.0.0
See #514
2019-07-09 23:34:16 -04:00
Andrew Kelley 7ccf7807b3 ability to target any glibc version 2019-07-07 17:56:08 -04:00
Timon Kruiper 7586f613d5 Added function-section functionality 2019-07-01 17:49:08 +02:00
Jonathan Marler 21dff1c4e2 Remove duplicate exe name with zig run 2019-06-17 14:10:10 -04:00
Andrew Kelley 5784631fab update the default macos version min to 10.14 2019-06-07 12:20:02 -04:00
LemonBoy 291aaee977 Stop the musl builder from skipping necessary files
The code assumed that the architecture-specific bits, found in the arch/
subfolder, were only overrides for the generic .c files.

Changed the logic to always include the whole architecture-specific
implementations and discard the generic ones, this way we won't exclude
files with no .c counterpart.
2019-06-04 12:45:02 -04:00
Andrew Kelley 1ab0ac3ea2 cleanups for windows subsystem in builtin.zig 2019-05-29 16:55:02 -04:00
Andrew Kelley 2c0280ba08 improve the stack check CLI options
See #2526
2019-05-27 20:59:19 -04:00
LemonBoy 266b2de150 Remove macos-specific linking hacks 2019-05-20 23:09:25 +02: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 14cdb01f35 improvements to zig's implementation of libc and WebAssembly
* rename std/special/builtin.zig to std/special/c.zig
   not to be confused with @import("builtin") which is entirely
   different, this is zig's multi-target libc implementation.
 * WebAssembly: build-exe is for executables which have a main().
   build-lib is for building libraries of functions to use from,
   for example, a web browser environment.
   - for now pass --export-all for libraries when there are any
     C objects because we have no way to detect the list of exports
     when compiling C code.
   - stop passing --no-entry for executables. if you want --no-entry
     then use build-lib.
 * make the "musl" ABI the default ABI for wasm32-freestanding.
 * zig provides libc for wasm32-freestanding-musl.
2019-05-15 20:14:58 -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
Benjamin Feng 8d58dc715b Switch wasm export-all to only values marked exports 2019-05-03 13:23:02 -04:00
Andrew Kelley d3c88a8949 Merge pull request #2139 from emekoi/lib-on-mingw
implement linking to libc on mingw
2019-04-29 13:16:41 -04:00
emekoi dfada0cc77 added static_crt_dir to libc file 2019-04-27 00:24:26 -05:00
emekoi f4c5fa7ff4 renamed add_gnu_link_args 2019-04-20 00:12:33 -05:00
Andrew Kelley f488f3fd03 remove workaround for LLD bug
Zig's embedded LLD now has a patch to resolve the deadlock race
condition, and the patch is getting upstreamed too, so this
closes #2283.
2019-04-16 03:58:15 -04:00
Andrew Kelley 6692cbbe18 disable threads when linking WebAssembly to work around an LLD bug
See #2283
2019-04-15 20:41:50 -04:00
Shritesh Bhattarai 94e0871603 wasi: don't pass --no-entry to linker 2019-04-14 00:03:32 -05:00
Andrew Kelley a895c59971 delete unused function
missed by 27cd830ec8
2019-04-11 14:33:43 -04:00
Matthew Iannucci 27cd830ec8 Add initial support for iOS targets (#2237)
* Add iOS C int sizes... try to hack in iOS DebugInfo

* Get rid of ios link check for now

* Remove macos linkversion check
2019-04-11 13:15:17 -04:00
Shritesh Bhattarai 666e879925 Build compiler_rt for WASM exe 2019-04-10 19:14:19 -04:00
Shritesh Bhattarai 3854bb9198 wasm: Pass --allow-undefined and --export-all to the linker 2019-04-05 18:46:11 -04:00
emekoi 0bd4901a17 fixed linking of system libraries on mingw 2019-04-04 21:07:02 -05:00
emekoi 6cc443ee45 added code for linking libc on mingw 2019-04-04 19:51:55 -05:00
emekoi ecd2332bb5 made lld flags on windows consistent 2019-04-04 19:51:55 -05:00
Andrew Kelley 3c7555cb67 Merge remote-tracking branch 'origin/llvm8' 2019-03-20 13:34:07 -04:00
Andrew Kelley 9801a1df6a disable all C warnings when building musl 2019-03-19 15:04:39 -04:00
Andrew Kelley a581f4f0e2 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-18 20:03:23 -04:00
Andrew Kelley 7dfbeca13e libc: separate linux headers from musl/glibc 2019-03-18 13:47:59 -04:00
Andrew Kelley 6acabd6b57 when linking msvcrt, also link ntdll.lib
See #2073
2019-03-17 14:14:05 -04:00
Andrew Kelley e861da03f9 macho linking: always -dynamic for non-static-libs 2019-03-14 00:07:05 -04:00
Andrew Kelley 862ac42a6e ignore -lm on darwin because it's handled by libSystem 2019-03-13 23:44:38 -04:00