wasabi
wasabi copied to clipboard
resolveTableIdx gives wrong function index when using multiple wasm modules
Repository reproducing the problem: https://github.com/doehyunbaek/wasabi_multimodule_fidx
Currently, resolveTableIdx relies on name property of the function to resolve function index.
https://github.com/danleh/wasabi/blob/21a322b7faac9440b931762aae124ffa57d0fa17/crates/wasabi/js/runtime.js#L45-L51
This does not work when the function is imported from other WebAssembly instance and the index of the function in its imported module and the index of the function in its declared module is different, e.g.
module1.wat
(module
(func $private_func_0 (;0;) )
(func $private_func_1 (;1;) )
(func $shared_func (;2;) (param $0 i32) (result i32)
local.get $0
i32.const 1
i32.add
)
(export "shared_func" (func $shared_func))
)
module2.wat
(module
(import "env" "shared_func" (func $shared_func (;0;) ))
)
For module2, resolveTableIdx would resolve shared_func
to 2, which is different from expected behavior, which is 0.