-
Notifications
You must be signed in to change notification settings - Fork 47
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
resolveTableIdx gives wrong function index when using multiple wasm modules #45
Comments
Thanks, great analysis and very concise reproducer! :) This is indeed a bug. Besides the multi-module case you layed out here, I'm wondering what will happen for functions that were created with the WebAssembly.Function API (still a proposal, but already implemented in some engines/browsers). I bet it's wrong there too. How do we solve this? Basically, how to map back from a table entry to a function index in the local module? Even more problematic: Can we even always map back? E.g., what happens if we have a Wasm module that exports its table and the host inserts (via So the proper solution is probably:
WDYT? |
Mhm, maybe even simpler: one can just have a Map from function references to index, and either prefill at initialization time with all references in the table or lazily initialize it with the "slowpath" code from above. |
I like this approach best, will tinker around with this in mind.
So it's a funcref --> fidx instead of fidx --> funcref as above? I think this is better, although I'm not sure we can construct such a map having funcref as a key. Will try and update. |
temporary fix for danleh/wasabi#45
temporary fix for danleh/wasabi#45
This works! I played around with the sola-st/wasm-r3@1004e65 commit and it seems it works well at least for the Wasm-R3's use case. I want to generalize this solution and upstream to Wasabi but I think it is better to merge any outstanding changes(esp. #41) and build on top of that, WDYT? |
Yes, sounds good (merging first, unless fixing this is urgent) |
Repository reproducing the problem: https://github.com/doehyunbaek/wasabi_multimodule_fidx
Currently, resolveTableIdx relies on name property of the function to resolve function index.
wasabi/crates/wasabi/js/runtime.js
Lines 45 to 51 in 21a322b
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
module2.wat
For module2, resolveTableIdx would resolve
shared_func
to 2, which is different from expected behavior, which is 0.The text was updated successfully, but these errors were encountered: