-
Notifications
You must be signed in to change notification settings - Fork 261
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
__wasm_call_ctors, __wasm_call_dtors #471
Comments
Hey, I found a workaround after reading this:
So in case anyone has this issue that static constructors and destructors are being called for each export function, make a call to __wasm_call_ctors in _start/main function: In my case, C++: WA_EXPORT("main") And not the linker generates code where: |
I also suggest to avoid static destructors for unexpected llvm changes that will break correct functionality! To detect them use the -Wexit-time-destructors flag. It is also worth noting that clang has support for not generating static destructors: -fno-c++-static-destructors Calling by default C++ static constructors and functions (static int x = somefunc()) for each "export" entry point is a very very bad idea!!! The project: I also wrote about this issue to llvm guys: |
The idea here is that there are two different types of wasm modules that one might build: What you are building sound more like a "reactor" which is more like shared library that maintains state between calls into it from the outside. You can read more about this change here: #13 |
Thank you Sam! |
This is primarly a mechanism to deliver a workaround for a breaking change in Rust v1.56.0 (which updated LLVM to v13.0), which changed existing reactors into multi-entry commands, leading to performance degradation and/or unusable Proxy-Wasm plugins. See: WebAssembly/WASI#471 This is delivered as a macro to make it somehow compatible with the unstable "-Z wasi-exec-model=reactor" feature. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
The issue is that this change broke previously working WASI reactors. Note that Rust supports building proper WASI reactors only in nightly using This worked fine until Rust v1.56.0 (which updated LLVM to v13.0), which started adding Thanks for the workaround, but I don't understand why this was added as an opt-out instead of an opt-in feature. |
The C execution model is that there's a "-mexec-model=reactor" is the LLVM wasm backend's way to support this use case, with a design and implementation that actually anticipates being used this way. It supports calling exports without rerunning the constructor on each entrypoint. |
Yes, I understand that. What I'm saying is that the LLVM change (and the lack of support for |
Ultimately, I made a judgement call. It appears I misjudged how many people were using "handmade" WASI reactors here. |
Yeah, no worries. The landscape was very different 2 years ago when you originally authored that change... and it wouldn't even be an issue if Anyway, I mostly wanted to bring more attention to this issue and provide more context for other people to find, since I would definitely spend way more time tracking this down if @realuptime didn't open this issue. |
This is primarly a mechanism to deliver a workaround for a breaking change in Rust v1.56.0 (which updated LLVM to v13.0), which changed existing reactors into multi-entry commands, leading to performance degradation and/or unusable Proxy-Wasm plugins. See: WebAssembly/WASI#471 This is delivered as a macro to make it somehow compatible with the unstable "-Z wasi-exec-model=reactor" feature. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
This is primarly a mechanism to deliver a workaround for a breaking change in Rust v1.56.0 (which updated LLVM to v13.0), which changed existing reactors into multi-entry commands, leading to performance degradation and/or unusable Proxy-Wasm plugins. See: WebAssembly/WASI#471 This is delivered as a macro to make it somehow compatible with the unstable "-Z wasi-exec-model=reactor" feature. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Hey,
Why in the 14 release __wasm_call_ctors and __wasm_call_ctors is called after each export function call?
In the 12 release everything worked fine and all the variables and state was preserved, but 14 release broke this.
The text was updated successfully, but these errors were encountered: