Skip to content

Commit 23d08ab

Browse files
authored
Asyncify JS library funcs under any namespace (#20223)
Previously any JS library funcs were passed to ASYNCIFY_IMPORTS under `env.` prefix. This can be problematic when implementing WASI functions using Asyncify, since we pass the same `wasmImports` object under both `env` and `wasi_snapshot_preview1` namespaces, and don't really differentiate under which namespace it will be called in the JS code. One existing example of this was `fd_sync` which already had to be hardcoded in `DEFAULT_ASYNCIFY_IMPORTS`, but there can be more examples both in the future as well as today in user's code that wants to override WASI functions with some Asyncify code. The simplest and most reliable fix to cover those scenarios is to do what JS already does and not differentiate between namespaces - that is, pass `*.{name}` instead of `env.{name}` so that function is correctly Asyncified no matter under which namespace it ends up imported in the Wasm module.
1 parent 104e3de commit 23d08ab

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

emcc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@
100100
'-install_name': True,
101101
}
102102

103-
DEFAULT_ASYNCIFY_IMPORTS = [
104-
'wasi_snapshot_preview1.fd_sync', '__wasi_fd_sync', '__asyncjs__*'
105-
]
103+
DEFAULT_ASYNCIFY_IMPORTS = ['__asyncjs__*']
106104

107105
DEFAULT_ASYNCIFY_EXPORTS = [
108106
'main',
@@ -1332,7 +1330,7 @@ def add_js_deps(sym):
13321330
for sym in settings.EXPORTED_RUNTIME_METHODS:
13331331
add_js_deps(shared.demangle_c_symbol_name(sym))
13341332
if settings.ASYNCIFY:
1335-
settings.ASYNCIFY_IMPORTS += ['env.' + x for x in js_info['asyncFuncs']]
1333+
settings.ASYNCIFY_IMPORTS += ['*.' + x for x in js_info['asyncFuncs']]
13361334

13371335
phase_calculate_system_libraries(state, linker_arguments, newargs)
13381336

src/library_wasi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ var WasiLibrary = {
562562
return {{{ cDefs.ENOSYS }}};
563563
#endif // SYSCALLS_REQUIRE_FILESYSTEM
564564
},
565+
fd_sync__async: true,
565566
};
566567

567568
for (var x in WasiLibrary) {

0 commit comments

Comments
 (0)