From 942f4ee464d4386cff63dfc067f817cbe2a05cd3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:24:50 +0200 Subject: [PATCH 1/3] Use 2 word unwinder_private_data on Emscripten The 20 word requirement was likely from the JS EH ABI which we no longer support. --- library/unwind/src/types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/unwind/src/types.rs b/library/unwind/src/types.rs index 413cd677fe7e0..7634052c93f33 100644 --- a/library/unwind/src/types.rs +++ b/library/unwind/src/types.rs @@ -36,7 +36,6 @@ pub const unwinder_private_data_size: usize = cfg_select! { target_arch = "s390x" => 2, any(target_arch = "sparc", target_arch = "sparc64") => 2, any(target_arch = "riscv64", target_arch = "riscv32") => 2, - all(target_family = "wasm", target_os = "emscripten") => 20, target_family = "wasm" => 2, target_arch = "hexagon" => 5, any(target_arch = "loongarch32", target_arch = "loongarch64") => 2, From 1698d4dcfd6454e079553f85e0a856af99d87efe Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:37:57 +0200 Subject: [PATCH 2/3] Inline _Unwind_DeleteException 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. --- library/panic_unwind/src/gcc.rs | 4 +++- library/unwind/src/libunwind.rs | 1 - library/unwind/src/wasm.rs | 6 ------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/library/panic_unwind/src/gcc.rs b/library/panic_unwind/src/gcc.rs index adcbe5170623c..1abce9ead9db6 100644 --- a/library/panic_unwind/src/gcc.rs +++ b/library/panic_unwind/src/gcc.rs @@ -86,7 +86,9 @@ pub(crate) unsafe fn cleanup(ptr: *mut u8) -> Box { unsafe { let exception = ptr as *mut uw::_Unwind_Exception; if (*exception).exception_class != RUST_EXCEPTION_CLASS { - uw::_Unwind_DeleteException(exception); + if let Some(exception_cleanup) = (*exception).exception_cleanup { + exception_cleanup(uw::_URC_FOREIGN_EXCEPTION_CAUGHT, exception); + } super::__rust_foreign_exception(); } diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index bfa6b1b33008f..b2931b162ab16 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -37,7 +37,6 @@ unsafe extern "C-unwind" { pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; } unsafe extern "C" { - pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception); pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void; pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; diff --git a/library/unwind/src/wasm.rs b/library/unwind/src/wasm.rs index ef961ae6410a4..ded261d6a0221 100644 --- a/library/unwind/src/wasm.rs +++ b/library/unwind/src/wasm.rs @@ -28,12 +28,6 @@ core::arch::global_asm!( pub use crate::types::*; -pub unsafe fn _Unwind_DeleteException(exception: *mut _Unwind_Exception) { - if let Some(exception_cleanup) = unsafe { (*exception).exception_cleanup } { - exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, exception); - } -} - pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code { // This implementation is only used for `wasm*-unknown-unknown` targets. Such targets are not // guaranteed to support exceptions, and they default to `-C panic=abort`. Because an unknown From 59594a6bf304d427373c64ec1b3c254165a6c236 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 24 Jul 2026 15:46:13 +0200 Subject: [PATCH 3/3] Use our own _Unwind_RaiseException definition on all wasm targets --- library/unwind/src/lib.rs | 15 +++++++++------ library/unwind/src/libunwind.rs | 7 ------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index 3725375a713dc..6612438b3a7d3 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -18,6 +18,11 @@ cfg_select! { target_env = "msvc" => { // Windows MSVC no extra unwinder support needed } + target_family = "wasm" => { + mod types; + mod wasm; + pub use wasm::*; + } any( target_os = "l4re", target_os = "none", @@ -32,18 +37,12 @@ cfg_select! { target_os = "psp", target_os = "solid_asp3", all(target_vendor = "fortanix", target_env = "sgx"), - all(target_os = "wasi", panic = "unwind"), target_os = "xous", ) => { mod libunwind; pub use libunwind::*; mod types; } - target_family = "wasm" => { - mod types; - mod wasm; - pub use wasm::*; - } _ => { // no unwinder on the system! // - os=none ("bare metal" targets) @@ -215,6 +214,10 @@ cfg_select! { #[link(name = "gcc_s")] unsafe extern "C" {} +#[cfg(all(target_os = "wasi", panic = "unwind"))] +#[link(name = "unwind")] +unsafe extern "C" {} + #[cfg(all(target_os = "windows", target_env = "gnu", target_abi = "llvm"))] #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "unwind", cfg(not(target_feature = "crt-static")))] diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index b2931b162ab16..35870d7db0391 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -26,13 +26,6 @@ pub enum _Unwind_Context {} all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), link(name = "unwind", kind = "static", modifiers = "-bundle") )] -// Explicitly link the `unwind` library on WASI targets. -// -// This is provided in the self-contained sysroot for WASI targets by default. -// Note that Rust defaults to `-Cpanic=abort` on WASI targets meaning that this -// doesn't end up getting used by default, but this does mean that with -// `-Zbuild-std` this'll automatically link it in. -#[cfg_attr(target_os = "wasi", link(name = "unwind"))] unsafe extern "C-unwind" { pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; }