Skip to content

Commit 3188d07

Browse files
author
Ellen Arteca
committed
PR edits: check for host == target, moving some testing setup around as per @RalfJung s comments
1 parent 22b699a commit 3188d07

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

miri

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ esac
104104

105105
## Prepare the environment
106106
# Determine some toolchain properties
107-
TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
107+
# export the target so its available in miri
108+
export TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
108109
SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)
109110
LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
110111
if ! test -d "$LIBDIR"; then

src/shims/ffi_support.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
237237
.map(|cur_arg| cur_arg.arg_downcast())
238238
.collect::<Vec<libffi::high::Arg<'_>>>();
239239

240-
// Code pointer to C function.
241-
// let ptr = CodePtr(*func.deref() as *mut _);
242240
// Call the function and store output, depending on return type in the function signature.
243241
self.call_external_c_and_store_return(link_name, dest, code_ptr, libffi_args)?;
244242
Ok(true)
@@ -272,7 +270,7 @@ pub enum CArg {
272270

273271
impl<'a> CArg {
274272
/// Convert a `CArg` to a `libffi` argument type.
275-
pub fn arg_downcast(&'a self) -> libffi::high::Arg<'a> {
273+
fn arg_downcast(&'a self) -> libffi::high::Arg<'a> {
276274
match self {
277275
CArg::Int8(i) => ffi::arg(i),
278276
CArg::Int16(i) => ffi::arg(i),

src/shims/foreign_items.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
368368
let this = self.eval_context_mut();
369369

370370
// First deal with any external C functions in linked .so file
371-
// (if any SO file is specified).
372-
if this.machine.external_so_lib.as_ref().is_some() {
371+
// (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+
&& env!("TARGET") == this.tcx.sess.opts.target_triple.to_string()
374+
{
373375
// An Ok(false) here means that the function being called was not exported
374376
// by the specified SO file; we should continue and check if it corresponds to
375377
// a provided shim.

tests/compiletest.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ fn miri_path() -> PathBuf {
1111
// Build the shared object file for testing external C function calls.
1212
fn build_so_for_c_ffi_tests() {
1313
let cc = option_env!("CC").unwrap_or("cc");
14+
// Target directory that we can write to.
15+
let so_target_dir = env!("CARGO_TARGET_DIR").to_owned() + "/miri-extern-so";
16+
// Create the directory if it does not already exist.
17+
std::fs::create_dir_all(so_target_dir.as_str())
18+
.expect("Failed to create directory for shared object file");
1419
let cc_output = Command::new(cc)
1520
.args([
1621
"-shared",
1722
"-o",
18-
"tests/extern-so/libtestlib.so",
23+
&(so_target_dir + "/libtestlib.so"),
1924
"tests/extern-so/test.c",
2025
// Only add the functions specified in libcode.version to the shared object file.
2126
// This is to avoid automatically adding `malloc`, etc.

0 commit comments

Comments
 (0)