-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add Wasm exception support #198
base: main
Are you sure you want to change the base?
Conversation
Do we need a wasm-specific macro here, or can we just use
Similarly, do we need a wasm-specific option here, or can we just use
I expect we will indeed need to build two copies of libc++, as many wasm engines today don't support the EH proposal yet, so we don't want make existing libc++ users incompatible with those engines. |
The implementation of the personality function in upstream libc++abi has two major code paths: one for DWARF exceptions (where the unwinder IP is the actual instruction pointer) and one for SjLj exceptions (where the unwinder IP is a landing pad index). The semantics required from the personality by Wasm exceptions is mostly similar to that of SjLj exceptions, but it diverges in a few important places because SjLj exceptions are two-phase and Wasm exceptions are single-phase. The Also, this macro fits well into the existing series of predefined macros in the frontend, so I don't see a reason to avoid defining it. (I was surprised to see it's not already there.)
The
That makes sense. Do you have any preferences on how to switch between the builds of libc++/libc++abi? I'd probably patch the compiler driver to pick different versions of the libraries depending on whether |
I've compiled all of the YoWASP tools with the patched SDK and I've tested yosys, nextpnr-ecp5, ecppack (a somewhat diverse set of codebases, the last two including boost). I confirmed that exception handling works just fine. |
That sounds reasonable to me. Our existing builds use the name "libc++.a" for a library which does not have exception support, but I think if someone tries to mix a new clang with exception support with an old libc++.a without it, it would fail at link time anyway, so I don't think it'll be a problem in practice. |
d5f07cb
to
8f09a60
Compare
I'm working on a project called Blam Creation Suite and I require the exception support with wasi. I've created a fork of llvm and a fork of the wasi-sdk based off @whitequark 's code and I've merged them to the latest version and updated the makefile. I haven't checked over in detail what changes were made to llvm-project, I simply did a blind merge and prayed as there was little conflicts. https://github.com/ChimpsAtSea/wasi-sdk There is also an issue I've raised with llvm-project regarding a lack of the Support for |
8f09a60
to
32df2d4
Compare
Rebased on top of latest wasi-sdk. |
Talking to @sunfishcode and @sbc100 about this:
Overall we all wanted to include exception support in wasi-sdk especially as the proposal reaches phase 4; it just make take a bit of time to get there. |
Wasm EH's libcxxabi/libunwind changes have now been upstreamed: |
@aheejin o/ Fantastic work!! I'm really excited about it, too! |
They can be enabled now with an experimental flag in both Node.js and Deno, and they work out of the box in Firefox. 👀 |
Yes, the proposal has certainly advanced over the last year; maybe it is now time to revisit this for wasi-sdk. |
🎉 Looking forward to being able to use exceptions! |
This PR is an early preview. I'm interested in feedback on the general approach!
First, a demo:
Most of the changes here are in my LLVM fork. Although the commits are attributed to me, this is mostly a port of the work done in Emscripten by @aheejin.
Items that should be resolved before I could see this PR as mergeable:
__USING_WASM_EXCEPTIONS__
to predefined macros should be upstreamed.-lunwind
to the linker command line when called with-fwasm-exceptions
.XXX whitequark
that are#ifdef
'd out. The first of these is not disabled in Emscripten but necessary for unwinding to work, and the second is removed in Emscripten without indicating why. This should be investigated.__gxx_personality_wasm0
and LLVM uses__gxx_wasm_personality_v0
. (This works because on WebAssembly libunwind calls the personality function directly. That's also something I suspect is planned to be changed, though I do not know for sure.)-flto
builds.Something should be discussed is whether the build process in wasi-sdk should be altered so that it builds two copies of libc++ and libc++abi; one with
-fwasm-exceptions
and one without. Otherwise, any code that pulls in libc++, even that which is built with-fno-exceptions
, will require libunwind to be linked in, and code size will be larger. However, as far as I know, this requires either more compiler driver changes or complicates the build process for downstream code, so I'm not sure how desirable it is.