diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-07-04 16:22:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 16:22:36 +0200 |
| commit | 2faf66d091b071a0c3ceb510a184b33f2214a7b2 (patch) | |
| tree | d4787f6cf323111142d8f0a13e6fb93dbd2a239a /library/alloc | |
| parent | 18b374d5a7d947ef4c817280991da8d0ce207d31 (diff) | |
| parent | 2b22d0f0d2b9d0d71025065db93058e34f846600 (diff) | |
| download | rust-2faf66d091b071a0c3ceb510a184b33f2214a7b2.tar.gz rust-2faf66d091b071a0c3ceb510a184b33f2214a7b2.zip | |
Rollup merge of #143387 - dpaoliello:shouldpanicfn, r=bjorn3
Make __rust_alloc_error_handler_should_panic a function Fixes rust-lang/rust#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/rust#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`
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/alloc.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index b4176e9c1f4..c9b98fa4e5a 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -429,10 +429,10 @@ pub mod __alloc_error_handler { // This symbol is emitted by rustc next to __rust_alloc_error_handler. // Its value depends on the -Zoom={panic,abort} compiler option. #[rustc_std_internal_symbol] - static __rust_alloc_error_handler_should_panic: u8; + fn __rust_alloc_error_handler_should_panic_v2() -> u8; } - if unsafe { __rust_alloc_error_handler_should_panic != 0 } { + if unsafe { __rust_alloc_error_handler_should_panic_v2() != 0 } { panic!("memory allocation of {size} bytes failed") } else { core::panicking::panic_nounwind_fmt( |
