Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Nov 8, 2019

The dynamic loader needs to place the original wasm functions in the table, so that other modules can call them. The JS-legalized versions will have the wrong types for indirect calls.

To implement this, binaryen's legalization pass exports illegal functions twice, once legalized for JS, and once as orig$ plus the original name. This PR makes the loader use those.

Fixes #9562

Depends on WebAssembly/binaryen#2427 to roll first.

@kripken kripken requested a review from sbc100 November 8, 2019 21:49
@kripken
Copy link
Member Author

kripken commented Nov 12, 2019

The dependencies have all rolled, and looks like tests all pass.

src/support.js Outdated
assert(parts.length == 3)
var name = parts[1];
var sig = parts[2];
var legalized = sig.indexOf('j') >= 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume 'j' means i64?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, j is i64. I'll add a comment.

sym = 'orig$' + sym;
}
#if WASM_BACKEND
sym = '_' + sym;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use asmjs_mangle here? Also does the mangling happen before the orig$ .. i.e. is it _orig$foo or orig$foo. Above it looks like your remove the mangled before pretending orig$.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pre-existing code, but I think asm_mangle in python makes sense (where it checks if the _ is needed or not, which it isn't for dynCall etc.) while here, all we have are exported symbols at the C level, which does not include things like dynCall etc. that are only for JS.

@kripken
Copy link
Member Author

kripken commented Nov 13, 2019

Thanks, I pushed updates for the feedback.

@kripken kripken merged commit 6df46b6 into incoming Nov 14, 2019
@delete-merged-branch delete-merged-branch bot deleted the mod64b branch November 14, 2019 00:04
kripken added a commit that referenced this pull request Nov 19, 2019
#9810 mostly fixed i64 pointers in MAIN_MODULE, but it
turns out that a corner case was a function that is illegal
only due to its return value.

fixes #9850
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
…en-core#9810)

The dynamic loader needs to place the original wasm functions in the table, so
that other modules can call them. The JS-legalized versions will have the wrong
types for indirect calls.

To implement this, binaryen's legalization pass exports illegal functions twice,
once legalized for JS, and once as orig$ plus the original name. This PR makes
the loader use those.

Fixes emscripten-core#9562
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
…-core#9855)

emscripten-core#9810 mostly fixed i64 pointers in MAIN_MODULE, but it
turns out that a corner case was a function that is illegal
only due to its return value.

fixes emscripten-core#9850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-s MAIN_MODULE=1 + upstream + function pointer calls using i64 => TypeError: cannot pass i64 to or from JS

3 participants