]> git.proxmox.com Git - wasi-libc.git/commit
Lazy-initialize the environment variables. (#184)
authorDan Gohman <sunfish@mozilla.com>
Thu, 19 Mar 2020 16:32:41 +0000 (09:32 -0700)
committerGitHub <noreply@github.com>
Thu, 19 Mar 2020 16:32:41 +0000 (09:32 -0700)
commit9efc2f428358564fe64c374d762d0bfce1d92507
tree3852747d49a49e67a02d974edf51d1021a26c4a5
parent38b930a26b60558522bc34adc7621fff17925b4a
Lazy-initialize the environment variables. (#184)

* Lazy-initialize the environment variables.

This is the first in a series of PRs to make it easier to use WASI libc
in Wasm modules that don't have a `main` function. By initializing the
environment on demand, we avoid depending on having `__wasm_call_ctors`
run.

This uses weak symbols strategically to ensure that if `environ` is
used, it is initialized eagerly, but if only `getenv` and friends
are used, the environment is initialized lazily.

Eventually, I expect we'll have a convention for wasm modules without
main functions which will allow the `__wasm_call_ctors` function to be
called automatically, but this helps in simple cases for now.

Fixes #180.

* Add comments explaining the libc-environ-compat.h header usage.
14 files changed:
expected/wasm32-wasi/defined-symbols.txt
expected/wasm32-wasi/include-all.c
expected/wasm32-wasi/predefined-macros.txt
libc-bottom-half/headers/public/wasi/libc-environ.h [new file with mode: 0644]
libc-bottom-half/libpreopen/libpreopen.c
libc-bottom-half/sources/__environ.c [deleted file]
libc-bottom-half/sources/__wasilibc_initialize_environ.c [new file with mode: 0644]
libc-bottom-half/sources/environ.c [new file with mode: 0644]
libc-top-half/headers/private/wasi/libc-environ-compat.h [new file with mode: 0644]
libc-top-half/musl/src/env/clearenv.c
libc-top-half/musl/src/env/getenv.c
libc-top-half/musl/src/env/putenv.c
libc-top-half/musl/src/env/unsetenv.c
libc-top-half/musl/src/include/unistd.h