Skip to content

Commit 69f3f04

Browse files
author
Ellen Arteca
committed
addressing some of the PR comments; still issues with the TARGET env var
1 parent 37b53fd commit 69f3f04

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/shims/foreign_items.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
369369

370370
// First deal with any external C functions in linked .so file
371371
// (if any SO file is specified, and if the host target == the session target)
372-
if this.machine.external_so_lib.as_ref().is_some()
373-
&& option_env!("TARGET") == Some(&this.tcx.sess.opts.target_triple.to_string())
374-
{
372+
if this.machine.external_so_lib.as_ref().is_some() {
373+
if option_env!("TARGET") != Some(&this.tcx.sess.opts.target_triple.to_string()) {
374+
throw_ub_format!(
375+
"calling external C functions in linked .so file requires target and host to be the same"
376+
);
377+
}
375378
// An Ok(false) here means that the function being called was not exported
376379
// by the specified SO file; we should continue and check if it corresponds to
377380
// a provided shim.

tests/compiletest.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ fn miri_path() -> PathBuf {
1212
fn build_so_for_c_ffi_tests() {
1313
let cc = option_env!("CC").unwrap_or("cc");
1414
// Target directory that we can write to.
15-
let so_target_dir = env!("CARGO_TARGET_DIR").to_owned() + "/miri-extern-so";
15+
let so_target_dir = Path::new(&env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri-extern-so");
1616
// Create the directory if it does not already exist.
17-
std::fs::create_dir_all(so_target_dir.as_str())
17+
std::fs::create_dir_all(&so_target_dir)
1818
.expect("Failed to create directory for shared object file");
19+
let so_file_path = so_target_dir.join("libtestlib.so");
1920
let cc_output = Command::new(cc)
2021
.args([
2122
"-shared",
2223
"-o",
23-
&(so_target_dir + "/libtestlib.so"),
24+
so_file_path.to_str().unwrap(),
2425
"tests/extern-so/test.c",
2526
// Only add the functions specified in libcode.version to the shared object file.
2627
// This is to avoid automatically adding `malloc`, etc.

tests/fail/extern-so/function_not_in_SO.stderr renamed to tests/fail/extern-so/function_not_in_so.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error: unsupported operation: can't call foreign function: foo
2-
--> $DIR/function_not_in_SO.rs:LL:CC
2+
--> $DIR/function_not_in_so.rs:LL:CC
33
|
44
LL | foo();
55
| ^^^^^ can't call foreign function: foo
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
88
= note: backtrace:
9-
= note: inside `main` at $DIR/function_not_in_SO.rs:LL:CC
9+
= note: inside `main` at $DIR/function_not_in_so.rs:LL:CC
1010

1111
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1212

0 commit comments

Comments
 (0)