From 2ecbdc1b3223eb9acda60014946738cd8e87f7e5 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 10:04:02 -0700 Subject: [PATCH 1/4] Don't use __gxx_personality_v0 in panic_unwind on emscripten target This resolves #85821. See also the discussion here: https://github.com/emscripten-core/emscripten/issues/17128 The consensus seems to be that rust_eh_personality is never invoked. I patched __gxx_personality_v0 to log invocations and then ran various panic tests and it was never called, so this analysis matches what seems to happen in practice. This replaces the definition with an abort, modeled on the structured exception handling implementation. --- library/panic_unwind/src/emcc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index 12f0fe9c3c3a9..e3a32a5581eaf 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -105,6 +105,11 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void { } } + +// This is required by the compiler to exist (e.g., it's a lang item), but it's +// never actually called by the compiler. Emscripten EH doesn't use a +// personality function at all, it instead uses __cxa_find_matching_catch. +// Wasm error handling would use __gxx_personality_wasm0. #[lang = "eh_personality"] unsafe extern "C" fn rust_eh_personality( version: c_int, @@ -113,7 +118,7 @@ unsafe extern "C" fn rust_eh_personality( exception_object: *mut uw::_Unwind_Exception, context: *mut uw::_Unwind_Context, ) -> uw::_Unwind_Reason_Code { - __gxx_personality_v0(version, actions, exception_class, exception_object, context) + core::intrinsics::abort() } extern "C" { From 0ec3174e3ea682aac2633b38e75db0e94eabe5c9 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 10:25:18 -0700 Subject: [PATCH 2/4] Fix formatter --- library/panic_unwind/src/emcc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index e3a32a5581eaf..790aacdbe455d 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -105,7 +105,6 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void { } } - // This is required by the compiler to exist (e.g., it's a lang item), but it's // never actually called by the compiler. Emscripten EH doesn't use a // personality function at all, it instead uses __cxa_find_matching_catch. From 46a3f0feb6bee316a682bd8b62d3a0a0f2647619 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 16:31:21 -0700 Subject: [PATCH 3/4] Remove __gxx_personality_v0 declaration --- library/panic_unwind/src/emcc.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index 790aacdbe455d..c458af10aad19 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -129,11 +129,4 @@ extern "C" { tinfo: *const TypeInfo, dest: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void, ) -> !; - fn __gxx_personality_v0( - version: c_int, - actions: uw::_Unwind_Action, - exception_class: uw::_Unwind_Exception_Class, - exception_object: *mut uw::_Unwind_Exception, - context: *mut uw::_Unwind_Context, - ) -> uw::_Unwind_Reason_Code; } From d2d205d0a87861aaa2ce3a39a65afc35a2beb55a Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 9 Jun 2022 09:50:26 -0700 Subject: [PATCH 4/4] Add underscores to rust_eh_personality arguments to mark them as unused --- library/panic_unwind/src/emcc.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index c458af10aad19..1ee69ff9cb285 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -111,11 +111,11 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void { // Wasm error handling would use __gxx_personality_wasm0. #[lang = "eh_personality"] unsafe extern "C" fn rust_eh_personality( - version: c_int, - actions: uw::_Unwind_Action, - exception_class: uw::_Unwind_Exception_Class, - exception_object: *mut uw::_Unwind_Exception, - context: *mut uw::_Unwind_Context, + _version: c_int, + _actions: uw::_Unwind_Action, + _exception_class: uw::_Unwind_Exception_Class, + _exception_object: *mut uw::_Unwind_Exception, + _context: *mut uw::_Unwind_Context, ) -> uw::_Unwind_Reason_Code { core::intrinsics::abort() }