@@ -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 ,
@@ -455,7 +456,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
455456 }
456457
457458 // Rust allocation
458- "__rust_alloc" | "miri_alloc" => {
459+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc" )
460+ || name == "miri_alloc" =>
461+ {
459462 let default = |this : & mut MiriInterpCx < ' tcx > | {
460463 // Only call `check_shim` when `#[global_allocator]` isn't used. When that
461464 // 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> {
466469 this. check_rustc_alloc_request ( size, align) ?;
467470
468471 let memory_kind = match link_name. as_str ( ) {
469- "__rust_alloc" => MiriMemoryKind :: Rust ,
470472 "miri_alloc" => MiriMemoryKind :: Miri ,
471- _ => unreachable ! ( ) ,
473+ _ => MiriMemoryKind :: Rust ,
472474 } ;
473475
474476 let ptr = this. allocate_ptr (
@@ -481,15 +483,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
481483 } ;
482484
483485 match link_name. as_str ( ) {
484- "__rust_alloc" => return this. emulate_allocator ( default) ,
485486 "miri_alloc" => {
486487 default ( this) ?;
487488 return Ok ( EmulateItemResult :: NeedsReturn ) ;
488489 }
489- _ => unreachable ! ( ) ,
490+ _ => return this . emulate_allocator ( default ) ,
490491 }
491492 }
492- "__rust_alloc_zeroed" => {
493+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_alloc_zeroed" ) => {
493494 return this. emulate_allocator ( |this| {
494495 // See the comment for `__rust_alloc` why `check_shim` is only called in the
495496 // default case.
@@ -514,7 +515,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
514515 this. write_pointer ( ptr, dest)
515516 } ) ;
516517 }
517- "__rust_dealloc" | "miri_dealloc" => {
518+ name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
519+ || name == "miri_dealloc" =>
520+ {
518521 let default = |this : & mut MiriInterpCx < ' tcx > | {
519522 // See the comment for `__rust_alloc` why `check_shim` is only called in the
520523 // default case.
@@ -525,9 +528,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
525528 let align = this. read_target_usize ( align) ?;
526529
527530 let memory_kind = match link_name. as_str ( ) {
528- "__rust_dealloc" => MiriMemoryKind :: Rust ,
529531 "miri_dealloc" => MiriMemoryKind :: Miri ,
530- _ => unreachable ! ( ) ,
532+ _ => MiriMemoryKind :: Rust ,
531533 } ;
532534
533535 // 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> {
539541 } ;
540542
541543 match link_name. as_str ( ) {
542- "__rust_dealloc" => {
543- return this. emulate_allocator ( default) ;
544- }
545544 "miri_dealloc" => {
546545 default ( this) ?;
547546 return Ok ( EmulateItemResult :: NeedsReturn ) ;
548547 }
549- _ => unreachable ! ( ) ,
548+ _ => return this . emulate_allocator ( default ) ,
550549 }
551550 }
552- "__rust_realloc" => {
551+ name if name == mangle_internal_symbol ( * this . tcx , "__rust_realloc" ) => {
553552 return this. emulate_allocator ( |this| {
554553 // See the comment for `__rust_alloc` why `check_shim` is only called in the
555554 // default case.
0 commit comments