@@ -358,10 +358,14 @@ pub struct Evaluator<'mir, 'tcx> {
358
358
pub ( crate ) report_progress : Option < u32 > ,
359
359
/// The number of blocks that passed since the last progress report.
360
360
pub ( crate ) since_progress_report : u32 ,
361
+
362
+ /// Handle of the optional shared object file for external functions.
363
+ pub external_so_lib : Option < ( libloading:: Library , std:: path:: PathBuf ) > ,
361
364
}
362
365
363
366
impl < ' mir , ' tcx > Evaluator < ' mir , ' tcx > {
364
367
pub ( crate ) fn new ( config : & MiriConfig , layout_cx : LayoutCx < ' tcx , TyCtxt < ' tcx > > ) -> Self {
368
+ let target_triple = & layout_cx. tcx . sess . opts . target_triple . to_string ( ) ;
365
369
let local_crates = helpers:: get_local_crates ( layout_cx. tcx ) ;
366
370
let layouts =
367
371
PrimitiveLayouts :: new ( layout_cx) . expect ( "Couldn't get layouts of primitive types" ) ;
@@ -412,6 +416,24 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
412
416
preemption_rate : config. preemption_rate ,
413
417
report_progress : config. report_progress ,
414
418
since_progress_report : 0 ,
419
+ external_so_lib : config. external_so_file . as_ref ( ) . map ( |lib_file_path| {
420
+ // Check if host target == the session target.
421
+ if option_env ! ( "TARGET" ) == Some ( target_triple) {
422
+ panic ! (
423
+ "calling external C functions in linked .so file requires target and host to be the same"
424
+ ) ;
425
+ }
426
+ // Note: it is the user's responsibility to provide a correct SO file.
427
+ // WATCH OUT: If an invalid/incorrect SO file is specified, this can cause
428
+ // undefined behaviour in Miri itself!
429
+ (
430
+ unsafe {
431
+ libloading:: Library :: new ( lib_file_path)
432
+ . expect ( "Failed to read specified shared object file" )
433
+ } ,
434
+ lib_file_path. clone ( ) ,
435
+ )
436
+ } ) ,
415
437
}
416
438
}
417
439
0 commit comments