@@ -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 ,
@@ -52,7 +53,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
52
53
match link_name. as_str ( ) {
53
54
// This matches calls to the foreign item `panic_impl`.
54
55
// The implementation is provided by the function with the `#[panic_handler]` attribute.
55
- "panic_impl" => {
56
+ name if name == mangle_internal_symbol ( * this . tcx , "rust_begin_unwind" ) => {
56
57
// We don't use `check_shim` here because we are just forwarding to the lang
57
58
// item. Argument count checking will be performed when the returned `Body` is
58
59
// called.
@@ -470,7 +471,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
470
471
}
471
472
472
473
// Rust allocation
473
- "__rust_alloc" | "miri_alloc" => {
474
+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc" )
475
+ || name == "miri_alloc" =>
476
+ {
474
477
let default = |this : & mut MiriInterpCx < ' tcx > | {
475
478
// Only call `check_shim` when `#[global_allocator]` isn't used. When that
476
479
// macro is used, we act like no shim exists, so that the exported function can run.
@@ -481,9 +484,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
481
484
this. check_rustc_alloc_request ( size, align) ?;
482
485
483
486
let memory_kind = match link_name. as_str ( ) {
484
- "__rust_alloc" => MiriMemoryKind :: Rust ,
485
487
"miri_alloc" => MiriMemoryKind :: Miri ,
486
- _ => unreachable ! ( ) ,
488
+ _ => MiriMemoryKind :: Rust ,
487
489
} ;
488
490
489
491
let ptr = this. allocate_ptr (
@@ -496,15 +498,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
496
498
} ;
497
499
498
500
match link_name. as_str ( ) {
499
- "__rust_alloc" => return this. emulate_allocator ( default) ,
500
501
"miri_alloc" => {
501
502
default ( this) ?;
502
503
return Ok ( EmulateItemResult :: NeedsReturn ) ;
503
504
}
504
- _ => unreachable ! ( ) ,
505
+ _ => return this . emulate_allocator ( default ) ,
505
506
}
506
507
}
507
- "__rust_alloc_zeroed" => {
508
+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_alloc_zeroed" ) => {
508
509
return this. emulate_allocator ( |this| {
509
510
// See the comment for `__rust_alloc` why `check_shim` is only called in the
510
511
// default case.
@@ -529,7 +530,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
529
530
this. write_pointer ( ptr, dest)
530
531
} ) ;
531
532
}
532
- "__rust_dealloc" | "miri_dealloc" => {
533
+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
534
+ || name == "miri_dealloc" =>
535
+ {
533
536
let default = |this : & mut MiriInterpCx < ' tcx > | {
534
537
// See the comment for `__rust_alloc` why `check_shim` is only called in the
535
538
// default case.
@@ -540,9 +543,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
540
543
let align = this. read_target_usize ( align) ?;
541
544
542
545
let memory_kind = match link_name. as_str ( ) {
543
- "__rust_dealloc" => MiriMemoryKind :: Rust ,
544
546
"miri_dealloc" => MiriMemoryKind :: Miri ,
545
- _ => unreachable ! ( ) ,
547
+ _ => MiriMemoryKind :: Rust ,
546
548
} ;
547
549
548
550
// No need to check old_size/align; we anyway check that they match the allocation.
@@ -554,17 +556,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
554
556
} ;
555
557
556
558
match link_name. as_str ( ) {
557
- "__rust_dealloc" => {
558
- return this. emulate_allocator ( default) ;
559
- }
560
559
"miri_dealloc" => {
561
560
default ( this) ?;
562
561
return Ok ( EmulateItemResult :: NeedsReturn ) ;
563
562
}
564
- _ => unreachable ! ( ) ,
563
+ _ => return this . emulate_allocator ( default ) ,
565
564
}
566
565
}
567
- "__rust_realloc" => {
566
+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_realloc" ) => {
568
567
return this. emulate_allocator ( |this| {
569
568
// See the comment for `__rust_alloc` why `check_shim` is only called in the
570
569
// default case.
0 commit comments