aboutsummaryrefslogtreecommitdiff
path: root/src/wasi_libc.zig
AgeCommit message (Collapse)Author
2025-05-10compiler: Move vendored library support to `libs` subdirectory.Alex Rønne Petersen
2025-05-10Introduce common `bzero` libc implementation. (#23812)David
* Introduce common `bzero` libc implementation. * Update test name according to review Co-authored-by: Linus Groh <mail@linusgroh.de> * address code review - import common implementation when musl or wasi is included - don't use `c_builtins`, use `@memset` * bzero calling conv to .c * Apply review Co-authored-by: Veikka Tuominen <git@vexu.eu> --------- Co-authored-by: Linus Groh <mail@linusgroh.de> Co-authored-by: Veikka Tuominen <git@vexu.eu>
2025-04-28wasi-libc: Fix paths to psignal.c and strsignal.c.Alex Rønne Petersen
Closes #23709.
2025-04-11Introduce libzigc for libc function implementations in Zig.Alex Rønne Petersen
This lays the groundwork for #2879. This library will be built and linked when a static libc is going to be linked into the compilation. Currently, that means musl, wasi-libc, and MinGW-w64. As a demonstration, this commit removes the musl C code for a few string functions and implements them in libzigc. This means that those libzigc functions are now load-bearing for musl and wasi-libc. Note that if a function has an implementation in compiler-rt already, libzigc should not implement it. Instead, as we recently did for memcpy/memmove, we should delete the libc copy and rely on the compiler-rt implementation. I repurposed the existing "universal libc" code to do this. That code hadn't seen development beyond basic string functions in years, and was only usable-ish on freestanding. I think that if we want to seriously pursue the idea of Zig providing a freestanding libc, we should do so only after defining clear goals (and non-goals) for it. See also #22240 for a similar case.
2025-02-21wasi-libc: Deduplicate sources and headers with regards to upstream musl.Alex Rønne Petersen
Unfortunately some duplicate files must remain in lib/libc/wasi/libc-top-half because they include internal headers *in the same directory* which have edits relative to upstream musl. Because C is an amazing language, there is no way to make it so that e.g. upstream musl's src/stdio/fputc.c includes wasi-libc's src/stdio/putc.h instead of the upstream putc.h. The preprocessor always searches the current directory first for quote includes. Anyway, this still takes us from 2.9M to 1.4M for the combination of lib/libc/wasi and lib/libc/include/wasm-wasi-musl, so I still call it a win.
2025-01-29Add libdl shims from wasi-libcFrank Denis
2025-01-29Re-add lazy preopen changesFrank Denis
2025-01-29Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5Frank Denis
2025-01-20fix build failure when llvm not availableAndrew Kelley
2025-01-17remove memcpy and memmove from bundled libcsAndrew Kelley
These are provided instead by compiler_rt. Part of #2879
2024-11-05glibc, musl, wasi-libc: Don't explicitly pass -fno-stack-protector.Alex Rønne Petersen
This is already handled by build_crt_file().
2024-11-05Compilation: Move no_builtin to Package.Module.Alex Rønne Petersen
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-03Compilation: Use the regular module mechanism for setting PIC on CRT objects.Alex Rønne Petersen
addCCArgs() will then pass the appropriate flag to Clang.
2024-10-10link: fix false positive crtbegin/crtend detectionAndrew Kelley
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-05-27update the codebase for the new std.Progress APIAndrew Kelley
2024-02-27move `zig libc` command to be lazily builtAndrew Kelley
part of #19063 This is a prerequisite for doing the same for Resinator.
2024-01-01fix compilation errors when enabling llvmAndrew Kelley
2023-07-29Remove obsolete comment in wasi_libc.zigFrank Denis
The referenced bug in LLD has been fixed: https://reviews.llvm.org/D85567
2023-06-25wasi-libc: compile emmalloc.c without strict aliasing (#16157)Frank Denis
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-20musl: deal with zig rename of i386 to x86Andrew Kelley
musl uses "i386" for this while Zig has switched to "x86".
2023-05-23Update wasi-libc to 3189cd1ceec8771e8f27faab58ad05d4d6c369ef (#15817)Frank Denis
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-03-15compiler: update function accepts a std.Progress.NodeAndrew Kelley
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-15progress towards semantic error serializationAndrew Kelley
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.
2022-12-06Update wasi-libc to 8b7148f69ae241a2749b3defe4606da8143b72e0 (#13793)Frank Denis
2022-12-06wasi-libc: define BULK_MEMORY_THRESHOLD for the bulk_memory feature (#13787)Frank Denis
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-11-28Update wasi-libc to a00bf321eeeca836ee2a0d2d25aeb8524107b8cc (#13626)Frank Denis
* 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.
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: stage 1 and 2 buildingLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-07-11wasi-libc: remove crt1.o as it's not WASI ABI compatibleTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-30Add support for WASI reactor in pure Zig-exe. (#9178)Takeshi Yoneda
* 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-09cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModelJakub Konka
2021-06-09cc,wasi: store CRTFile enum in wasi_emulated_libsJakub Konka
* 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-09cc,wasi: build referenced-only emulated componentsJakub Konka
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-09cc,wasi: package emulations as static archivesJakub Konka
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-09zig,cc,wasi: include emulated libs in WASI libcJakub Konka
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-05-23stage2: fix reference to musl arch nameAndrew Kelley
Also rename musl.archMuslName to musl.archName. Fixes a merge conflict from #8730 and #8837
2021-05-22cc,wasi: force isysroot to /Jakub Konka
2021-05-20cc,wasi: do not add stack protectorJakub Konka
2021-05-20wasm: link dynamically by default when targeting wasmJakub Konka
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-20cc,wasi: link compiled WASI libc with wasm-ldJakub Konka
2021-05-20cc,wasi: compile all WASI libc objectsJakub Konka
2021-05-20cc,wasi: add source file paths to wasi_libc.zigJakub Konka
2021-05-20wasi,cc: fix naming and add stubs for buildingJakub Konka
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.