This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Add Wasm SjLj option support for clang
ClosedPublic

Authored by aheejin on Aug 23 2021, 1:41 PM.

Details

Summary

This adds support for Wasm SjLj in clang. Also this sets the new
-mllvm -wasm-enable-eh option for Wasm EH.

Note there is a little unfortunate inconsistency there: Wasm EH is
enabled by a clang option -fwasm-exceptions, which sets
-mllvm -wasm-enable-eh in the backend options. It also sets
-exception-model=wasm but this is done in the common code.

Wasm SjLj doesn't have a clang-level option like -fwasm-exceptions.
-fwasm-exceptions was added because each exception model has its
corresponding -f***-exceptions, but I'm not sure if adding a new
option like -fwasm-sjlj or something is a good idea.

So the current plan is Emscripten sets -mllvm -wasm-enable-sjlj if
Wasm SJLj is enabled in its settings.js, as it does for Emscripten
EH/SjLj (it sets -mllvm -enable-emscripten-cxx-exceptions for
Emscripten EH and -mllvm -enable-emscripten-sjlj for Emscripten SjLj).
And setting this enables the exception handling feature, and also sets
-exception-model=wasm, but this time this is not done in the common
code so we do it ourselves. It also sets the multivalue feature, because
for longjmp we throw two values and catch two values: the setjmp
buffer and the return value. So catch instruction will produce two
values.

Also note that other exception models have 1-to-1 correspondance with
their -f***-exceptions flag and their -exception-model=*** flag, but
because we use -exception-model=wasm also for Wasm SjLj while
-fwasm-exceptions still means Wasm EH, there is also a little
inconsistency there, but I think it is manageable.

Also this adds various error checking and tests.

Diff Detail

Event Timeline

aheejin created this revision.Aug 23 2021, 1:41 PM
aheejin requested review of this revision.Aug 23 2021, 1:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2021, 1:41 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aheejin accepted this revision.Aug 23 2021, 1:42 PM
aheejin edited the summary of this revision. (Show Details)

Oh, I fortot I made this currently set +multivalue feature... Maybe we have to rethink that.

This revision is now accepted and ready to land.Aug 23 2021, 1:44 PM
aheejin planned changes to this revision.Aug 23 2021, 1:44 PM

Oh sorry I clicked the wrong button....

aheejin resigned from this revision.Aug 23 2021, 1:45 PM
aheejin removed a reviewer: aheejin.
dschuff accepted this revision.Aug 24 2021, 12:47 PM

As we discussed offline, I'll remove +multivalue part for now; it doesn't have reliable support in the Wasm LLVM backend and Binaryen yet.

aheejin updated this revision to Diff 368519.Aug 24 2021, 6:10 PM

Remove multivalue setting

This revision is now accepted and ready to land.Aug 24 2021, 6:10 PM
This revision was landed with ongoing or failed builds.Aug 24 2021, 6:13 PM
This revision was automatically updated to reflect the committed changes.