Skip to content

Commit 9f681d8

Browse files
authored
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`
2 parents 5bed6f3 + 4041c0c commit 9f681d8

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/shims/extern_static.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Provides the `extern static` that this platform expects.
22
3-
use rustc_symbol_mangling::mangle_internal_symbol;
4-
53
use crate::*;
64

75
impl<'tcx> MiriMachine<'tcx> {
@@ -45,15 +43,6 @@ impl<'tcx> MiriMachine<'tcx> {
4543

4644
/// Sets up the "extern statics" for this machine.
4745
pub fn init_extern_statics(ecx: &mut MiriInterpCx<'tcx>) -> InterpResult<'tcx> {
48-
// "__rust_alloc_error_handler_should_panic"
49-
let val = ecx.tcx.sess.opts.unstable_opts.oom.should_panic();
50-
let val = ImmTy::from_int(val, ecx.machine.layouts.u8);
51-
Self::alloc_extern_static(
52-
ecx,
53-
&mangle_internal_symbol(*ecx.tcx, "__rust_alloc_error_handler_should_panic"),
54-
val,
55-
)?;
56-
5746
if ecx.target_os_is_unix() {
5847
// "environ" is mandated by POSIX.
5948
let environ = ecx.machine.env_vars.unix().environ();

src/shims/foreign_items.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
615615
// This is a no-op shim that only exists to prevent making the allocator shims instantly stable.
616616
let [] = this.check_shim(abi, CanonAbi::Rust, link_name, args)?;
617617
}
618+
name if name == this.mangle_internal_symbol("__rust_alloc_error_handler_should_panic_v2") => {
619+
// Gets the value of the `oom` option.
620+
let [] = this.check_shim(abi, CanonAbi::Rust, link_name, args)?;
621+
let val = this.tcx.sess.opts.unstable_opts.oom.should_panic();
622+
this.write_int(val, dest)?;
623+
}
618624

619625
// C memory handling functions
620626
"memcmp" => {

tests/pass/alloc-access-tracking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22
#![no_main]
3-
//@compile-flags: -Zmiri-track-alloc-id=19 -Zmiri-track-alloc-accesses -Cpanic=abort
4-
//@normalize-stderr-test: "id 19" -> "id $$ALLOC"
3+
//@compile-flags: -Zmiri-track-alloc-id=18 -Zmiri-track-alloc-accesses -Cpanic=abort
4+
//@normalize-stderr-test: "id 18" -> "id $$ALLOC"
55
//@only-target: linux # alloc IDs differ between OSes (due to extern static allocations)
66

77
extern "Rust" {

0 commit comments

Comments
 (0)