Skip to content

Commit ce4620b

Browse files
committed
Auto merge of rust-lang#2586 - RalfJung:ffi, r=RalfJung
remove FFI support for macOS We're only testing this on Linux, and `@thomcc` reports that libffi on macOS is a pain, so let's just disable this for now.
2 parents 9cc11e2 + 33bdddb commit ce4620b

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/tools/miri/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ smallvec = "1.7"
3131
rustc-workspace-hack = "1.0.0"
3232
measureme = "10.0.0"
3333

34-
[target."cfg(unix)".dependencies]
34+
[target.'cfg(unix)'.dependencies]
3535
libc = "0.2"
36+
37+
[target.'cfg(target_os = "linux")'.dependencies]
3638
libffi = "3.0.0"
3739
libloading = "0.7"
3840

src/tools/miri/src/machine.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,10 @@ pub struct MiriMachine<'mir, 'tcx> {
421421
pub(crate) basic_block_count: u64,
422422

423423
/// Handle of the optional shared object file for external functions.
424-
#[cfg(unix)]
424+
#[cfg(target_os = "linux")]
425425
pub external_so_lib: Option<(libloading::Library, std::path::PathBuf)>,
426+
#[cfg(not(target_os = "linux"))]
427+
pub external_so_lib: Option<!>,
426428

427429
/// Run a garbage collector for SbTags every N basic blocks.
428430
pub(crate) gc_interval: u32,
@@ -485,7 +487,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
485487
report_progress: config.report_progress,
486488
basic_block_count: 0,
487489
clock: Clock::new(config.isolated_op == IsolatedOp::Allow),
488-
#[cfg(unix)]
490+
#[cfg(target_os = "linux")]
489491
external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| {
490492
let target_triple = layout_cx.tcx.sess.opts.target_triple.triple();
491493
// Check if host target == the session target.
@@ -507,6 +509,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
507509
lib_file_path.clone(),
508510
)
509511
}),
512+
#[cfg(not(target_os = "linux"))]
513+
external_so_lib: config.external_so_file.as_ref().map(|_| {
514+
panic!("loading external .so files is only supported on Linux")
515+
}),
510516
gc_interval: config.gc_interval,
511517
since_gc: 0,
512518
num_cpus: config.num_cpus,
@@ -648,7 +654,6 @@ impl VisitTags for MiriMachine<'_, '_> {
648654
preemption_rate: _,
649655
report_progress: _,
650656
basic_block_count: _,
651-
#[cfg(unix)]
652657
external_so_lib: _,
653658
gc_interval: _,
654659
since_gc: _,

src/tools/miri/src/shims/ffi_support.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
183183
// from: https://docs.rs/libloading/0.7.3/src/libloading/os/unix/mod.rs.html#411
184184
// using the `libc` crate where this interface is public.
185185
// No `libc::dladdr` on windows.
186-
#[cfg(unix)]
187186
let mut info = std::mem::MaybeUninit::<libc::Dl_info>::uninit();
188-
#[cfg(unix)]
189187
unsafe {
190188
if libc::dladdr(*func.deref() as *const _, info.as_mut_ptr()) != 0 {
191189
if std::ffi::CStr::from_ptr(info.assume_init().dli_fname).to_str().unwrap()

src/tools/miri/src/shims/foreign_items.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ use rustc_target::{
2323

2424
use super::backtrace::EvalContextExt as _;
2525
use crate::helpers::{convert::Truncate, target_os_is_unix};
26-
#[cfg(unix)]
27-
use crate::shims::ffi_support::EvalContextExt as _;
2826
use crate::*;
2927

3028
/// Returned by `emulate_foreign_item_by_name`.
@@ -372,8 +370,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
372370
let this = self.eval_context_mut();
373371

374372
// First deal with any external C functions in linked .so file.
375-
#[cfg(unix)]
373+
#[cfg(target_os = "linux")]
376374
if this.machine.external_so_lib.as_ref().is_some() {
375+
use crate::shims::ffi_support::EvalContextExt as _;
377376
// An Ok(false) here means that the function being called was not exported
378377
// by the specified `.so` file; we should continue and check if it corresponds to
379378
// a provided shim.

src/tools/miri/src/shims/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(clippy::integer_arithmetic)]
22

33
mod backtrace;
4-
#[cfg(unix)]
4+
#[cfg(target_os = "linux")]
55
pub mod ffi_support;
66
pub mod foreign_items;
77
pub mod intrinsics;

0 commit comments

Comments
 (0)