binaryen
binaryen copied to clipboard
Add --js-call-indirect option.
Currently Chrome and Firefox are unhelpful in diagnosing call_indirect errors, but when one occurs, a blank error print
RuntimeError: null function or function signature mismatch
is logged.
This challenge was discussed in https://github.com/emscripten-core/emscripten/issues/16126 and there were workarounds presented there:
- one can build with
-Wbad-function-cast -Wcast-function-typeor even-Werror=bad-function-cast -Werror=cast-function-type. However, in our huge codebase, we get tons of diagnostics from these in 3rd party code paths that are never exercised, or are false positives, so it does not help one to target an immediate bug scenario - and would not help see into issues where the function pointers to call_indirect are either null, or corrupted. - one can build with UBSAN:
-fsanitize=undefined. However unfortunately our codebase is too large, and we get alocal count too largeerror. - in Chromium bug entry https://bugs.chromium.org/p/chromium/issues/detail?id=1350384# , Chrome authors did help Chrome's debugger to do better prints, but unfortunately our codebase is too large that Chrome dies attempting to debug it.
Hence I would like to improve the debuggability of call_indirects from the toolchain side to help figure out when the function signature does not match, or when the function pointer is bad.
To do that, my idea is to try to route all call_indirects instead over to js_call_indirect_sig functions on the JS import side, which could do analysis on the calls, and then refer to the WebAssembly.Table (wasmTable object in Emscripten JS runtime).