Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

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

Copy link
Contributor Author

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.

} else {
let new_args = [];
for(let i = 0; i < sig.length; i++){
if(sig[i + 1] === "j"){
new_args.push((BigInt(args[i] || 0) | (BigInt(args[i+1] || 0) << BigInt(32))));
i++;
} else {
new_args.push(args[i]);
}
}
let result = wasmTable.get(ptr).apply(null, new_args);
if(sig[0] !== "j"){
return result;
}
setTempRet0(Number(result >> BigInt(32)));
return Number(result & BigInt(0xffffffff));
}
#else
return dynCallLegacy(sig, ptr, args);
#endif
}
#endif
#if ASSERTIONS
Expand Down