From ffd8cb87bf342488b56fe8e0238b0e556e813601 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Feb 2023 00:12:25 +0100 Subject: [PATCH] Fix review comments Co-authored-by: Ralf Jung --- src/tools/miri/src/shims/foreign_items.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 167370ef4a8..57fce448b60 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -359,10 +359,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { match allocator_kind { AllocatorKind::Global => { // When `#[global_allocator]` is used, `__rust_*` is defined by the macro expansion - // of this attribute rather than generated by the allocator shim. As such we have - // to call the definition produced by `#[global_allocator]` instead of the shim like - // in the case of `#[global_allocator]` not existing. Somewhat unintuitively doing - // so is done by returning `NotSupported`. + // of this attribute. As such we have to call an exported Rust function, + // and not execute any Miri shim. Somewhat unintuitively doing so is done + // by returning `NotSupported`, which triggers the `lookup_exported_symbol` + // fallback case in `emulate_foreign_item`. return Ok(EmulateByNameResult::NotSupported); } AllocatorKind::Default => { @@ -559,9 +559,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { // Rust allocation "__rust_alloc" | "miri_alloc" => { let default = |this: &mut MiriInterpCx<'mir, 'tcx>| { - // Only call `check_shim` when `#[global_allocator]` isn't used. The macro - // expansion of `#[global_allocator]` defines this symbol and `check_shim` - // checks that there exists no definition of a shim. + // Only call `check_shim` when `#[global_allocator]` isn't used. When that + // macro is used, we act like no shim exists, so that the exported function can run. let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?; let size = this.read_target_usize(size)?; let align = this.read_target_usize(align)?;