Skip to content

Commit bbbdd07

Browse files
authored
Rollup merge of rust-lang#143387 - dpaoliello:shouldpanicfn, r=bjorn3
Make __rust_alloc_error_handler_should_panic a function Fixes rust-lang#143253 `__rust_alloc_error_handler_should_panic` is a static but was being exported as a function. For most targets this doesn't matter, but Arm64EC Windows uses different decorations for exported variables vs functions, hence it fails to link when `-Z oom=abort` is enabled. We've had issues in the past with statics like this (see rust-lang#141061) but the tldr; is that Arm64EC needs symbols correctly exported as either a function or data, and data MUST and MUST ONLY be marked `dllimport` when the symbol is being imported from another binary, which is non-trivial to calculate for these compiler-generated statics. So, instead, the easiest thing to do is to make `__rust_alloc_error_handler_should_panic` a function instead. Since `__rust_alloc_error_handler_should_panic` isn't involved in any linking shenanigans, I've marked it as `AlwaysInline` with the hopes that the various backends will see that it is just returning a constant and perform the same optimizations as the previous implementation. r? `@bjorn3`
2 parents 67b3bce + fcbe668 commit bbbdd07

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ pub mod __alloc_error_handler {
429429
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
430430
// Its value depends on the -Zoom={panic,abort} compiler option.
431431
#[rustc_std_internal_symbol]
432-
static __rust_alloc_error_handler_should_panic: u8;
432+
fn __rust_alloc_error_handler_should_panic_v2() -> u8;
433433
}
434434

435-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
435+
if unsafe { __rust_alloc_error_handler_should_panic_v2() != 0 } {
436436
panic!("memory allocation of {size} bytes failed")
437437
} else {
438438
core::panicking::panic_nounwind_fmt(

std/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ fn default_alloc_error_hook(layout: Layout) {
349349
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
350350
// Its value depends on the -Zoom={panic,abort} compiler option.
351351
#[rustc_std_internal_symbol]
352-
static __rust_alloc_error_handler_should_panic: u8;
352+
fn __rust_alloc_error_handler_should_panic_v2() -> u8;
353353
}
354354

355-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
355+
if unsafe { __rust_alloc_error_handler_should_panic_v2() != 0 } {
356356
panic!("memory allocation of {} bytes failed", layout.size());
357357
} else {
358358
// This is the default path taken on OOM, and the only path taken on stable with std.

0 commit comments

Comments
 (0)