@@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
77use rustc_middle:: mir;
88use rustc_middle:: ty;
99use rustc_span:: Symbol ;
10+ use rustc_symbol_mangling:: mangle_internal_symbol;
1011use rustc_target:: {
1112 abi:: { Align , Size } ,
1213 spec:: abi:: Abi ,
@@ -52,7 +53,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5253 match link_name. as_str ( ) {
5354 // This matches calls to the foreign item `panic_impl`.
5455 // 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" ) => {
5657 // We don't use `check_shim` here because we are just forwarding to the lang
5758 // item. Argument count checking will be performed when the returned `Body` is
5859 // called.
@@ -470,7 +471,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
470471 }
471472
472473 // Rust allocation
473- "__rust_alloc" | "miri_alloc" => {
474+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc" )
475+ || name == "miri_alloc" =>
476+ {
474477 let default = |this : & mut MiriInterpCx < ' tcx > | {
475478 // Only call `check_shim` when `#[global_allocator]` isn't used. When that
476479 // 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> {
481484 this. check_rustc_alloc_request ( size, align) ?;
482485
483486 let memory_kind = match link_name. as_str ( ) {
484- "__rust_alloc" => MiriMemoryKind :: Rust ,
485487 "miri_alloc" => MiriMemoryKind :: Miri ,
486- _ => unreachable ! ( ) ,
488+ _ => MiriMemoryKind :: Rust ,
487489 } ;
488490
489491 let ptr = this. allocate_ptr (
@@ -496,15 +498,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
496498 } ;
497499
498500 match link_name. as_str ( ) {
499- "__rust_alloc" => return this. emulate_allocator ( default) ,
500501 "miri_alloc" => {
501502 default ( this) ?;
502503 return Ok ( EmulateItemResult :: NeedsReturn ) ;
503504 }
504- _ => unreachable ! ( ) ,
505+ _ => return this . emulate_allocator ( default ) ,
505506 }
506507 }
507- "__rust_alloc_zeroed" => {
508+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_alloc_zeroed" ) => {
508509 return this. emulate_allocator ( |this| {
509510 // See the comment for `__rust_alloc` why `check_shim` is only called in the
510511 // default case.
@@ -529,7 +530,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
529530 this. write_pointer ( ptr, dest)
530531 } ) ;
531532 }
532- "__rust_dealloc" | "miri_dealloc" => {
533+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
534+ || name == "miri_dealloc" =>
535+ {
533536 let default = |this : & mut MiriInterpCx < ' tcx > | {
534537 // See the comment for `__rust_alloc` why `check_shim` is only called in the
535538 // default case.
@@ -540,9 +543,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
540543 let align = this. read_target_usize ( align) ?;
541544
542545 let memory_kind = match link_name. as_str ( ) {
543- "__rust_dealloc" => MiriMemoryKind :: Rust ,
544546 "miri_dealloc" => MiriMemoryKind :: Miri ,
545- _ => unreachable ! ( ) ,
547+ _ => MiriMemoryKind :: Rust ,
546548 } ;
547549
548550 // 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> {
554556 } ;
555557
556558 match link_name. as_str ( ) {
557- "__rust_dealloc" => {
558- return this. emulate_allocator ( default) ;
559- }
560559 "miri_dealloc" => {
561560 default ( this) ?;
562561 return Ok ( EmulateItemResult :: NeedsReturn ) ;
563562 }
564- _ => unreachable ! ( ) ,
563+ _ => return this . emulate_allocator ( default ) ,
565564 }
566565 }
567- "__rust_realloc" => {
566+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_realloc" ) => {
568567 return this. emulate_allocator ( |this| {
569568 // See the comment for `__rust_alloc` why `check_shim` is only called in the
570569 // default case.
0 commit comments