Skip to content

Support wasm exception handling for Emscripten target #112195

Description

@hoodmane

View all comments

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...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-panicArea: Panicking machineryO-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions