From 4e017b54ad96175939c90353b89017d1fd1b9e09 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 26 Aug 2022 17:38:59 -0400 Subject: [PATCH 1/3] fix host/target check for extern-so --- build.rs | 2 +- src/machine.rs | 6 ++++-- src/shims/foreign_items.rs | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index c8121aa973..15d6c963ad 100644 --- a/build.rs +++ b/build.rs @@ -2,5 +2,5 @@ fn main() { // Re-export the TARGET environment variable so it can // be accessed by miri. let target = std::env::var("TARGET").unwrap(); - println!("cargo:rustc-env=TARGET={:?}", target); + println!("cargo:rustc-env=TARGET={}", target); } diff --git a/src/machine.rs b/src/machine.rs index 841c1343fa..70b8263a9e 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -418,9 +418,11 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> { since_progress_report: 0, external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| { // Check if host target == the session target. - if option_env!("TARGET") == Some(target_triple) { + if env!("TARGET") != target_triple { panic!( - "calling external C functions in linked .so file requires target and host to be the same" + "calling external C functions in linked .so file requires host and target to be the same: host={}, target={}", + env!("TARGET"), + target_triple, ); } // Note: it is the user's responsibility to provide a correct SO file. diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index b8862b3ba4..117e0933dd 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -370,11 +370,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { let this = self.eval_context_mut(); - // First deal with any external C functions in linked .so file - // (if any SO file is specified, and if the host target == the session target) + // First deal with any external C functions in linked .so file. if this.machine.external_so_lib.as_ref().is_some() { // 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 + // by the specified `.so` file; we should continue and check if it corresponds to // a provided shim. if this.call_external_c_fct(link_name, dest, args)? { return Ok(EmulateByNameResult::NeedsJumping); From 82802337a88b241c03ccb04a934f9fdb541a3200 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 26 Aug 2022 17:40:26 -0400 Subject: [PATCH 2/3] rename test to match usual naming conventions what's a "fcts"? --- .../extern-so/pass/{call_extern_c_fcts.rs => call_extern_c_fn.rs} | 0 .../pass/{call_extern_c_fcts.stdout => call_extern_c_fn.stdout} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/extern-so/pass/{call_extern_c_fcts.rs => call_extern_c_fn.rs} (100%) rename tests/extern-so/pass/{call_extern_c_fcts.stdout => call_extern_c_fn.stdout} (100%) diff --git a/tests/extern-so/pass/call_extern_c_fcts.rs b/tests/extern-so/pass/call_extern_c_fn.rs similarity index 100% rename from tests/extern-so/pass/call_extern_c_fcts.rs rename to tests/extern-so/pass/call_extern_c_fn.rs diff --git a/tests/extern-so/pass/call_extern_c_fcts.stdout b/tests/extern-so/pass/call_extern_c_fn.stdout similarity index 100% rename from tests/extern-so/pass/call_extern_c_fcts.stdout rename to tests/extern-so/pass/call_extern_c_fn.stdout From 235036fcb3b8cac8b98774224c56c0ab7b454bb5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 26 Aug 2022 17:43:04 -0400 Subject: [PATCH 3/3] nicer errors --- src/bin/miri.rs | 6 +++--- src/machine.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index fa6a307038..2684ad7ff3 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -534,14 +534,14 @@ fn main() { let filename = param.to_string(); if std::path::Path::new(&filename).exists() { if let Some(other_filename) = miri_config.external_so_file { - panic!( - "-Zmiri-extern-so-file external SO file is already set to {}", + show_error!( + "-Zmiri-extern-so-file is already set to {}", other_filename.display() ); } miri_config.external_so_file = Some(filename.into()); } else { - panic!("-Zmiri-extern-so-file path {} does not exist", filename); + show_error!("-Zmiri-extern-so-file `{}` does not exist", filename); } } else { // Forward to rustc. diff --git a/src/machine.rs b/src/machine.rs index 70b8263a9e..df2566de88 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -431,7 +431,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> { ( unsafe { libloading::Library::new(lib_file_path) - .expect("Failed to read specified shared object file") + .expect("failed to read specified extern shared object file") }, lib_file_path.clone(), )