-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
How to make C++ global compile to Wasm global? #11035
Comments
Clang doesn't currently support wasm globals in C/C++. Global variables in C/C++ live in linear memory and have address. This is fairly fundamental to the language. If you want mess with actual wasm globals would have use assembly in some way. I'll come back to you with an example of this if I can. Having said that, with the wasm backend you can export the address of the global directly: For example:
So here you can see that its possible export the address of Note that this did not work in the old fastcomp backend. Exporting a data symbol never worked there. Its also not yet a well known, used, or tested feature. |
It looks like we currently can't define new wasm globals, even in the assembly format. I opened a bug for that: https://bugs.llvm.org/show_bug.cgi?id=45742 |
You can now define new wasm globals using the assembly format if you need to. See: https://github.com/emscripten-core/emscripten/blob/master/system/lib/compiler-rt/stack_ops.s |
Late to the party, but the URL above is outdated, now it's https://github.com/emscripten-core/emscripten/blob/main/system/lib/compiler-rt/stack_ops.S |
This code:
Compiles to this:
It appears that the value of
myGlobal
is stored in linear memory, as opposed to an actual WebAssembly global. I would like to make it compile to an actual Wasm global, maybe like this:I know that Emscripten supports this because a separate project I have had variables compiled to globals, but it's a lot of code and I figured I'd ask here first before trying to go Sherlock-Holmes on that. 😄
The text was updated successfully, but these errors were encountered: