From 622a394da15ba7c599eef41ca1daf743c3c23913 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 17 Aug 2021 22:34:15 +0100 Subject: [PATCH 1/2] Allow handle_alloc_error to unwind --- library/alloc/src/alloc.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 66ef92558d8b5..09adbff2b3558 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -344,7 +344,6 @@ extern "Rust" { // This is the magic symbol to call the global alloc error handler. rustc generates // it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the // default implementations below (`__rdl_oom`) otherwise. - #[rustc_allocator_nounwind] fn __rust_alloc_error_handler(size: usize, align: usize) -> !; } @@ -362,7 +361,6 @@ extern "Rust" { /// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html #[stable(feature = "global_alloc", since = "1.28.0")] #[cfg(all(not(no_global_oom_handling), not(test)))] -#[rustc_allocator_nounwind] #[cold] pub fn handle_alloc_error(layout: Layout) -> ! { unsafe { From f4545cc4ea6ceeb8f6383c73440aa293b4f0a922 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Mon, 4 Oct 2021 02:02:33 +0100 Subject: [PATCH 2/2] Mark __rgl_oom and __rd_oom as "C-unwind" --- library/alloc/src/alloc.rs | 4 ++-- library/alloc/src/lib.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 09adbff2b3558..306cea4e32c99 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -383,13 +383,13 @@ pub mod __alloc_error_handler { // if there is no `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C" fn __rdl_oom(size: usize, _align: usize) -> ! { + pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! { panic!("memory allocation of {} bytes failed", size) } // if there is an `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C" fn __rg_oom(size: usize, align: usize) -> ! { + pub unsafe extern "C-unwind" 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/alloc/src/lib.rs b/library/alloc/src/lib.rs index 600862c4224a1..da224a61adcf7 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -152,6 +152,7 @@ #![cfg_attr(test, feature(test))] #![feature(unboxed_closures)] #![feature(unsized_fn_params)] +#![feature(c_unwind)] // // Rustdoc features: #![feature(doc_cfg)]