Skip to content

Commit e0138df

Browse files
authored
Avoid using WasmOffsetConverter when Module.instantiateWasm (#13425)
Module.instantiateWasm is a callback the user provides, and then the user is in change of fetching and instantiating the wasm. In that code path emscripten never sees the wasm binary, which means we cannot create a WasmOffsetConverter. With this PR we will not hang on startup, and we will still detect problems, but the sanitizer's own stack traces will mark function names as "unknown". That will limit the santizer's usefulness, but they do still detect errors, and the browser's own stack traces may be enough to diagnose things. Fixes #13424
1 parent 8da8de9 commit e0138df

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/preamble.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,24 @@ function createWasm() {
11201120
var exports = Module['instantiateWasm'](info, receiveInstance);
11211121
#if ASYNCIFY
11221122
exports = Asyncify.instrumentWasmExports(exports);
1123+
#endif
1124+
#if USE_OFFSET_CONVERTER
1125+
{{{
1126+
runOnMainThread(`
1127+
// We have no way to create an OffsetConverter in this code path since
1128+
// we have no access to the wasm binary (only the user does). Instead,
1129+
// create a fake one that reports we cannot identify functions from
1130+
// their binary offsets.
1131+
// Note that we only do this on the main thread, as the workers
1132+
// receive the OffsetConverter data from there.
1133+
wasmOffsetConverter = {
1134+
getName: function() {
1135+
return 'unknown-due-to-instantiateWasm';
1136+
}
1137+
};
1138+
removeRunDependency('offset-converter');
1139+
`)
1140+
}}}
11231141
#endif
11241142
return exports;
11251143
} catch(e) {

tests/test_browser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,8 +4155,12 @@ def test_binaryen_async(self):
41554155
self.btest_exit('binaryen_async.c', expected=1, args=common_args)
41564156

41574157
# Test that implementing Module.instantiateWasm() callback works.
4158-
def test_manual_wasm_instantiate(self):
4159-
self.compile_btest([path_from_root('tests/manual_wasm_instantiate.cpp'), '-o', 'manual_wasm_instantiate.js', '-s', 'BINARYEN'])
4158+
@parameterized({
4159+
'': ([],),
4160+
'asan': (['-fsanitize=address', '-s', 'INITIAL_MEMORY=128MB'],)
4161+
})
4162+
def test_manual_wasm_instantiate(self, args=[]):
4163+
self.compile_btest([path_from_root('tests/manual_wasm_instantiate.cpp'), '-o', 'manual_wasm_instantiate.js'] + args)
41604164
shutil.copyfile(path_from_root('tests', 'manual_wasm_instantiate.html'), 'manual_wasm_instantiate.html')
41614165
self.run_browser('manual_wasm_instantiate.html', 'wasm instantiation succeeded', '/report_result?1')
41624166

0 commit comments

Comments
 (0)