39 Commits

Author SHA1 Message Date
Frank Denis
e60072635e
Add libdl shims from wasi-libc 2025-01-29 12:48:56 +01:00
Frank Denis
8a8da49b52
Re-add lazy preopen changes 2025-01-29 11:54:08 +01:00
Frank Denis
3f4c43b0aa
Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5 2025-01-29 11:54:02 +01:00
Andrew Kelley
2391c460b1 fix build failure when llvm not available 2025-01-20 20:59:52 -08:00
Andrew Kelley
e6dc85f1b4 remove memcpy and memmove from bundled libcs
These are provided instead by compiler_rt.

Part of #2879
2025-01-17 12:34:15 -08:00
Alex Rønne Petersen
f973d3e93e
glibc, musl, wasi-libc: Don't explicitly pass -fno-stack-protector.
This is already handled by build_crt_file().
2024-11-05 22:41:09 +01:00
Alex Rønne Petersen
b57819118d
Compilation: Move no_builtin to Package.Module.
This option, by its very nature, needs to be attached to a module. If it isn't,
the code in a module could break at random when compiled into an application
that doesn't have this option set.

After this change, skip_linker_dependencies no longer implies no_builtin in the
LLVM backend.
2024-11-05 14:43:02 +01:00
Alex Rønne Petersen
4c70aea460
Compilation: Use the regular module mechanism for setting PIC on CRT objects.
addCCArgs() will then pass the appropriate flag to Clang.
2024-11-03 09:29:33 +01:00
Andrew Kelley
14c8e270bb link: fix false positive crtbegin/crtend detection
Embrace the Path abstraction, doing more operations based on directory
handles rather than absolute file paths. Most of the diff noise here
comes from this one.

Fix sorting of crtbegin/crtend atoms. Previously it would look at all
path components for those strings.

Make the C runtime path detection partially a pure function, and move
some logic to glibc.zig where it belongs.
2024-10-10 14:21:52 -07:00
Andrew Kelley
f97c2f28fd update the codebase for the new std.Progress API 2024-05-27 20:56:48 -07:00
Andrew Kelley
a4380a30f5 move zig libc command to be lazily built
part of #19063

