allow dyn_sym in the files where they are defined; remove unreachable android code

This commit is contained in:
Ralf Jung 2023-10-06 09:38:50 +02:00
parent 099311ba5a
commit 16cde069fc
4 changed files with 25 additions and 19 deletions

View File

@ -707,7 +707,8 @@ fn init_extern_statics(this: &mut MiriInterpCx<'mir, 'tcx>) -> InterpResult<'tcx
);
}
"android" => {
// "signal"
// "signal" -- just needs a non-zero pointer value (function does not even get called),
// but we arrange for this to be callable anyway (it will then do nothing).
let layout = this.machine.layouts.const_raw_ptr;
let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str("signal")));
let val = ImmTy::from_scalar(Scalar::from_pointer(ptr, this), layout);

View File

@ -6,11 +6,12 @@
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
pub fn is_dyn_sym(name: &str) -> bool {
matches!(name, "signal")
pub fn is_dyn_sym(_name: &str) -> bool {
false
}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
#[allow(unused, clippy::match_single_binding)] // there isn't anything here yet
fn emulate_foreign_item_inner(
&mut self,
link_name: Symbol,
@ -21,15 +22,9 @@ fn emulate_foreign_item_inner(
let this = self.eval_context_mut();
match link_name.as_str() {
"signal" if this.frame_in_std() => {
let [_sig, _func] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?;
}
_ => return Ok(EmulateForeignItemResult::NotSupported),
}
#[allow(unreachable_code)]
Ok(EmulateForeignItemResult::NeedsJumping)
}
}

View File

@ -20,6 +20,23 @@
use shims::unix::linux::foreign_items as linux;
use shims::unix::macos::foreign_items as macos;
fn is_dyn_sym(name: &str, target_os: &str) -> bool {
match name {
// `signal` is set up as a weak symbol in `init_extern_statics` so we might as well allow it
// in `dlsym` as well.
"signal" => true,
// Give specific OSes a chance to allow their symbols.
_ =>
match target_os {
"android" => android::is_dyn_sym(name),
"freebsd" => freebsd::is_dyn_sym(name),
"linux" => linux::is_dyn_sym(name),
"macos" => macos::is_dyn_sym(name),
target_os => panic!("unsupported Unix OS {target_os}"),
},
}
}
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn emulate_foreign_item_inner(
@ -237,14 +254,7 @@ fn emulate_foreign_item_inner(
this.read_target_usize(handle)?;
let symbol = this.read_pointer(symbol)?;
let name = this.read_c_str(symbol)?;
let is_dyn_sym = |name| match &*this.tcx.sess.target.os {
"android" => android::is_dyn_sym(name),
"freebsd" => freebsd::is_dyn_sym(name),
"linux" => linux::is_dyn_sym(name),
"macos" => macos::is_dyn_sym(name),
target_os => panic!("unsupported Unix OS {target_os}"),
};
if let Ok(name) = str::from_utf8(name) && is_dyn_sym(name) {
if let Ok(name) = str::from_utf8(name) && is_dyn_sym(name, &this.tcx.sess.target.os) {
let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str(name)));
this.write_pointer(ptr, dest)?;
} else {

View File

@ -12,8 +12,8 @@
use shims::unix::sync::EvalContextExt as _;
use shims::unix::thread::EvalContextExt as _;
pub fn is_dyn_sym(_name: &str) -> bool {
false
pub fn is_dyn_sym(name: &str) -> bool {
matches!(name, "getrandom")
}
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}