Commit 5f73782
authored
Use RuntimeError in abort() before module instantiation (#18664)
We decided use a trap for `abort` function in case of Wasm EH in order
to prevent infinite-looping (#16910).
https://github.com/emscripten-core/emscripten/blob/44b2c2a1ecad39c534e14179acb49419dfee528b/src/preamble.js#L472-L474
The short reason is, in Wasm EH `RuntimeError` is treated as a foreign
exception and caught by `catch_all`, so you try to abort the program and
throw a `RuntimeError`, but it is caught by some `catch_all` used in the
cleanup (=destructors, etc) code, causing the program to continue to
run.
`__trap` is defined in compiler-rt and exported when Wasm EH is enabled.
This has worked so far, but in case we fail to instantiate a Wasm
module and call `abort` because of it, we don't have access to the
imported `Module['asm']['__trap']`, because `Module['asm']` has not been
set:
https://github.com/emscripten-core/emscripten/blob/44b2c2a1ecad39c534e14179acb49419dfee528b/src/preamble.js#L848
So the `abort` call will end like this:
```console
TypeError: Cannot read properties of undefined (reading '__trap')
at ___trap (/usr/local/google/home/aheejin/test/gl84/exported_api.js:5152:34)
at abort (/usr/local/google/home/aheejin/test/gl84/exported_api.js:892:5)
at /usr/local/google/home/aheejin/test/gl84/exported_api.js:1172:5
```
which may not be the worst thing in the world given that we are crashing
anyway, but not the situation we intended.
This PR lets us throw `RuntimeError` in case we don't have the wasm
module instantiated and have access to `Module['asm']['__trap']`. This
is OK even with Wasm EH because we haven't been running the module,
there's no risk of infinite-looping we tried to prevent in #16910.1 parent 87083ed commit 5f73782
1 file changed
+13
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | | - | |
475 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
476 | 487 | | |
477 | 488 | | |
478 | 489 | | |
| |||
483 | 494 | | |
484 | 495 | | |
485 | 496 | | |
486 | | - | |
487 | 497 | | |
488 | 498 | | |
489 | 499 | | |
| |||
0 commit comments