You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wasip3: Calls to __wasm_get_stack_pointer should directly invoke the imported context.get intrinsic #805
I'm extracting out an issue for my comment at #799 (comment). Currently the __wasm_get_stack_pointer function is a non-inlinable inline assembly function that, at the wasm level, calls the context.get intrinsic which is imported. This indirection is not boiled away by runtimes like Wasmtime by default, and I think it's something that we should strive to fix at the toolchain level. This may require changes in wasm-ld, or may require changes here, I'm not entirely sure.
@sbc100 I was wondering if I could get your thoughts on this and how best to solve this. Possible solutions I'm thinking of range from "do nothing" to new wasm-ld flags/configuration to new tooling conventions. The basic problem right now is that with wasip3 and --cooperative-threading the stack pointer is found via call $__wasm_get_stack_pointer and the goal is to hook this up directly to an import in the wasm module, but today that's not quite possible.
Today the workaround looks like this where __wasm_get_stack_pointer is a defined symbol which calls the desired symbol. The desired symbol today has both the wasm-level module name and field name configured to match the current wasm-component-ld conventions. I'd ideally like to be able to do something like:
wasm-ld: error: import module mismatch for symbol: __wasm_set_stack_pointer
>>> defined as env in /home/alex/code/wasi-libc/build/p3t/sysroot/lib/wasm32-wasip3/crt1-command.o
>>> defined as $root in libc-static.a(__libcall_thread_context.S.obj)
when combined with -Wl,--wrap=__wasm_get_stack_pointer produces the executable as-desired. One wrinkle here is that there's a segfault when producing a shared library and I'm not entirely sure what that's about. This also feels like a bit of an abuse of --wrap as well, hence my thinking of pursuing more options.
Another possible option would be a new flag to wasm-ld along the lines of --import=<symbol>=<module>,<name> or something like that. Personally I'm not a huge fan of wasm-ld-flag solutions because we'll also be required to pass them around, but it's a possibility.
Another possible option would be to add Clang flags/options to configure the import module and import name of this symbol when it's emitted in the wasm object itself. For example on WASIp3 targets it could default to something different than on other targets.
And, finally, the last possible option I can think of is to leave Clang as-is and update the component transform to recognize env and __wasm_get_stack_pointer to get hooked up correctly.
Do you have thoughts/opinions on how best we might go about this? I've hoped to try other alternatives like symbol aliases but I unfortunately wasn't able to get them working either.
Activity
alexcrichton commentedon Jul 8, 2026
@sbc100 I was wondering if I could get your thoughts on this and how best to solve this. Possible solutions I'm thinking of range from "do nothing" to new
wasm-ldflags/configuration to new tooling conventions. The basic problem right now is that with wasip3 and--cooperative-threadingthe stack pointer is found viacall $__wasm_get_stack_pointerand the goal is to hook this up directly to an import in the wasm module, but today that's not quite possible.Today the workaround looks like this where
__wasm_get_stack_pointeris a defined symbol which calls the desired symbol. The desired symbol today has both the wasm-level module name and field name configured to match the currentwasm-component-ldconventions. I'd ideally like to be able to do something like:but this fails with:
One possible solution is to use
--wrap:when combined with
-Wl,--wrap=__wasm_get_stack_pointerproduces the executable as-desired. One wrinkle here is that there's a segfault when producing a shared library and I'm not entirely sure what that's about. This also feels like a bit of an abuse of--wrapas well, hence my thinking of pursuing more options.Another possible option would be a new flag to
wasm-ldalong the lines of--import=<symbol>=<module>,<name>or something like that. Personally I'm not a huge fan ofwasm-ld-flag solutions because we'll also be required to pass them around, but it's a possibility.Another possible option would be to add Clang flags/options to configure the import module and import name of this symbol when it's emitted in the wasm object itself. For example on WASIp3 targets it could default to something different than on other targets.
And, finally, the last possible option I can think of is to leave Clang as-is and update the component transform to recognize
envand__wasm_get_stack_pointerto get hooked up correctly.Do you have thoughts/opinions on how best we might go about this? I've hoped to try other alternatives like symbol aliases but I unfortunately wasn't able to get them working either.
TartanLlama commentedon Jul 29, 2026
I think this might be the path of least resistance:
Can view it as something of a linker inlining operation to avoid the indirection
Route `__wasm_get_stack_pointer` as an import
Route `__wasm_get_stack_pointer` as an import (#856)
Support `__wasm_{g,s}et_{tls_base,stack_pointer}` in `wit-component` (b…