[Emscripten-EH] Implement __cxa_throw in terms of _Unwind_RaiseException - #27498
Conversation
5f0e9ae to
637ec5b
Compare
6dcdb9f to
4f4cd6d
Compare
|
I could potentially split this change up, land an NFC that just moves the old unwind code into its own file? Would that be useful? |
__cxa_throw in terms of _Unwind_RaiseException
Extract `_Unwind_*` functions and `uncaughtExceptionCount` / `exceptionLast` JS state from libcore.js and libexceptions.js into a dedicated `libunwind.js`. This new libunwind.js is included as long as wasm EH is not being used. Also, invert the dependency between `__cxa_throw` and `_Unwind_RaiseException` so that `__cxa_throw` now calls `_Unwind_RaiseException` rather than the other way around. This is important as it allows C programs (or rather non-C++ programs like Rust) to call `_Unwind_RaiseException` without linking as C++. Inspired by emscripten-core#27496
|
The reason we see a light code size saving here is because |
|
Funny how I can work on compilers for decades and not be aware of how/when libunwind function are linked / used... |
| $uncaughtExceptionCount: '0', | ||
| #if !DISABLE_EXCEPTION_CATCHING | ||
| $exceptionLast: null, | ||
| #endif |
There was a problem hiding this comment.
In libcxxabi native code (and thus in Wasm EH), managing information like uncaught exception count and last exception is done by libcxxabi, not libunwind. It is true in libcxxabi/libunwind that __cxa_throw calls _Unwind_RaiseException, but all exception status managing is done within libcxxabi. Wouldn't it be consistent to manage it within libexceptions.js and leave libunwind simple?
There was a problem hiding this comment.
Sure, we can make it consistent in that way. I'll make a followup PR.
It turns out the libunwind symbols are supposed to always be available, enen non-C++ programs. This means that
__cxa_throwshould be implemented in terms of_Unwind_RaiseExceptionand not the other way around._Unwind_Resume__cxa_throwand other exception-handling APIs in terms of the lower level_UnwindAPI.Inspired by #27496