Skip to content

Commit 3e784f2

Browse files
author
Ellen Arteca
committed
adding a build script to re-export the TARGET env var so it can be read in miri
1 parent 69f3f04 commit 3e784f2

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
// Re-export the TARGET environment variable so it can
3+
// be accessed by miri.
4+
let target = std::env::var("TARGET").unwrap();
5+
println!("cargo:rustc-env=TARGET={:?}", target);
6+
}

miri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ esac
105105
## Prepare the environment
106106
# Determine some toolchain properties
107107
# export the target so its available in miri
108-
export TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
108+
TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
109109
SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)
110110
LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
111111
if ! test -d "$LIBDIR"; then

src/shims/ffi_support.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
221221

222222
let this = self.eval_context_mut();
223223

224+
// Check if host target == the session target.
225+
// This check needs to happen _after_ we check if the shared object file does not
226+
// export the function: we don't want to throw an error if we are just going to use
227+
// one of the shims.
228+
if option_env!("TARGET") == Some(&this.tcx.sess.opts.target_triple.to_string()) {
229+
throw_ub_format!(
230+
"calling external C functions in linked .so file requires target and host to be the same"
231+
);
232+
}
233+
224234
// Get the function arguments, and convert them to `libffi`-compatible form.
225235
let mut libffi_args = Vec::<CArg>::with_capacity(args.len());
226236
for cur_arg in args.iter() {

src/shims/foreign_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
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)
372372
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-
}
378373
// An Ok(false) here means that the function being called was not exported
379374
// by the specified SO file; we should continue and check if it corresponds to
380375
// a provided shim.

0 commit comments

Comments
 (0)