Skip to content

Commit 351afbb

Browse files
committed
Auto merge of rust-lang#2555 - oli-obk:libffi-is-unhappy, r=RalfJung
Only support libffi on unix for now
2 parents eb84c8b + 4f35795 commit 351afbb

File tree

8 files changed

+11
-9
lines changed

8 files changed

+11
-9
lines changed

Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ doctest = false # and no doc tests
2020
[dependencies]
2121
getrandom = { version = "0.2", features = ["std"] }
2222
env_logger = "0.9"
23-
libffi = "3.0.0"
24-
libloading = "0.7"
2523
log = "0.4"
2624
shell-escape = "0.1.4"
2725
rand = "0.8"
@@ -33,10 +31,10 @@ smallvec = "1.7"
3331
rustc-workspace-hack = "1.0.0"
3432
measureme = "10.0.0"
3533

36-
# Enable some feature flags that dev-dependencies need but dependencies
37-
# do not. This makes `./miri install` after `./miri build` faster.
3834
[target."cfg(unix)".dependencies]
3935
libc = "0.2"
36+
libffi = "3.0.0"
37+
libloading = "0.7"
4038

4139
[dev-dependencies]
4240
colored = "2"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ to Miri failing to detect cases of undefined behavior in a program.
360360
file descriptors will be mixed up.
361361
This is **work in progress**; currently, only integer arguments and return values are
362362
supported (and no, pointer/integer casts to work around this limitation will not work;
363-
they will fail horribly).
363+
they will fail horribly). It also only works on unix hosts for now.
364364
Follow [the discussion on supporting other types](https://github.com/rust-lang/miri/issues/2365).
365365
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
366366
This can be used to find which parts of your program are executing slowly under Miri.

src/bin/miri.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
extern crate rustc_data_structures;
99
extern crate rustc_driver;
10-
extern crate rustc_errors;
1110
extern crate rustc_hir;
1211
extern crate rustc_interface;
1312
extern crate rustc_metadata;

src/concurrency/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! declare_id {
4444
}
4545

4646
impl $name {
47-
pub fn to_u32_scalar<'tcx>(&self) -> Scalar<Provenance> {
47+
pub fn to_u32_scalar(&self) -> Scalar<Provenance> {
4848
Scalar::from_u32(self.0.get())
4949
}
5050
}

src/machine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ pub struct MiriMachine<'mir, 'tcx> {
400400
pub(crate) basic_block_count: u64,
401401

402402
/// Handle of the optional shared object file for external functions.
403+
#[cfg(unix)]
403404
pub external_so_lib: Option<(libloading::Library, std::path::PathBuf)>,
404405

405406
/// Run a garbage collector for SbTags every N basic blocks.
@@ -410,7 +411,6 @@ pub struct MiriMachine<'mir, 'tcx> {
410411

411412
impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
412413
pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Self {
413-
let target_triple = &layout_cx.tcx.sess.opts.target_triple.to_string();
414414
let local_crates = helpers::get_local_crates(layout_cx.tcx);
415415
let layouts =
416416
PrimitiveLayouts::new(layout_cx).expect("Couldn't get layouts of primitive types");
@@ -462,7 +462,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
462462
report_progress: config.report_progress,
463463
basic_block_count: 0,
464464
clock: Clock::new(config.isolated_op == IsolatedOp::Allow),
465+
#[cfg(unix)]
465466
external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| {
467+
let target_triple = &layout_cx.tcx.sess.opts.target_triple.to_string();
466468
// Check if host target == the session target.
467469
if env!("TARGET") != target_triple {
468470
panic!(

src/shims/foreign_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc_target::{
2323

2424
use super::backtrace::EvalContextExt as _;
2525
use crate::helpers::{convert::Truncate, target_os_is_unix};
26+
#[cfg(unix)]
2627
use crate::shims::ffi_support::EvalContextExt as _;
2728
use crate::*;
2829

@@ -371,6 +372,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
371372
let this = self.eval_context_mut();
372373

373374
// First deal with any external C functions in linked .so file.
375+
#[cfg(unix)]
374376
if this.machine.external_so_lib.as_ref().is_some() {
375377
// An Ok(false) here means that the function being called was not exported
376378
// by the specified `.so` file; we should continue and check if it corresponds to

src/shims/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![warn(clippy::integer_arithmetic)]
22

33
mod backtrace;
4+
#[cfg(unix)]
45
pub mod ffi_support;
56
pub mod foreign_items;
67
pub mod intrinsics;

src/shims/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl FileDescriptor for DummyOutput {
246246
Ok(Ok(bytes.len()))
247247
}
248248

249-
fn dup<'tcx>(&mut self) -> io::Result<Box<dyn FileDescriptor>> {
249+
fn dup(&mut self) -> io::Result<Box<dyn FileDescriptor>> {
250250
Ok(Box::new(DummyOutput))
251251
}
252252
}

0 commit comments

Comments
 (0)