This is a prerequisite for doing the same for Resinator.
2024-02-27 22:55:00 -07:00
Andrew Kelley
f256431838 fix compilation errors when enabling llvm 2024-01-01 17:51:20 -07:00
Frank Denis
7ad4aede7a Remove obsolete comment in wasi_libc.zig
The referenced bug in LLD has been fixed:
https://reviews.llvm.org/D85567
2023-07-29 20:33:29 -07:00
Frank Denis
e7f872c9c6
wasi-libc: compile emmalloc.c without strict aliasing (#16157)
emmalloc.c does a fair amount of type punning in order to access
the size of memory regions and traverse them.

Unfortunately, that can lead to unwanted optimizations.

This simple test case currently triggers a memory fault:

int main(void) {
    char * volatile p = malloc(1);
    p = realloc(p, 12);
    p = malloc(1);
    printf("%p\n", p);
}

Work around this by adding "-fno-strict-aliasing" when compiling
that file.
2023-06-25 11:24:54 +02:00
Andrew Kelley
cdcfd15d3c musl: deal with zig rename of i386 to x86
musl uses "i386" for this while Zig has switched to "x86".
2023-06-20 12:55:38 -04:00
Frank Denis
dcc1b4fd15
Update wasi-libc to 3189cd1ceec8771e8f27faab58ad05d4d6c369ef (#15817)
Also remove all the wasi-libc files we used to ship, but never compile.

The latest wasi-libc HEAD has an extra commit (a6f871343313220b76009827ed0153586361c0d5), which makes preopen initialization lazy.

Unfortunately, that breaks quite a lot of things on our end. Applications now need to explicitly call __wasilibc_populate_preopens() everywhere when the libc is linked. That can wait after 0.11.
2023-05-23 22:12:53 +02:00
Andrew Kelley
8acbfafefb compiler: update function accepts a std.Progress.Node
This makes progress be exposed to the top-level caller of update().

I tossed in a bonus change: when the `zig build` subcommand sees exit
code 2, it omits the "following command failed" line, and the build
runner uses exit code 2 when there are compile errors. This tidies up
the output on build failure by a little bit.
2023-03-15 10:48:13 -07:00
Andrew Kelley
572cb24d1a progress towards semantic error serialization
Introduces std.zig.ErrorBundle which is a trivially serializeable set
of compilation errors. This is in the standard library so that both
the compiler and the build runner can use it. The idea is they will
use it to communicate compilation errors over a binary protocol.

The binary encoding of ErrorBundle is a bit problematic - I got a little
too aggressive with compaction. I need to change it in a follow-up
commit to use some indirection in the error message list, otherwise
iteration is too unergonomic. In fact it's so problematic right now that
the logic getAllErrorsAlloc() actually fails to produce a viable
ErrorBundle because it puts SourceLocation data in between the root
level ErrorMessage data.

This commit has a simplification - redundant logic for rendering AST
errors to stderr has been removed in favor of moving the logic for
lowering AST errors into AstGen. So even if we get parse errors, the
errors will get lowered into ZIR before being reported. I believe this
will be useful when working on --autofix. Either way, some redundant
brittle logic was happily deleted.

In Compilation, updateSubCompilation() is improved to properly perform
error reporting when a sub-compilation object fails. It no longer dumps
directly to stderr; instead it populates an ErrorBundle object, which
gets added to the parent one during getAllErrorsAlloc().

In package fetching code, instead of dumping directly to stderr, it now
populates an ErrorBundle object, and gets properly reported at the CLI
layer of abstraction.
2023-03-15 10:48:12 -07:00
Frank Denis
817cf6a82e
Update wasi-libc to 8b7148f69ae241a2749b3defe4606da8143b72e0 (#13793) 2022-12-06 22:48:35 +00:00
Frank Denis
861aa98ac2
wasi-libc: define BULK_MEMORY_THRESHOLD for the bulk_memory feature (#13787)
When the bulk_memory feature is enabled, wasi-libc will only use
it if the number of bytes is >= BULK_MEMORY_THRESHOLD

Set it to 32 as in the original wasi-libc Makefile.
2022-12-06 04:05:00 +00:00
Frank Denis
da9c530d99
Update wasi-libc to a00bf321eeeca836ee2a0d2d25aeb8524107b8cc (#13626)
* Update wasi-libc to a00bf321eeeca836ee2a0d2d25aeb8524107b8cc

It includes a port of emscripten's allocator that performs
performs much better than the old one.

Most importantly, it includes the prerequisites to later add
support for POSIX threads.
2022-11-28 19:58:03 +01:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
75548b50ff
allocgate: stage 1 and 2 building 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Takeshi Yoneda
b9e896d7b0 wasi-libc: remove crt1.o as it's not WASI ABI compatible
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-11 00:06:47 +02:00
Takeshi Yoneda
bc7761d8e0
Add support for WASI reactor in pure Zig-exe. (#9178)
* Add command line help for "-mexec-model"
* Define WasmExecModel enum in std.builtin.
* Drop the support for the old crt1.o in favor of crt1-command.o

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-30 20:02:48 -04:00
Jakub Konka
9f8de83d93 cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel 2021-06-09 11:11:55 +02: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
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
Andrew Kelley
ae01c65a58 stage2: fix reference to musl arch name
Also rename musl.archMuslName to musl.archName.

Fixes a merge conflict from #8730 and #8837
2021-05-23 13:32:52 -07:00
Jakub Konka
8c87a981f1 cc,wasi: force isysroot to / 2021-05-22 20:50:06 -04:00
Jakub Konka
b63c92f0b9 cc,wasi: do not add stack protector 2021-05-20 16:54:00 +02:00
Jakub Konka
3a5d0f7700 wasm: link dynamically by default when targeting wasm
This matches the behaviour of other languages and leaves us
the ability to create actual static Wasm archives with

```
zig build-lib -static some.zig
```

which can then be combined with other Wasm object files and linked
into either a Wasm lib or executable using `wasm-ld`.

Update langref to reflect the fact we now ship WASI libc.
2021-05-20 16:54:00 +02:00
Jakub Konka
6d5002028a cc,wasi: link compiled WASI libc with wasm-ld 2021-05-20 16:54:00 +02:00
Jakub Konka
f102a5800c cc,wasi: compile all WASI libc objects 2021-05-20 16:54:00 +02:00
Jakub Konka
60d8779eae cc,wasi: add source file paths to wasi_libc.zig 2021-05-20 16:54:00 +02:00
Jakub Konka
7b74de7d71 wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention:
  from `wasm32-wasi` to `wasm-wasi-musl`

Add building stubs which will be used to build and cache WASI
libc sysroot.
2021-05-20 16:54:00 +02:00