Simplify exception handling on wasm - #160067
Conversation
The 20 word requirement was likely from the JS EH ABI which we no longer support.
I can't think of any reason why any implementation of _Unwind_DeleteException would do anything different. This reduces the amount of special casing in the unwind crate for wasm32-unknown-unknown.
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I'm not sure if I understand. |
I'm aware. Is this a stable guarantee though? Or is it possible that a future libunwind version will do something else that would make us using llvm.wasm.throw directly be ABI incompatible with C++ code using libunwind _Unwind_RaiseException? For example storing a pointer to the exception in a global or setting an "unwinding" flag.
LLVM unfortunately doesn't support using arbitrary execption tags afaik and even if it did, I don't know if |
|
I'm unfamiliar with the requirements of this class of targets. If you know of someone that may be familiar, I'd suggest requesting them as the reviewer. Otherwise, |
|
@alexcrichton seems like the obvious choice for reviewer if he has bandwidth. @workingjubilee and @petrochenkov have also reviewed my PRs in this general area in the past. |
| uw::_Unwind_DeleteException(exception); | ||
| if let Some(exception_cleanup) = (*exception).exception_cleanup { | ||
| exception_cleanup(uw::_URC_FOREIGN_EXCEPTION_CAUGHT, exception); | ||
| } |
There was a problem hiding this comment.
Given the breadth of libunwind implementations, how confident are you that all implementations basically look like this? I'd expect some libunwind somewhere to do something weird for example which means that this might be a regression.
| target_os = "psp", | ||
| target_os = "solid_asp3", | ||
| all(target_vendor = "fortanix", target_env = "sgx"), | ||
| all(target_os = "wasi", panic = "unwind"), |
There was a problem hiding this comment.
Personally I feel it'll work best to "pretend like you're native" on WASI as opposed to having wasm-specific code here. You've already got concerns about possible future LLVM changes/evolutions, for example, and presumably libunwind would be kept in sync which means Rust wouldn't have to explicitly keep in sync.
Have you tested this on WASI targets to see if it works? I remember dealing with __cpp_exception is finnicky and difficult to precisely align.
There was a problem hiding this comment.
WASI is already not native in that we don't have a personality function on wasm and consequently all functions that the personality function would normally need to call are entirely missing on wasm.
You've already got concerns about possible future LLVM changes/evolutions, for example, and presumably libunwind would be kept in sync which means Rust wouldn't have to explicitly keep in sync.
We already would need to adapt to LLVM changes on wasm32-unknown-unknown. This PR merely makes that code used on all wasm targets.
Have you tested this on WASI targets to see if it works?
Not yet.
I remember dealing with __cpp_exception is finnicky and difficult to precisely align.
It should still be using __cpp_exception from libunwind.
There was a problem hiding this comment.
I'd recommend testing this change. "Should work" I have found often means "there's some subtle reason that this doesn't actually work", especially when it comes to things like this.
For WASI libunwind is already linked, so I think it's best to use it directly instead of going behind it to throw an exception.
I'm not sure if I understand Rust's configuration correctly. After this PR, if you are not going to use And how much of LLVM C/C++ libraries is the Rust EH using? As per |
_Unwind_Exceptionsize on Emscripten._Unwind_DeleteExceptionon all targets.llvm.wasm.throwon all wasm targets.Follow up to #159785