Skip to content

Commit

Permalink
experiment: enable native-lib support on all Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 10, 2024
1 parent 73cbb49 commit 11f1256
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ features = ['unprefixed_malloc_on_supported_platforms']

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[target.'cfg(target_os = "linux")'.dependencies]
libffi = "3.2.0"
libloading = "0.8"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ to Miri failing to detect cases of undefined behavior in a program.
file descriptors will be mixed up.
This is **work in progress**; currently, only integer arguments and return values are
supported (and no, pointer/integer casts to work around this limitation will not work;
they will fail horribly). It also only works on Linux hosts for now.
they will fail horribly). It also only works on Unix hosts for now.
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
This can be used to find which parts of your program are executing slowly under Miri.
The profile is written out to a file inside a directory called `<name>`, and can be processed
Expand Down
10 changes: 5 additions & 5 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ pub struct MiriMachine<'mir, 'tcx> {
pub(crate) basic_block_count: u64,

/// Handle of the optional shared object file for native functions.
#[cfg(target_os = "linux")]
#[cfg(unix)]
pub native_lib: Option<(libloading::Library, std::path::PathBuf)>,
#[cfg(not(target_os = "linux"))]
#[cfg(not(unix))]
pub native_lib: Option<!>,

/// Run a garbage collector for BorTags every N basic blocks.
Expand Down Expand Up @@ -664,7 +664,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(target_os = "linux")]
#[cfg(unix)]
native_lib: config.native_lib.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 @@ -686,9 +686,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
lib_file_path.clone(),
)
}),
#[cfg(not(target_os = "linux"))]
#[cfg(not(unix))]
native_lib: config.native_lib.as_ref().map(|_| {
panic!("loading external .so files is only supported on Linux")
panic!("loading external .so files is only supported on Unix")
}),
gc_interval: config.gc_interval,
since_gc: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ trait EvalContextExtPriv<'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(target_os = "linux")]
#[cfg(unix)]
if this.machine.native_lib.as_ref().is_some() {
use crate::shims::native_lib::EvalContextExt as _;
// An Ok(false) here means that the function being called was not exported
Expand Down
2 changes: 1 addition & 1 deletion src/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod alloc;
mod backtrace;
pub mod foreign_items;
#[cfg(target_os = "linux")]
#[cfg(unix)]
pub mod native_lib;
pub mod unix;
pub mod windows;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn main() -> Result<()> {
WithDependencies,
tmpdir.path(),
)?;
if cfg!(target_os = "linux") {
if cfg!(unix) {
ui(Mode::Pass, "tests/native-lib/pass", &target, WithoutDependencies, tmpdir.path())?;
ui(
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
Expand Down

0 comments on commit 11f1256

Please sign in to comment.