WasmEdge
WasmEdge copied to clipboard
failed to instance.writeMemory: failed to Call allocate
Description
Current State
When running the reactr example with my compiled rust app as wasm I'm facing the error
❯ go run -tags wasmedge main.go
[2022-06-01 15:31:12.271] [error] wasmedge runtime failed: wasm function not found, Code: 0x05
[2022-06-01 15:31:12.271] [error] When executing function name: "allocate"
failed to execute Wasm Runnable: failed to instance.writeMemory: failed to Call allocate: failed to execute wasm func: wasm function not found
I can confirm the environment works with a hello world example.
Expected
Working Program
Environment
- Hardware Architecture: x86
- Operating system: Arch
Hi @chris-aeviator
According to the error messages, the WasmEdge is trying to call the function called allocate. However, this function is not found. Could you provide the wasm file for more details?
Hello, I have the same problem.
Here is the generated wasm file. I get the same error trying to call any of my exported functions: AddInts, myStringFunction, basicStrFunc and withStructArgs. engine-nojs.wasm.zip
Using wasmedge in reactor mode works with the Integer functions as expected. The error only occurs when I use the Go SDK with the bindgen helper lib.
The wasm was generated with tinygo version 0.23.0 darwin/amd64 (using go version go1.18.2 and LLVM version 14.0.0)
The wasmedge-go and wasmedge-bindgen libs have the following versions:
github.com/second-state/WasmEdge-go v0.10.0 github.com/second-state/wasmedge-bindgen v0.2.0
The following code can reproduce the "allocate" function not found error, when calling the bg.Execute() with any of the exported functions
`package main
import ( "github.com/second-state/WasmEdge-go/wasmedge" bindgen "github.com/second-state/wasmedge-bindgen/host/go" "os" )
func main() {
var conf = wasmedge.NewConfigure(wasmedge.WASI)
var store = wasmedge.NewStore()
var vm = wasmedge.NewVMWithConfigAndStore(conf, store)
wasi := vm.GetImportModule(wasmedge.WASI)
wasi.InitWasi(
os.Args[1:],
os.Environ(),
[]string{".:."},
)
err := vm.LoadWasmFile("bin/engine-nojs.wasm")
check(err)
err = vm.Validate()
check(err)
bg := bindgen.Instantiate(vm)
res, err := bg.Execute("AddInts", 10, 15)
check(err)
println(res[0].(int32))
}
func check(err error) { if err != nil { panic(err) } } `
Hi @DarumaDocker
Could you help with this? I would like to know where the allocate function comes from. And is this function available with tinygo?
@evilnoxx Now the wasmedge-bindgen only works with the wasm that is compiled from rust code.
The allocate function is defined here https://github.com/second-state/wasmedge-bindgen/blob/v0.2.0/bindgen/rust/wasm/src/lib.rs#L6. It helps to allocate memory for passing the arguments.
To my knowledge, the wasm file generated from tinygo includes malloc and free functions for managing memory, so if you want to use tinygo, I'm afraid you should write code manually to do what wasmedge-bindgen does for you.
I had a look at https://wasmedge.org/book/en/embed/go/memory.html and made my own binding functions. It's actually easier than it looks. Thank you for the guidance.