Fix emulated function pointer cast exporting #6939
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Emulated function pointers is the mode where we do calls from JS using the wasm Table, which is how we currently do dynamic linking in both asm.js and wasm (in asm.js, this mode creates something like a wasm Table on the outside of the asm.js, and calls that). Emulated function pointer casts is where we assume a function pointer type may be cast in a weird way, so we make sure indirect calls work even with the wrong argument number or type, sort of like native platforms do. The "trick" we use for that is to use i64s for all values, and cast as necessary. For this mode, we export every single function's function table index, as we need those from JS - we can't call them as wasm exports, as they return i64. So we call dynCall of the right signature, and then inside wasm we cast the i64 to what we want, and return that to JS.
The bug here is that we mixed those two modes up - we exported all the function pointers for the former mode, when we just need it in the latter. So this just changes up a few ifdefs to the proper mode. Note the effect on the metadce test - a dynamic library now has far fewer exports and is smaller.