binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Support cross-module calls properly in the interpreter

Open kripken opened this issue 1 year ago • 2 comments

Right now some things like function and tag literals store a name. The Literal for a RefFunc stores the name of the function, for example. That means we may refer to the wrong thing if the value is used in another module with different internal names.

To fix this, we could add direct references from the Literal for a function to the Function it refers to. Maybe a good way to do that is to give it a shared_ptr<Function>, in which case we'd want to make Modules store their functions as a vector of such shared pointers and not unique_ptrs etc.

This may not be urgent as it is a long-standing issue. If we ever start to do testing of cross-module calls in our interpreter then we'd need to fix it.

Noticed here: https://github.com/WebAssembly/binaryen/pull/6814#discussion_r1705862342

kripken avatar Aug 07 '24 21:08 kripken

Another option would be to make such literals point to the Module the thing is in, and still refer to it by name.

kripken avatar Aug 07 '24 21:08 kripken

This affects not only cross-module calls but also in a single module when there are duplicate tags: imagine we import the same tag from JS twice, once as wasm name $a and once as $b. The Try instructions will refer to only one of them, as they refer to the name of the tag, so the behavior may not be right. For now we can work around this in the fuzzer by avoiding wasm files with such duplicate tag imports.

(This becomes an issue now that we import jstag and wasmtag, tags from JS; and specifically the Merge fuzzer can hit this if it generates two wasms, each importing the same tag.)

kripken avatar Feb 10 '25 20:02 kripken