Skip to content

Commit 4405ce4

Browse files
committed
Provide a default for __rust_alloc_error_handler_should_panic
1 parent 4f0dcf6 commit 4405ce4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

library/alloc/src/alloc.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
358358
#[cfg(not(no_global_oom_handling))]
359359
unsafe extern "Rust" {
360360
// This is the magic symbol to call the global alloc error handler. rustc generates
361-
// it if there is a `#[alloc_error_handler]`, or to the weak implementations below
361+
// it if there is an `#[alloc_error_handler]`, or to the weak implementations below
362362
// is called otherwise.
363363
#[rustc_std_internal_symbol]
364364
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
@@ -423,14 +423,16 @@ pub mod __alloc_error_handler {
423423
#[rustc_std_internal_symbol]
424424
#[linkage = "weak"]
425425
pub unsafe extern "Rust" fn __rust_alloc_error_handler(size: usize, _align: usize) -> ! {
426-
unsafe extern "Rust" {
427-
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
428-
// Its value depends on the -Zoom={panic,abort} compiler option.
429-
#[rustc_std_internal_symbol]
430-
static __rust_alloc_error_handler_should_panic: u8;
431-
}
432-
433-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
426+
// This symbol is normally overwritten by rustc next to __rust_alloc_error_handler.
427+
// However when skipping the allocator handler shim the value here is used which
428+
// corresponds to -Zoom=abort.
429+
// Its value depends on the -Zoom={panic,abort} compiler option.
430+
#[rustc_std_internal_symbol]
431+
#[linkage = "weak"]
432+
#[allow(non_upper_case_globals)]
433+
static __rust_alloc_error_handler_should_panic: u8 = 0;
434+
435+
if __rust_alloc_error_handler_should_panic != 0 {
434436
panic!("memory allocation of {size} bytes failed")
435437
} else {
436438
core::panicking::panic_nounwind_fmt(

0 commit comments

Comments
 (0)