Use the symbol_name query instead of trying to infer from the link_name attribute
This prevents the calculated name from going out of sync with exported_symbols. It also avoids having to special case the panic_impl lang item.
This commit is contained in:
parent
9d920ed333
commit
18049b73ec
3 changed files with 3 additions and 26 deletions
|
|
@ -24,7 +24,7 @@ use rustc_middle::ty::{
|
|||
FloatTy, IntTy, Ty, TyCtxt, UintTy,
|
||||
};
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_span::{sym, Span, Symbol};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::abi::{Align, FieldIdx, FieldsShape, Size, Variants};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
|
|
@ -1182,14 +1182,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
this.alloc_mark_immutable(provenance.get_alloc_id().unwrap()).unwrap();
|
||||
}
|
||||
|
||||
fn item_link_name(&self, def_id: DefId) -> Symbol {
|
||||
let tcx = self.eval_context_ref().tcx;
|
||||
match tcx.get_attrs(def_id, sym::link_name).filter_map(|a| a.value_str()).next() {
|
||||
Some(name) => name,
|
||||
None => tcx.item_name(def_id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts `src` from floating point to integer type `dest_ty`
|
||||
/// after rounding with mode `round`.
|
||||
/// Returns `None` if `f` is NaN or out of range.
|
||||
|
|
|
|||
|
|
@ -954,7 +954,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
|
|||
// foreign function
|
||||
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
|
||||
let args = ecx.copy_fn_args(args); // FIXME: Should `InPlace` arguments be reset to uninit?
|
||||
let link_name = ecx.item_link_name(instance.def_id());
|
||||
let link_name = Symbol::intern(ecx.tcx.symbol_name(instance).name);
|
||||
return ecx.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
|
||||
}
|
||||
|
||||
|
|
@ -1050,7 +1050,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
|
|||
ecx: &MiriInterpCx<'tcx>,
|
||||
def_id: DefId,
|
||||
) -> InterpResult<'tcx, StrictPointer> {
|
||||
let link_name = ecx.item_link_name(def_id);
|
||||
let link_name = Symbol::intern(ecx.tcx.symbol_name(Instance::mono(*ecx.tcx, def_id)).name);
|
||||
if let Some(&ptr) = ecx.machine.extern_statics.get(&link_name) {
|
||||
// Various parts of the engine rely on `get_alloc_info` for size and alignment
|
||||
// information. That uses the type information of this static.
|
||||
|
|
|
|||
|
|
@ -46,24 +46,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
unwind: mir::UnwindAction,
|
||||
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
|
||||
let this = self.eval_context_mut();
|
||||
let tcx = this.tcx.tcx;
|
||||
|
||||
// Some shims forward to other MIR bodies.
|
||||
match link_name.as_str() {
|
||||
// This matches calls to the foreign item `panic_impl`.
|
||||
// The implementation is provided by the function with the `#[panic_handler]` attribute.
|
||||
"panic_impl" => {
|
||||
// We don't use `check_shim` here because we are just forwarding to the lang
|
||||
// item. Argument count checking will be performed when the returned `Body` is
|
||||
// called.
|
||||
this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?;
|
||||
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
|
||||
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
|
||||
return Ok(Some((
|
||||
this.load_mir(panic_impl_instance.def, None)?,
|
||||
panic_impl_instance,
|
||||
)));
|
||||
}
|
||||
"__rust_alloc_error_handler" => {
|
||||
// Forward to the right symbol that implements this function.
|
||||
let Some(handler_kind) = this.tcx.alloc_error_handler_kind(()) else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue