-
Notifications
You must be signed in to change notification settings - Fork 204
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
NativeAOT-LLVM: runtime initialization workarounds #2359
Comments
Three comments:
|
1.You are right, I thought there was something, but its the runtime intitialization callback that is the blocker.
|
That is good news. I am actually wondering what is the purpose behind the somewhat involved initialization handshake. On the face of it, it could be replaced by, e. g. defining
Or some other equivalent scheme which avoids global |
Does C/C++ in wasm guarantee that this won't compile into a static constructor? Also, the variable would need to extern instead of static so that it is visible to the runtime. It should work otherwise. |
I believe so, for the configurations we target right now at least. I think PIC modes have more elaborate constraints, but they're also browser-only.
Indeed, fixed. |
Thanks I'll give this a try and report back. |
This was the blocker, but I was wrong to say it was the only problem. runtimelab/src/coreclr/gc/gcscan.cpp Line 21 in 7dace36
It should be set in the wasm function (func $__cxx_global_var_init.6 (type 6)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
global.get $__stack_pointer
local.set 0
i32.const 16
local.set 1
local.get 0
local.get 1
i32.sub
local.set 2
local.get 2
global.set $__stack_pointer
i32.const 1
local.set 3
local.get 2
local.get 3
i32.store offset=12
i32.const 1609420
(func $__wasm_call_ctors (type 6)
call $__wasilibc_initialize_environ_eagerly
call $__wasilibc_populate_preopens
call $_GLOBAL__sub_I_gccommon.cpp
call $_GLOBAL__sub_I_main.cpp
call $_GLOBAL__sub_I_yieldprocessornormalized.cpp
call $_GLOBAL__sub_I_gcenv.unix.cpp
call $_GLOBAL__sub_I_objecthandle.cpp
call $_GLOBAL__sub_I_gcscan.cpp
call $_GLOBAL__sub_I_gcwks.cpp
call $_GLOBAL__sub_I_gceventstatus.cpp) As it is not initialised to 1 this fails with
What do think about #2364 ? There's some stuff to clean up, the empty methods, but caliing This does appear to work for wasm components in a native lib, what they call reactor components
|
@yowl I think this one can be considered fixed? |
Yes, thanks, we implemented the problem function |
For Wasm components, there is no mechanism currently for a component's module, to have its initialization called, i.e for static c++ class constructors to run. Wasm tool chains put these in a
__wasm_call_ctors
method, which is invoked (for libraries) via_initialize
. However the component model does not export_initialize
and the wasmtime (I've not investigated other hosts) host cannot/does not invoke it. We therefore have a problem when an exported method is called as the runtime is not initialized. We can take advantage of the fact that Wasm memory is zero initialized to do something likeAs a hack for components. It could probably be extended to cover
wasm-wasi
programs , but as a temporary workaround until bytecodealliance/preview2-prototyping#99 is resolved, could there be a better solution?Thanks
The text was updated successfully, but these errors were encountered: