Skip to content

Commit

Permalink
Auto merge of #2511 - RalfJung:extern-so, r=RalfJung
Browse files Browse the repository at this point in the history
some extern-so cleanup and fixes
  • Loading branch information
bors committed Aug 26, 2022
2 parents 4ae6874 + 235036f commit 101c4f2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -429,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(),
)
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 @@ -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);
Expand Down
File renamed without changes.

0 comments on commit 101c4f2

Please sign in to comment.