mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 22:34:28 +00:00
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.
27 lines
635 B
C
Vendored
27 lines
635 B
C
Vendored
#if defined(_REENTRANT)
|
|
#include <stdatomic.h>
|
|
extern void __wasi_init_tp(void);
|
|
#endif
|
|
extern void __wasm_call_ctors(void);
|
|
|
|
__attribute__((export_name("_initialize")))
|
|
void _initialize(void) {
|
|
#if defined(_REENTRANT)
|
|
static volatile atomic_int initialized = 0;
|
|
int expected = 0;
|
|
if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) {
|
|
__builtin_trap();
|
|
}
|
|
|
|
__wasi_init_tp();
|
|
#else
|
|
static volatile int initialized = 0;
|
|
if (initialized != 0) {
|
|
__builtin_trap();
|
|
}
|
|
initialized = 1;
|
|
#endif
|
|
|
|
// The linker synthesizes this to call constructors.
|
|
__wasm_call_ctors();
|
|
}
|