From d315a3088462113adc2c0413dc4abfcbceb009e6 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 17 Oct 2024 13:00:35 +0200 Subject: [PATCH] Add support for wasm exception handling to Emscripten target --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 6 +++--- compiler/rustc_codegen_ssa/src/back/link.rs | 6 +++--- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_passes/src/weak_lang_items.rs | 6 +++--- library/panic_unwind/src/lib.rs | 5 +---- library/unwind/src/lib.rs | 5 +---- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 57936215ff130..89a96b3135332 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -108,9 +108,9 @@ unsafe fn configure_llvm(sess: &Session) { add("-wasm-enable-eh", false); } - if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind { - add("-enable-emscripten-cxx-exceptions", false); - } + // if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind { + // add("-enable-emscripten-cxx-exceptions", false); + // } // HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes // during inlining. Unfortunately these may block other optimizations. diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 34dc599e4fddd..dce37bce70be8 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2437,10 +2437,10 @@ fn add_order_independent_options( } if sess.target.os == "emscripten" { - cmd.cc_arg("-s").cc_arg(if sess.panic_strategy() == PanicStrategy::Abort { - "DISABLE_EXCEPTION_CATCHING=1" + cmd.cc_arg(if sess.panic_strategy() == PanicStrategy::Abort { + "-sDISABLE_EXCEPTION_CATCHING=1" } else { - "DISABLE_EXCEPTION_CATCHING=0" + "-fwasm-exceptions" }); } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index d91c0f0790d9d..773fe01389145 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -387,7 +387,7 @@ pub(crate) fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // exceptions. This means that the VM does the unwinding for // us pub fn wants_wasm_eh(sess: &Session) -> bool { - sess.target.is_like_wasm && sess.target.os != "emscripten" + sess.target.is_like_wasm } /// Returns `true` if this session's target will use SEH-based unwinding. diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 020128f29c59b..4c091269a7830 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -26,9 +26,9 @@ pub(crate) fn check_crate( if items.eh_personality().is_none() { items.missing.push(LangItem::EhPersonality); } - if tcx.sess.target.os == "emscripten" && items.eh_catch_typeinfo().is_none() { - items.missing.push(LangItem::EhCatchTypeinfo); - } + // if tcx.sess.target.os == "emscripten" && items.eh_catch_typeinfo().is_none() { + // items.missing.push(LangItem::EhCatchTypeinfo); + // } visit::Visitor::visit_crate(&mut WeakLangItemVisitor { tcx, items }, krate); diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 6cd4dffb8aa30..432f48eceed62 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -33,10 +33,7 @@ use core::any::Any; use core::panic::PanicPayload; cfg_if::cfg_if! { - if #[cfg(target_os = "emscripten")] { - #[path = "emcc.rs"] - mod imp; - } else if #[cfg(target_os = "hermit")] { + if #[cfg(target_os = "hermit")] { #[path = "hermit.rs"] mod imp; } else if #[cfg(target_os = "l4re")] { diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index 5a476d5843b2f..f55da872a20a4 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -4,10 +4,7 @@ #![feature(staged_api)] #![feature(strict_provenance)] #![cfg_attr(not(target_env = "msvc"), feature(libc))] -#![cfg_attr( - all(target_family = "wasm", not(target_os = "emscripten")), - feature(simd_wasm64, wasm_exception_handling_intrinsics) -)] +#![cfg_attr(all(target_family = "wasm"), feature(simd_wasm64, wasm_exception_handling_intrinsics))] #![allow(internal_features)] // Force libc to be included even if unused. This is required by many platforms.