From 68f063bf3fb9ca7dc585e18250ba7a75f40a245f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 14 May 2022 02:46:46 +0100 Subject: [PATCH 1/2] Use Rust ABI for `__rust_start_panic` and `_{rdl,rg}_oom` --- library/alloc/src/alloc.rs | 4 ++-- library/panic_abort/src/lib.rs | 2 +- library/panic_unwind/src/lib.rs | 2 +- library/std/src/panicking.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 39f8f1d5a0ec7..da61ff1e7512a 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -398,13 +398,13 @@ pub mod __alloc_error_handler { // if there is no `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! { + pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { panic!("memory allocation of {size} bytes failed") } // if there is an `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! { + pub unsafe fn __rg_oom(size: usize, align: usize) -> ! { let layout = unsafe { Layout::from_size_align_unchecked(size, align) }; extern "Rust" { #[lang = "oom"] diff --git a/library/panic_abort/src/lib.rs b/library/panic_abort/src/lib.rs index 2bcb3182a7bf2..0a1aa7bb3c833 100644 --- a/library/panic_abort/src/lib.rs +++ b/library/panic_abort/src/lib.rs @@ -30,7 +30,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen // "Leak" the payload and shim to the relevant abort on the platform in question. #[rustc_std_internal_symbol] -pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 { +pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 { // Android has the ability to attach a message as part of the abort. #[cfg(target_os = "android")] android::android_set_abort_message(_payload); diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 7f05c82ac284b..4ae5f8ae4468d 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -104,7 +104,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any // Entry point for raising an exception, just delegates to the platform-specific // implementation. #[rustc_std_internal_symbol] -pub unsafe extern "C-unwind" fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 { +pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 { let payload = Box::from_raw((*payload).take_box()); imp::panic(payload) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index f1baf077580e6..9b045980d4543 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -47,7 +47,7 @@ extern "C" { } #[allow(improper_ctypes)] -extern "C-unwind" { +extern "Rust" { /// `payload` is passed through another layer of raw pointers as `&mut dyn Trait` is not /// FFI-safe. `BoxMeUp` lazily performs allocation only when needed (this avoids allocations /// when using the "abort" panic runtime). From fbb3c19e0347b21d84b428981e930401b7f81b76 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 14 May 2022 02:49:12 +0100 Subject: [PATCH 2/2] Use re-export instead of inline wrapper in libunwind This ensures that there are no calls to `C-unwind` function in libunwind. --- library/unwind/src/libunwind.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index 432628613f586..7b78bda424bb0 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -264,10 +264,7 @@ if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; } - #[inline] - pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code { - _Unwind_SjLj_RaiseException(exc) - } + pub use _Unwind_SjLj_RaiseException as _Unwind_RaiseException; } } // cfg_if!