-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for external C functions that have integer (or empty) args and/or returns #2363
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,10 +358,14 @@ pub struct Evaluator<'mir, 'tcx> { | |
pub(crate) report_progress: Option<u32>, | ||
/// The number of blocks that passed since the last progress report. | ||
pub(crate) since_progress_report: u32, | ||
|
||
/// Handle of the optional shared object file for external functions. | ||
pub external_so_lib: Option<(libloading::Library, std::path::PathBuf)>, | ||
} | ||
|
||
impl<'mir, 'tcx> Evaluator<'mir, 'tcx> { | ||
pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Self { | ||
let target_triple = &layout_cx.tcx.sess.opts.target_triple.to_string(); | ||
let local_crates = helpers::get_local_crates(layout_cx.tcx); | ||
let layouts = | ||
PrimitiveLayouts::new(layout_cx).expect("Couldn't get layouts of primitive types"); | ||
|
@@ -412,6 +416,24 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> { | |
preemption_rate: config.preemption_rate, | ||
report_progress: config.report_progress, | ||
since_progress_report: 0, | ||
external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the right spot to error if host != target. |
||
// Check if host target == the session target. | ||
if option_env!("TARGET") == Some(target_triple) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we panic if they are equal? How does that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hiding a bug, the comparison doesn't actually work right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by #2511 |
||
panic!( | ||
"calling external C functions in linked .so file requires target and host to be the same" | ||
); | ||
} | ||
// Note: it is the user's responsibility to provide a correct SO file. | ||
// WATCH OUT: If an invalid/incorrect SO file is specified, this can cause | ||
// undefined behaviour in Miri itself! | ||
( | ||
RalfJung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unsafe { | ||
libloading::Library::new(lib_file_path) | ||
.expect("Failed to read specified shared object file") | ||
}, | ||
lib_file_path.clone(), | ||
) | ||
}), | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a merge conflict issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I created a fix PR for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh no -- good catch and thanks for fixing it!