-
Notifications
You must be signed in to change notification settings - Fork 830
Add validations for imports during instantiation #8086
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
base: main
Are you sure you want to change the base?
Conversation
4c82930 to
9c0a77c
Compare
44c5834 to
62b613b
Compare
9c0a77c to
760c35a
Compare
62b613b to
bb0d612
Compare
3920f0c to
766d753
Compare
1f212af to
1368f6a
Compare
1368f6a to
cb635ed
Compare
cb635ed to
35d3f13
Compare
35d3f13 to
abb3c33
Compare
abb3c33 to
08cdd58
Compare
|
Will run this through the fuzzer as well before merging |
| trap((std::stringstream() | ||
| << "importGlobals: unknown import: " << import->module.str << "." | ||
| << import->name.str) | ||
| .str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know about this nice pattern for stringstream 😄
|
|
||
| virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); } | ||
|
|
||
| virtual void trap(std::string_view why) { WASM_UNREACHABLE("unimp"); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need two trap forms? This does not need to be fast. How about making them both std::string?
| Name name; | ||
| }; | ||
|
|
||
| // Trap if the importable's export's kind doesn't match `kind`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Trap if the importable's export's kind doesn't match `kind`. | |
| // Verify that a given Importable, which is exported from a module, is | |
| // actually exported with the proper kind from there. |
This might not be better but I had to read the existing one a few times... maybe being more verbose is clearer?
| return true; | ||
| } | ||
|
|
||
| bool isSubType(const Table& other) { return Table::isSubType(*this, other); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to put logic like this in ir/, so that we can keep wasm.h shorter. This might fit in memory-utils.h, table-utils.h etc?
ctor-eval doesn't have access to imports and previously didn't have any special handling for this. Globals would fail to import (https://github.com/WebAssembly/binaryen/blob/main/src/tools/wasm-ctor-eval.cpp#L247), which would prevent further evaluation (https://github.com/WebAssembly/binaryen/blob/main/src/tools/wasm-ctor-eval.cpp#L1451). This is why global-get-init.wast didn't optimize away even though it does nothing. We already stubbed out imports to "env". Change the code to create a stub module for all modules named in imports, so that instantiation is valid and evaluation can continue. This also unblocks #8086 which checks imports and requires them to exist during instantiation.
exact-func-import.wastfrom the testsuite repo, which now passes.ref_func.wastandtags.wastwhich also otherwise fail with the new validations.imports0,imports2,linking0,linking3and partially fixesimports,imports3andmemory64.As followups, we should improve the handling of the "spectest" module by implementing the implicit definition described by the spec, and we should add tracking for exact types of function re-exports so that we can enable import-time type checking for function types.