Skip to content

Commit

Permalink
Auto merge of rust-lang#2586 - RalfJung:ffi, r=RalfJung
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Oct 7, 2022
2 parents 2093184 + 4445ff6 commit ec9108b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 8 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -648,7 +654,6 @@ impl VisitTags for MiriMachine<'_, '_> {
preemption_rate: _,
report_progress: _,
basic_block_count: _,
#[cfg(unix)]
external_so_lib: _,
gc_interval: _,
since_gc: _,
Expand Down
2 changes: 0 additions & 2 deletions src/shims/ffi_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<libc::Dl_info>::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()
Expand Down
5 changes: 2 additions & 3 deletions src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/shims/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit ec9108b

Please sign in to comment.