-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
runtime: give clear error when a wasmexport function is called before module initialization #71240
Comments
CC @cherrymui |
Marking as a release-blocker since this may be a bug in a new feature shipping in Go 1.24. |
The main issue is that the module must be initialized first, as documented in WASI reactor doc:
E.g. for the wazero version, applying this change
(along with fixing compilation errors like unused imports and missing some definitions), it works as expected. This issue is essentially another occurrence of #65199 (comment) . Perhaps we should make it fail clearly when an exported function is called before the runtime is initialized. I'm retargeting this issue for the error detection, and perhaps documentation. I'm also a bit surprised that the WASI runtimes don't call |
Based on @cherrymui's comment, removing release-blocker. It doesn't sound like this is necessarily a bug on our side? |
Looks like it's historical? I may check the behavior of other wasm runtimes later. |
@cherrymui, thank you for the response! Setting the proper startup function resolved the issue. I have a question about WASM in Go 1.24. The documentation and compiled WASM file don’t clarify how to allocate memory for writing shared data (e.g., JSON). In TinyGo, memory allocation is possible via the C-API (see example). It also allows exporting malloc and free to the host (example). Similarly, AssemblyScript exports __alloc and __free for memory allocation. |
The approaches I can think of are
cc @golang/wasm for more suggestions, and if there is a need for a more standard interface. |
This may need a new issue for malloc proposal? |
Maybe. Or we can just do it manually, and perhaps document common best practices on a wiki page. |
Change https://go.dev/cl/643115 mentions this issue: |
The use of the
in the above document. CC @mathetake for some context from the Wazero side. |
_initialize was marked as unstable abi. I guess that explains why not all runtimes provide support. |
Go version
go version go1.24rc1 linux/arm64
Output of
go env
in your module/workspace:What did you do?
I'm trying to call simple wasm exported Go function from
wasmtime
andwazero
runtimes.wasm.go
GOOS=wasip1 GOARCH=wasm go build -o out.wasm -buildmode=c-shared ./wasm/
wasmtime_main.go
wazero_main.go
What did you see happen?
I got
out of bounds memory access
onwazero
andwasmtime
runtimeWhat did you expect to see?
I expect function execution without any error.
The text was updated successfully, but these errors were encountered: