[SH] Changes to compile with wasi-sdk #1589
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Wasi-sdk is much less Unix-like than the environment provided by Emscripten and requires more profound changes for support.
Unix mman emulation requires:
-lwasi-emulated-mman
Unfortunately JS and C++ exceptions are both a mess.
Wasi-sdk does not support C++ exceptions yet.
We can live with that, since Hermes for the most part compiles with exceptions disabled anyway. However JSI relies on exceptions and it is part of the compiled library. To get things working one needs to rely on the following hack (which isn't included in this commit):
This causes any JSI exception to simply abort.
JS exceptions work fine with the bytecode interpreter, however code produced by the native backend relies on
setjmp/longjmp
. Alas,setjmp/longjmp
are not well supported by Wasm. This fact was hidden by Emscripten, which used its own JS shim and exceptions to implement them. That, however, does not work with standalone WASI.According to the Wasi-sdk documentation,
setjmp/longjmp
can be supported, using the Wasm exception handling proposal.This requires:
-mllvm -wasm-enable-sjlj
-lsetjmp
I was able to successfully compile the shermes-generated code to a Wasm binary with the following flags, however I was not able to find a single standalone runtime that was able to run it out of the box!
Wasmtime and Wasmer refused to load the module with the error "exceptions proposal not enabled". Iwasm failed to load it some error about Wasm operand stack.
I am sure that it is possible to either find or configure a Wasm runtime to support the exceptions proposal, but since none of the major runtimes support if out of the box, I consider it useless for now. Sadly.
I am sure v8 supports it, but what's the point of using v8 for this? First, v8 already supports JS, and second, Emscripten has that covered already.
There is an experimental followup commit which turns setjmp() into noop and longjmp() into abort(). That at least allows natively compiled JS to run, until the first exception...
Summary
Test Plan