Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 332db9a

Browse files
committedJul 1, 2024
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.
1 parent 72b4d8c commit 332db9a

File tree

3 files changed

+3
-26
lines changed

3 files changed

+3
-26
lines changed
 

‎src/helpers.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::ty::{
2424
FloatTy, IntTy, Ty, TyCtxt, UintTy,
2525
};
2626
use rustc_session::config::CrateType;
27-
use rustc_span::{sym, Span, Symbol};
27+
use rustc_span::{Span, Symbol};
2828
use rustc_target::abi::{Align, FieldIdx, FieldsShape, Size, Variants};
2929
use rustc_target::spec::abi::Abi;
3030

@@ -1182,14 +1182,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11821182
this.alloc_mark_immutable(provenance.get_alloc_id().unwrap()).unwrap();
11831183
}
11841184

1185-
fn item_link_name(&self, def_id: DefId) -> Symbol {
1186-
let tcx = self.eval_context_ref().tcx;
1187-
match tcx.get_attrs(def_id, sym::link_name).filter_map(|a| a.value_str()).next() {
1188-
Some(name) => name,
1189-
None => tcx.item_name(def_id),
1190-
}
1191-
}
1192-
11931185
/// Converts `src` from floating point to integer type `dest_ty`
11941186
/// after rounding with mode `round`.
11951187
/// Returns `None` if `f` is NaN or out of range.

‎src/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
954954
// foreign function
955955
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
956956
let args = ecx.copy_fn_args(args); // FIXME: Should `InPlace` arguments be reset to uninit?
957-
let link_name = ecx.item_link_name(instance.def_id());
957+
let link_name = Symbol::intern(ecx.tcx.symbol_name(instance).name);
958958
return ecx.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
959959
}
960960

@@ -1050,7 +1050,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10501050
ecx: &MiriInterpCx<'tcx>,
10511051
def_id: DefId,
10521052
) -> InterpResult<'tcx, StrictPointer> {
1053-
let link_name = ecx.item_link_name(def_id);
1053+
let link_name = Symbol::intern(ecx.tcx.symbol_name(Instance::mono(*ecx.tcx, def_id)).name);
10541054
if let Some(&ptr) = ecx.machine.extern_statics.get(&link_name) {
10551055
// Various parts of the engine rely on `get_alloc_info` for size and alignment
10561056
// information. That uses the type information of this static.

‎src/shims/foreign_items.rs

-15
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4646
unwind: mir::UnwindAction,
4747
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
4848
let this = self.eval_context_mut();
49-
let tcx = this.tcx.tcx;
5049

5150
// Some shims forward to other MIR bodies.
5251
match link_name.as_str() {
53-
// This matches calls to the foreign item `panic_impl`.
54-
// The implementation is provided by the function with the `#[panic_handler]` attribute.
55-
"panic_impl" => {
56-
// We don't use `check_shim` here because we are just forwarding to the lang
57-
// item. Argument count checking will be performed when the returned `Body` is
58-
// called.
59-
this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?;
60-
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
61-
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
62-
return Ok(Some((
63-
this.load_mir(panic_impl_instance.def, None)?,
64-
panic_impl_instance,
65-
)));
66-
}
6752
"__rust_alloc_error_handler" => {
6853
// Forward to the right symbol that implements this function.
6954
let Some(handler_kind) = this.tcx.alloc_error_handler_kind(()) else {

0 commit comments

Comments
 (0)
Failed to load comments.