Skip to content

Commit 4135408

Browse files
committed
Auto merge of rust-lang#3108 - RalfJung:dlsym, r=RalfJung
refactor dlsym: dispatch symbols via the normal shim mechanism This avoids having to adjust Miri when switching between invoking the function via a linked symbol vs via dlsym.
2 parents f9003c0 + 16cde06 commit 4135408

29 files changed

+415
-702
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
960960
self.check_abi(abi, exp_abi)?;
961961
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
962962
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
963-
// We'll use our built-in implementation in `emulate_foreign_item_by_name` for increased
963+
// We'll use our built-in implementation in `emulate_foreign_item_inner` for increased
964964
// performance. Note that this means we won't catch any undefined behavior in
965965
// compiler-builtins when running other crates, but Miri can still be run on
966966
// compiler-builtins itself (or any crate that uses it as a normal dependency)

src/tools/miri/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(yeet_expr)]
99
#![feature(nonzero_ops)]
1010
#![feature(round_ties_even)]
11+
#![feature(let_chains)]
1112
#![feature(lint_reasons)]
1213
#![feature(trait_upcasting)]
1314
// Configure clippy and other lints
@@ -86,9 +87,8 @@ pub use rustc_const_eval::interpret::*;
8687
// Resolve ambiguity.
8788
pub use rustc_const_eval::interpret::{self, AllocMap, PlaceTy, Provenance as _};
8889

89-
pub use crate::shims::dlsym::{Dlsym, EvalContextExt as _};
9090
pub use crate::shims::env::{EnvVars, EvalContextExt as _};
91-
pub use crate::shims::foreign_items::EvalContextExt as _;
91+
pub use crate::shims::foreign_items::{DynSym, EvalContextExt as _};
9292
pub use crate::shims::intrinsics::EvalContextExt as _;
9393
pub use crate::shims::os_str::EvalContextExt as _;
9494
pub use crate::shims::panic::{CatchUnwindData, EvalContextExt as _};

src/tools/miri/src/machine.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
707707
);
708708
}
709709
"android" => {
710-
// "signal"
710+
// "signal" -- just needs a non-zero pointer value (function does not even get called),
711+
// but we arrange for this to be callable anyway (it will then do nothing).
711712
let layout = this.machine.layouts.const_raw_ptr;
712-
let dlsym = Dlsym::from_str("signal".as_bytes(), &this.tcx.sess.target.os)?
713-
.expect("`signal` must be an actual dlsym on android");
714-
let ptr = this.fn_ptr(FnVal::Other(dlsym));
713+
let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str("signal")));
715714
let val = ImmTy::from_scalar(Scalar::from_pointer(ptr, this), layout);
716715
Self::alloc_extern_static(this, "signal", val)?;
717716
// A couple zero-initialized pointer-sized extern statics.
@@ -867,7 +866,7 @@ impl<'mir, 'tcx> MiriInterpCxExt<'mir, 'tcx> for MiriInterpCx<'mir, 'tcx> {
867866
/// Machine hook implementations.
868867
impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
869868
type MemoryKind = MiriMemoryKind;
870-
type ExtraFnVal = Dlsym;
869+
type ExtraFnVal = DynSym;
871870

872871
type FrameExtra = FrameExtra<'tcx>;
873872
type AllocExtra = AllocExtra<'tcx>;
@@ -939,15 +938,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
939938
#[inline(always)]
940939
fn call_extra_fn(
941940
ecx: &mut MiriInterpCx<'mir, 'tcx>,
942-
fn_val: Dlsym,
941+
fn_val: DynSym,
943942
abi: Abi,
944943
args: &[FnArg<'tcx, Provenance>],
945944
dest: &PlaceTy<'tcx, Provenance>,
946945
ret: Option<mir::BasicBlock>,
947-
_unwind: mir::UnwindAction,
946+
unwind: mir::UnwindAction,
948947
) -> InterpResult<'tcx> {
949948
let args = ecx.copy_fn_args(args)?; // FIXME: Should `InPlace` arguments be reset to uninit?
950-
ecx.call_dlsym(fn_val, abi, &args, dest, ret)
949+
ecx.emulate_dyn_sym(fn_val, abi, &args, dest, ret, unwind)
951950
}
952951

953952
#[inline(always)]

src/tools/miri/src/shims/dlsym.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)