Skip to content
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

wasm_instance_new_with_args_ex failed: WASM module instantiate failed: failed to link import table (js, tbl) #3881

Open
ltshddx opened this issue Oct 24, 2024 · 1 comment

Comments

@ltshddx
Copy link

ltshddx commented Oct 24, 2024

I wrote a simple demo to run table-related WebAssembly:
https://github.com/mdn/webassembly-examples/blob/main/js-api-examples/table2.wat

However, a trap occurred during wasm_instance_new_with_args:
"wasm_instance_new_with_args_ex failed: WASM module instantiate failed: failed to link import table (js, tbl)"

How to avoid this error

@TianlongLiang
Copy link
Contributor

The issue is due to the handling of WebAssembly's import and table in different environments.

In your module, you are importing a table from the JavaScript environment ("js" namespace), which is typical for running WebAssembly in a browser. The import expects a table to be provided by the host environment (in this case, JavaScript), which is automatically handled by the browser's WebAssembly environment.

However, standalone WebAssembly runtimes like WAMR or Wasmtime don't automatically provide such an import from a JavaScript host, and they don't have a default environment like a browser. Instead, you need to explicitly define the imported table and any associated functions in the host application(or just change it to a non-import one like below).

(module
  (table 2 anyfunc)
  (func $f42 (result i32) i32.const 42)
  (func $f83 (result i32) i32.const 83)
  (elem (i32.const 0) $f42 $f83)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants