@@ -358,7 +358,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
358
358
359
359
match allocator_kind {
360
360
AllocatorKind :: Global => {
361
- // `__rust_*` is defined by `#[global_allocator]` if `#[global_allocator]` is used
361
+ // When `#[global_allocator]` is used, `__rust_*` is defined by the macro expansion
362
+ // of this attribute rather than generated by the allocator shim. As such we have
363
+ // to call the definition produced by `#[global_allocator]` instead of the shim like
364
+ // in the case of `#[global_allocator]` not existing. Somewhat unintuitively doing
365
+ // so is done by returning `NotSupported`.
362
366
return Ok ( EmulateByNameResult :: NotSupported ) ;
363
367
}
364
368
AllocatorKind :: Default => {
@@ -555,6 +559,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
555
559
// Rust allocation
556
560
"__rust_alloc" | "miri_alloc" => {
557
561
let default = |this : & mut MiriInterpCx < ' mir , ' tcx > | {
562
+ // Only call `check_shim` when `#[global_allocator]` isn't used. The macro
563
+ // expansion of `#[global_allocator]` defines this symbol and `check_shim`
564
+ // checks that there exists no definition of a shim.
558
565
let [ size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
559
566
let size = this. read_target_usize ( size) ?;
560
567
let align = this. read_target_usize ( align) ?;
@@ -587,6 +594,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
587
594
}
588
595
"__rust_alloc_zeroed" => {
589
596
return this. emulate_allocator ( |this| {
597
+ // See the comment for `__rust_alloc` why `check_shim` is only called in the
598
+ // default case.
590
599
let [ size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
591
600
let size = this. read_target_usize ( size) ?;
592
601
let align = this. read_target_usize ( align) ?;
@@ -610,6 +619,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
610
619
}
611
620
"__rust_dealloc" | "miri_dealloc" => {
612
621
let default = |this : & mut MiriInterpCx < ' mir , ' tcx > | {
622
+ // See the comment for `__rust_alloc` why `check_shim` is only called in the
623
+ // default case.
613
624
let [ ptr, old_size, align] =
614
625
this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
615
626
let ptr = this. read_pointer ( ptr) ?;
@@ -643,6 +654,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
643
654
}
644
655
"__rust_realloc" => {
645
656
return this. emulate_allocator ( |this| {
657
+ // See the comment for `__rust_alloc` why `check_shim` is only called in the
658
+ // default case.
646
659
let [ ptr, old_size, align, new_size] =
647
660
this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
648
661
let ptr = this. read_pointer ( ptr) ?;
0 commit comments