Support wasm exception handling for Emscripten target #112195
Open
Description
Currently the Rust Emscripten target supports js exception handling. I've been trying to get it to support also wasm exception handling. The patch to get it to exclusively use wasm exception handling is quite small. The following suffices:
Patch
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index a0a640473eb..cd88648911a 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -110,7 +110,7 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
}
if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
- add("-enable-emscripten-cxx-exceptions", false);
+ add("-wasm-enable-sjlj", false);
}
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 94acdea894b..2909401836d 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -2057,12 +2057,11 @@ fn add_order_independent_options(
}
if sess.target.os == "emscripten" {
- cmd.arg("-s");
- cmd.arg(if sess.panic_strategy() == PanicStrategy::Abort {
- "DISABLE_EXCEPTION_CATCHING=1"
+ if sess.panic_strategy() == PanicStrategy::Abort {
+ cmd.arg("-sDISABLE_EXCEPTION_CATCHING=1");
} else {
- "DISABLE_EXCEPTION_CATCHING=0"
- });
+ cmd.arg("-fwasm-exceptions");
+ }
}
if flavor == LinkerFlavor::PtxLinker {
I'm not sure what the best way is to add support for a choice between these two options.
@aheejin Is there any way to turn -enable-emscripten-cxx-exceptions
back off by adding another argument? It would be convenient to be able to inject -mllvm -disable-emscripten-cxx-exceptions -mllvm -wasm-enable-sjlj
and get wasm exceptions to work...