-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy-initialize the environment variables. #184
Conversation
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.
@@ -7,6 +7,10 @@ weak_alias(dummy, __env_rm_add); | |||
|
|||
int clearenv() | |||
{ | |||
#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | |||
#else | |||
#include "wasi/libc-environ-compat.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment here (& in the other uses) indicating that this header is intended to be used inside a func body, and it redefines the __environ symbol. The latter seems like it may cause unintended consequences if someone performed otherwise innocent-looking code motion without understanding the details of that header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments added. The most common cases of code motion are guarded against, because if you use __environ
before it's defined, you'll get errors, and if you use the redefined __environ
in a function other than the one the header was included in, __wasilibc_environ
won't be declared and you'll get errors. But I agree, this is particularly tricky code, so comments are good.
To support this, add a mechanism for filtering test output to filter out uninteresting diffs. This adds some coverage for the code being changed in WebAssembly/wasi-libc#184.
To support this, add a mechanism for filtering test output to filter out uninteresting diffs. This adds some coverage for the code being changed in WebAssembly/wasi-libc#184.
Brings in WebAssembly/wasi-libc#184 which can help standalone programs with environment variables!
…lbini Update the bundled wasi-libc with libstd Brings in WebAssembly/wasi-libc#184 which can help standalone programs with 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 theenvironment on demand, we avoid depending on having
__wasm_call_ctors
run.
This uses weak symbols strategically to ensure that if
environ
isused, it is initialized eagerly, but if only
getenv
and friendsare 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 becalled automatically, but this helps in simple cases for now.
Fixes #180. cc @alexcrichton