Skip to content

Commit 101c4f2

Browse files
committed
Auto merge of #2511 - RalfJung:extern-so, r=RalfJung
some extern-so cleanup and fixes
2 parents 4ae6874 + 235036f commit 101c4f2

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ fn main() {
22
// Re-export the TARGET environment variable so it can
33
// be accessed by miri.
44
let target = std::env::var("TARGET").unwrap();
5-
println!("cargo:rustc-env=TARGET={:?}", target);
5+
println!("cargo:rustc-env=TARGET={}", target);
66
}

src/bin/miri.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,14 @@ fn main() {
534534
let filename = param.to_string();
535535
if std::path::Path::new(&filename).exists() {
536536
if let Some(other_filename) = miri_config.external_so_file {
537-
panic!(
538-
"-Zmiri-extern-so-file external SO file is already set to {}",
537+
show_error!(
538+
"-Zmiri-extern-so-file is already set to {}",
539539
other_filename.display()
540540
);
541541
}
542542
miri_config.external_so_file = Some(filename.into());
543543
} else {
544-
panic!("-Zmiri-extern-so-file path {} does not exist", filename);
544+
show_error!("-Zmiri-extern-so-file `{}` does not exist", filename);
545545
}
546546
} else {
547547
// Forward to rustc.

src/machine.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
418418
since_progress_report: 0,
419419
external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| {
420420
// Check if host target == the session target.
421-
if option_env!("TARGET") == Some(target_triple) {
421+
if env!("TARGET") != target_triple {
422422
panic!(
423-
"calling external C functions in linked .so file requires target and host to be the same"
423+
"calling external C functions in linked .so file requires host and target to be the same: host={}, target={}",
424+
env!("TARGET"),
425+
target_triple,
424426
);
425427
}
426428
// Note: it is the user's responsibility to provide a correct SO file.
@@ -429,7 +431,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
429431
(
430432
unsafe {
431433
libloading::Library::new(lib_file_path)
432-
.expect("Failed to read specified shared object file")
434+
.expect("failed to read specified extern shared object file")
433435
},
434436
lib_file_path.clone(),
435437
)

src/shims/foreign_items.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
370370
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
371371
let this = self.eval_context_mut();
372372

373-
// First deal with any external C functions in linked .so file
374-
// (if any SO file is specified, and if the host target == the session target)
373+
// First deal with any external C functions in linked .so file.
375374
if this.machine.external_so_lib.as_ref().is_some() {
376375
// An Ok(false) here means that the function being called was not exported
377-
// by the specified SO file; we should continue and check if it corresponds to
376+
// by the specified `.so` file; we should continue and check if it corresponds to
378377
// a provided shim.
379378
if this.call_external_c_fct(link_name, dest, args)? {
380379
return Ok(EmulateByNameResult::NeedsJumping);

0 commit comments

Comments
 (0)