@@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
7
7
use rustc_middle:: mir;
8
8
use rustc_middle:: ty;
9
9
use rustc_span:: Symbol ;
10
+ use rustc_symbol_mangling:: mangle_internal_symbol;
10
11
use rustc_target:: {
11
12
abi:: { Align , Size } ,
12
13
spec:: abi:: Abi ,
@@ -455,7 +456,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
455
456
}
456
457
457
458
// Rust allocation
458
- "__rust_alloc" | "miri_alloc" => {
459
+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc" )
460
+ || name == "miri_alloc" =>
461
+ {
459
462
let default = |this : & mut MiriInterpCx < ' tcx > | {
460
463
// Only call `check_shim` when `#[global_allocator]` isn't used. When that
461
464
// macro is used, we act like no shim exists, so that the exported function can run.
@@ -466,9 +469,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
466
469
this. check_rustc_alloc_request ( size, align) ?;
467
470
468
471
let memory_kind = match link_name. as_str ( ) {
469
- "__rust_alloc" => MiriMemoryKind :: Rust ,
470
472
"miri_alloc" => MiriMemoryKind :: Miri ,
471
- _ => unreachable ! ( ) ,
473
+ _ => MiriMemoryKind :: Rust ,
472
474
} ;
473
475
474
476
let ptr = this. allocate_ptr (
@@ -481,15 +483,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
481
483
} ;
482
484
483
485
match link_name. as_str ( ) {
484
- "__rust_alloc" => return this. emulate_allocator ( default) ,
485
486
"miri_alloc" => {
486
487
default ( this) ?;
487
488
return Ok ( EmulateItemResult :: NeedsReturn ) ;
488
489
}
489
- _ => unreachable ! ( ) ,
490
+ _ => return this . emulate_allocator ( default ) ,
490
491
}
491
492
}
492
- "__rust_alloc_zeroed" => {
493
+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_alloc_zeroed" ) => {
493
494
return this. emulate_allocator ( |this| {
494
495
// See the comment for `__rust_alloc` why `check_shim` is only called in the
495
496
// default case.
@@ -514,7 +515,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
514
515
this. write_pointer ( ptr, dest)
515
516
} ) ;
516
517
}
517
- "__rust_dealloc" | "miri_dealloc" => {
518
+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
519
+ || name == "miri_dealloc" =>
520
+ {
518
521
let default = |this : & mut MiriInterpCx < ' tcx > | {
519
522
// See the comment for `__rust_alloc` why `check_shim` is only called in the
520
523
// default case.
@@ -525,9 +528,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
525
528
let align = this. read_target_usize ( align) ?;
526
529
527
530
let memory_kind = match link_name. as_str ( ) {
528
- "__rust_dealloc" => MiriMemoryKind :: Rust ,
529
531
"miri_dealloc" => MiriMemoryKind :: Miri ,
530
- _ => unreachable ! ( ) ,
532
+ _ => MiriMemoryKind :: Rust ,
531
533
} ;
532
534
533
535
// No need to check old_size/align; we anyway check that they match the allocation.
@@ -539,17 +541,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
539
541
} ;
540
542
541
543
match link_name. as_str ( ) {
542
- "__rust_dealloc" => {
543
- return this. emulate_allocator ( default) ;
544
- }
545
544
"miri_dealloc" => {
546
545
default ( this) ?;
547
546
return Ok ( EmulateItemResult :: NeedsReturn ) ;
548
547
}
549
- _ => unreachable ! ( ) ,
548
+ _ => return this . emulate_allocator ( default ) ,
550
549
}
551
550
}
552
- "__rust_realloc" => {
551
+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_realloc" ) => {
553
552
return this. emulate_allocator ( |this| {
554
553
// See the comment for `__rust_alloc` why `check_shim` is only called in the
555
554
// default case.
0 commit comments