-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix dyncall and dynamic linking with -sMAIN_MODULE=1 #16693
Conversation
We don't compile with WASM_BIGINT so if there is a 64 bit integer in the dynamic call, Emscripten tries to call a legalizer wrapper. These legalizer wrappers are only generated in the main module so sometimes a side module tries to call a wrapper that doesn't exist. This adds an extra handler in that case.
@@ -3139,7 +3139,29 @@ LibraryManager.library = { | |||
// part of thier signature, so we rely the dynCall functions generated by | |||
// wasm-emscripten-finalize | |||
if (sig.includes('j')) { | |||
#if MAIN_MODULE | |||
if(Module["dynCall_" + sig]){ | |||
return dynCallLegacy(sig, ptr, args); |
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.
Hmm, reading this I'm confused as to why dynCall_*
would only sometimes exist when DYNCALLS
. That is, we should have returned from line 3135 above, I think? Is this related to this issue from the description:
"Sometimes side modules need dyncalls with 64 bit types that are missing the dynCall wrappers from the main module."
If so, could we include dyncalls in side modules? cc @sbc100
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 will try to come up with a MWE soon. It occurred on this branch:
pyodide/pyodide#2378
with the signature viij
but I have seen it before.
could we include dyncalls in side modules? cc @sbc100
Yeah I suspect you can do that, perhaps it's a better solution? BigInt
support is much broader than BigInt64Array
so I don't mind this. But yeah it would be harder for me to come up with this.
Can you explain why you don't want to do use |
Can you share the backtrace of there the failing call to dynCall is coming from? Am I correct in assuming its coming from a function generated by emscripten/src/library_dylink.js Lines 251 to 255 in ec1cbf0
|
Yeah: we don't want -sWASM_BIGINT because it doesn't work on Safari 14 and
we haven't made up our mind that we are officially not supporting Safari 14.
…On Tue, Apr 12, 2022, 10:44 Sam Clegg ***@***.***> wrote:
Can you share the backtrace of there the failing call to dynCall is coming
from? Am I correct in assuming its coming from a function generated by
createInvokeFunction in response of an invoke_xx import? here:
https://github.com/emscripten-core/emscripten/blob/ec1cbf026077cd42f6247a21f2d9a4fe507cbda3/src/library_dylink.js#L251-L255
—
Reply to this email directly, view it on GitHub
<#16693 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCVWKUNOSCTLAR66YFXSR3VEWY7ZANCNFSM5TBC4D3Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sorry, can you explain a little more. I'm confused because this patch seems to rely on wasm/BigInt integration (you are passing BigInts as arguments and receiving them as return values to/from wasm functions) which is what I thought that the |
According to caniuse, Safari 14.0 has BigInt but not BigInt64Array. So we
are happy to assume the former is present. -sWASM_BIGINT assumes both.
…On Tue, Apr 12, 2022, 10:57 Sam Clegg ***@***.***> wrote:
Yeah: we don't want -sWASM_BIGINT because it doesn't work on Safari 14 and
we haven't made up our mind that we are officially not supporting Safari 14.
Sorry, can you explain a little more. I'm confused because this patch
seems to rely on wasm/BigInt integration (you are passing BigInts as
arguments and receiving them as return values to/from wasm functions) which
is what I thought that the WASM_BIGINT assumed. Or is WASM_BIGINT
assuming something more that just this?
—
Reply to this email directly, view it on GitHub
<#16693 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCVWKVY7VQY7Z7H6TPFNHTVEW2OZANCNFSM5TBC4D3Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
In that case can we fix this by making |
That would be great! Yeah if you just checked if |
Grepping for I think we could do this, though, with a little work. We could add a "BigInt but without BigInt[U]64Array" mode in which a custom acorn optimizer pass is run that rewrites |
Could we write a BigInt64Array polyfill that kicks in only when targeting older safari versions? |
Yeah that sounds like the best idea. It should be quite simple. |
We would probably also want to bump the default safari version to 15 (perhaps at least when bitint is enabled).. so that folks have to explicitly opt into the polyfil. |
Maybe there is JS magic that I am unaware of, but I'm not sure a polyfill can work. We need to replace |
Apparently that is possible yes: https://stackoverflow.com/questions/1711357/how-would-you-overload-the-operator-in-javascript |
Closed in favor of #17103. |
As discussed in #16693, -s WASM_BIGINT requires both BigInt (present since Safari 14.0) and BigInt64Array (present since Safari 15.0). Thus, users that want to target Safari 14.0 need a polyfill for BigInt64Array, which this adds.
-sWASM_BIGINT always crashes on startup if BigInt64Array is missing whereas
this would only break certain rare side modules that hit this code path if
BigInt is missing. But I think we are already assuming that BigInt is
present.
On Tue, Apr 12, 2022, 11:02 Hood Chatham ***@***.***>
wrote:
… According to caniuse, Safari 14.0 has BigInt but not BigInt64Array. So we
are happy to assume the former is present. -sWASM_BIGINT assumes both.
On Tue, Apr 12, 2022, 10:57 Sam Clegg ***@***.***> wrote:
> Yeah: we don't want -sWASM_BIGINT because it doesn't work on Safari 14
> and we haven't made up our mind that we are officially not supporting
> Safari 14.
>
> Sorry, can you explain a little more. I'm confused because this patch
> seems to rely on wasm/BigInt integration (you are passing BigInts as
> arguments and receiving them as return values to/from wasm functions) which
> is what I thought that the WASM_BIGINT assumed. Or is WASM_BIGINT
> assuming something more that just this?
>
> —
> Reply to this email directly, view it on GitHub
> <#16693 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACCVWKVY7VQY7Z7H6TPFNHTVEW2OZANCNFSM5TBC4D3Q>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Sometimes side modules need dyncalls with 64 bit types that are missing the
dynCall
wrappers from the main module. In this case, we can fall back to trying to use BigInt. I don't want to compile with-sWASM_BIGINT
BigInt64Array
has under a year of support in Safari.BigInt
has been supported in Safari since v14.0 so I'm not as worried about this. In any case, this works in strictly more cases than it would before.