Skip to content

Miri does not support swapping out core #4512

@gamozolabs

Description

@gamozolabs

I'm working on a custom core called corps which breaks some compatibility with Rust. While I realize I'm way off in the weeds and don't expect much support from things, I ran into an issue with miri where it resolves core::ffi::c_ulong as well as core::ascii::escape_default unconditionally, which causes miri to not work in my custom core.

"Fixing" the issue (temporarily for me) was quite a simple fix, and if miri was much further from working in my environment I wouldn't really bother making an issue.

The issues are in chunk_size in src/tools/miri/src/concurrency/cpu_affinity.rs which uses core::ffi::c_ulong, and the "sentinel" value checked in src/tools/miri/src/eval.rs of core::ascii::escape_default.

This is the diff I used to make miri work in my environment. Obviously, this is a hack workaround where I just remove the check if libcore is present in eval, and hard-code a c_ulong size. But I imagine that there would be a way to do these things through lang items which are accessible regardless of the path names.

diff --git a/src/tools/miri/src/concurrency/cpu_affinity.rs b/src/tools/miri/src/concurrency/cpu_affinity.rs
index 9583de5a483..0b6cd95a10c 100644
--- a/src/tools/miri/src/concurrency/cpu_affinity.rs
+++ b/src/tools/miri/src/concurrency/cpu_affinity.rs
@@ -32,10 +32,11 @@ pub fn new<'tcx>(cx: &impl LayoutOf<'tcx>, cpu_count: u32) -> Self {
         this
     }
 
-    pub fn chunk_size<'tcx>(cx: &impl LayoutOf<'tcx>) -> u64 {
+    pub fn chunk_size<'tcx>(_cx: &impl LayoutOf<'tcx>) -> u64 {
         // The actual representation of the CpuAffinityMask is [c_ulong; _].
-        let ulong = helpers::path_ty_layout(cx, &["core", "ffi", "c_ulong"]);
-        ulong.size.bytes()
+        //let ulong = helpers::path_ty_layout(cx, &["core", "ffi", "c_ulong"]);
+        //ulong.size.bytes()
+        8
     }
 
     fn set<'tcx>(&mut self, cx: &impl LayoutOf<'tcx>, cpu: usize) {
diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs
index 4c531a8d1f5..ca179a8a486 100644
--- a/src/tools/miri/src/eval.rs
+++ b/src/tools/miri/src/eval.rs
@@ -9,7 +9,7 @@
 
 use rustc_abi::ExternAbi;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_hir::def::Namespace;
+//use rustc_hir::def::Namespace;
 use rustc_hir::def_id::DefId;
 use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutCx};
 use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -329,6 +329,7 @@ pub fn create_ecx<'tcx>(
         MiriMachine::new(config, layout_cx, genmc_ctx),
     );
 
+    /*
     // Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
     let sentinel =
         helpers::try_resolve_path(tcx, &["core", "ascii", "escape_default"], Namespace::ValueNS);
@@ -337,7 +338,7 @@ pub fn create_ecx<'tcx>(
             "the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing.\n\
             Note that directly invoking the `miri` binary is not supported; please use `cargo miri` instead."
         );
-    }
+    }*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-shimsArea: This affects the external function shimsC-proposalCategory: a proposal for something we might want to do, or maybe not; details still being worked out

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions