diff --git a/Cargo.toml b/Cargo.toml index 0c547d585d198..b63186f98a700 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,10 @@ smallvec = "1.7" rustc-workspace-hack = "1.0.0" measureme = "10.0.0" -[target."cfg(unix)".dependencies] +[target.'cfg(unix)'.dependencies] libc = "0.2" + +[target.'cfg(target_os = "linux")'.dependencies] libffi = "3.0.0" libloading = "0.7" diff --git a/src/machine.rs b/src/machine.rs index 20ae908fce87c..fc9a1170d2942 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -421,8 +421,10 @@ pub struct MiriMachine<'mir, 'tcx> { pub(crate) basic_block_count: u64, /// Handle of the optional shared object file for external functions. - #[cfg(unix)] + #[cfg(target_os = "linux")] pub external_so_lib: Option<(libloading::Library, std::path::PathBuf)>, + #[cfg(not(target_os = "linux"))] + pub external_so_lib: Option, /// Run a garbage collector for SbTags every N basic blocks. pub(crate) gc_interval: u32, @@ -485,7 +487,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { report_progress: config.report_progress, basic_block_count: 0, clock: Clock::new(config.isolated_op == IsolatedOp::Allow), - #[cfg(unix)] + #[cfg(target_os = "linux")] external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| { let target_triple = layout_cx.tcx.sess.opts.target_triple.triple(); // Check if host target == the session target. @@ -507,6 +509,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { lib_file_path.clone(), ) }), + #[cfg(not(target_os = "linux"))] + external_so_lib: config.external_so_file.as_ref().map(|_| { + panic!("loading external .so files is only supported on Linux") + }), gc_interval: config.gc_interval, since_gc: 0, num_cpus: config.num_cpus, @@ -648,7 +654,6 @@ impl VisitTags for MiriMachine<'_, '_> { preemption_rate: _, report_progress: _, basic_block_count: _, - #[cfg(unix)] external_so_lib: _, gc_interval: _, since_gc: _, diff --git a/src/shims/ffi_support.rs b/src/shims/ffi_support.rs index 0813554e9d24e..c5db868cdc7c5 100644 --- a/src/shims/ffi_support.rs +++ b/src/shims/ffi_support.rs @@ -183,9 +183,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { // from: https://docs.rs/libloading/0.7.3/src/libloading/os/unix/mod.rs.html#411 // using the `libc` crate where this interface is public. // No `libc::dladdr` on windows. - #[cfg(unix)] let mut info = std::mem::MaybeUninit::::uninit(); - #[cfg(unix)] unsafe { if libc::dladdr(*func.deref() as *const _, info.as_mut_ptr()) != 0 { if std::ffi::CStr::from_ptr(info.assume_init().dli_fname).to_str().unwrap() diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index bb62a2a7ec1b5..26184fdc3c09a 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -23,8 +23,6 @@ use rustc_target::{ use super::backtrace::EvalContextExt as _; use crate::helpers::{convert::Truncate, target_os_is_unix}; -#[cfg(unix)] -use crate::shims::ffi_support::EvalContextExt as _; use crate::*; /// Returned by `emulate_foreign_item_by_name`. @@ -372,8 +370,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let this = self.eval_context_mut(); // First deal with any external C functions in linked .so file. - #[cfg(unix)] + #[cfg(target_os = "linux")] if this.machine.external_so_lib.as_ref().is_some() { + use crate::shims::ffi_support::EvalContextExt as _; // An Ok(false) here means that the function being called was not exported // by the specified `.so` file; we should continue and check if it corresponds to // a provided shim. diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 8cb648e517328..dcb99a2766826 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -1,7 +1,7 @@ #![warn(clippy::integer_arithmetic)] mod backtrace; -#[cfg(unix)] +#[cfg(target_os = "linux")] pub mod ffi_support; pub mod foreign_items; pub mod intrinsics;