Skip to content

Commit 60d514e

Browse files
committed
Provide a default for __rust_alloc_error_handler_should_panic
1 parent 2561dae commit 60d514e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

library/alloc/src/alloc.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
357357
#[cfg(not(no_global_oom_handling))]
358358
extern "Rust" {
359359
// This is the magic symbol to call the global alloc error handler. rustc generates
360-
// it if there is a `#[alloc_error_handler]`, or to the weak implementations below
360+
// it if there is an `#[alloc_error_handler]`, or to the weak implementations below
361361
// is called otherwise.
362362
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
363363
}
@@ -425,13 +425,16 @@ pub mod __alloc_error_handler {
425425
#[rustc_std_internal_symbol]
426426
#[linkage = "weak"]
427427
pub unsafe extern "Rust" fn __rust_alloc_error_handler(size: usize, _align: usize) -> ! {
428-
extern "Rust" {
429-
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
430-
// Its value depends on the -Zoom={panic,abort} compiler option.
431-
static __rust_alloc_error_handler_should_panic: u8;
432-
}
433-
434-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
428+
// This symbol is normally overwritten by rustc next to __rust_alloc_error_handler.
429+
// However when skipping the allocator handler shim the value here is used which
430+
// corresponds to -Zoom=abort.
431+
// Its value depends on the -Zoom={panic,abort} compiler option.
432+
#[rustc_std_internal_symbol]
433+
#[linkage = "weak"]
434+
#[allow(non_upper_case_globals)]
435+
static __rust_alloc_error_handler_should_panic: u8 = 0;
436+
437+
if __rust_alloc_error_handler_should_panic != 0 {
435438
panic!("memory allocation of {size} bytes failed")
436439
} else {
437440
core::panicking::panic_nounwind_fmt(

0 commit comments

Comments
 (0)