@@ -9,10 +9,9 @@ use rustc_hir::def::DefKind;
99use rustc_hir:: def_id:: CrateNum ;
1010use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
1111use rustc_middle:: mir:: interpret:: AllocInit ;
12- use rustc_middle:: ty:: Ty ;
12+ use rustc_middle:: ty:: { Instance , Ty } ;
1313use rustc_middle:: { mir, ty} ;
1414use rustc_span:: Symbol ;
15- use rustc_symbol_mangling:: mangle_internal_symbol;
1615use rustc_target:: callconv:: { Conv , FnAbi } ;
1716
1817use self :: helpers:: { ToHost , ToSoft } ;
@@ -52,19 +51,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5251
5352 // Some shims forward to other MIR bodies.
5453 match link_name. as_str ( ) {
55- name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc_error_handler" ) => {
54+ name if name == this. mangle_internal_symbol ( "__rust_alloc_error_handler" ) => {
5655 // Forward to the right symbol that implements this function.
5756 let Some ( handler_kind) = this. tcx . alloc_error_handler_kind ( ( ) ) else {
5857 // in real code, this symbol does not exist without an allocator
5958 throw_unsup_format ! (
6059 "`__rust_alloc_error_handler` cannot be called when no alloc error handler is set"
6160 ) ;
6261 } ;
63- let name =
64- mangle_internal_symbol ( * this. tcx , alloc_error_handler_name ( handler_kind) ) ;
65- let handler = this
66- . lookup_exported_symbol ( Symbol :: intern ( & name ) ) ?
67- . expect ( "missing alloc error handler symbol" ) ;
62+ let name = Symbol :: intern (
63+ this. mangle_internal_symbol ( alloc_error_handler_name ( handler_kind) ) ,
64+ ) ;
65+ let handler =
66+ this . lookup_exported_symbol ( name ) ? . expect ( "missing alloc error handler symbol" ) ;
6867 return interp_ok ( Some ( handler) ) ;
6968 }
7069 _ => { }
@@ -138,30 +137,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
138137 // Find it if it was not cached.
139138 let mut instance_and_crate: Option < ( ty:: Instance < ' _ > , CrateNum ) > = None ;
140139 helpers:: iter_exported_symbols ( tcx, |cnum, def_id| {
140+ let attrs = tcx. codegen_fn_attrs ( def_id) ;
141+ // Skip over imports of items.
141142 if tcx. is_foreign_item ( def_id) {
142- // Skip over imports of items
143143 return interp_ok ( ( ) ) ;
144144 }
145-
146- let attrs = tcx. codegen_fn_attrs ( def_id) ;
147- // FIXME use tcx.symbol_name(instance) instead
148- let symbol_name = if let Some ( export_name) = attrs. export_name {
149- export_name
150- } else if attrs. flags . contains ( CodegenFnAttrFlags :: NO_MANGLE )
151- || attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL )
145+ // Skip over items without an explicitly defined symbol name.
146+ if !( attrs. export_name . is_some ( )
147+ || attrs. flags . contains ( CodegenFnAttrFlags :: NO_MANGLE )
148+ || attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) )
152149 {
153- tcx. item_name ( def_id)
154- } else {
155- // Skip over items without an explicitly defined symbol name.
156150 return interp_ok ( ( ) ) ;
157- } ;
158- let symbol_name =
159- if attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) {
160- Symbol :: intern ( & mangle_internal_symbol ( tcx, symbol_name. as_str ( ) ) )
161- } else {
162- symbol_name
163- } ;
164- if symbol_name == link_name {
151+ }
152+
153+ let instance = Instance :: mono ( tcx, def_id) ;
154+ let symbol_name = tcx. symbol_name ( instance) . name ;
155+ if symbol_name == link_name. as_str ( ) {
165156 if let Some ( ( original_instance, original_cnum) ) = instance_and_crate {
166157 // Make sure we are consistent wrt what is 'first' and 'second'.
167158 let original_span = tcx. def_span ( original_instance. def_id ( ) ) . data ( ) ;
@@ -505,9 +496,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
505496 }
506497
507498 // Rust allocation
508- name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc" )
509- || name == "miri_alloc" =>
510- {
499+ name if name == this. mangle_internal_symbol ( "__rust_alloc" ) || name == "miri_alloc" => {
511500 let default = |ecx : & mut MiriInterpCx < ' tcx > | {
512501 // Only call `check_shim` when `#[global_allocator]` isn't used. When that
513502 // macro is used, we act like no shim exists, so that the exported function can run.
@@ -540,7 +529,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
540529 _ => return this. emulate_allocator ( default) ,
541530 }
542531 }
543- name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc_zeroed" ) => {
532+ name if name == this. mangle_internal_symbol ( "__rust_alloc_zeroed" ) => {
544533 return this. emulate_allocator ( |this| {
545534 // See the comment for `__rust_alloc` why `check_shim` is only called in the
546535 // default case.
@@ -559,7 +548,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
559548 this. write_pointer ( ptr, dest)
560549 } ) ;
561550 }
562- name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
551+ name if name == this. mangle_internal_symbol ( "__rust_dealloc" )
563552 || name == "miri_dealloc" =>
564553 {
565554 let default = |ecx : & mut MiriInterpCx < ' tcx > | {
@@ -592,7 +581,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
592581 _ => return this. emulate_allocator ( default) ,
593582 }
594583 }
595- name if name == mangle_internal_symbol ( * this. tcx , "__rust_realloc" ) => {
584+ name if name == this. mangle_internal_symbol ( "__rust_realloc" ) => {
596585 return this. emulate_allocator ( |this| {
597586 // See the comment for `__rust_alloc` why `check_shim` is only called in the
598587 // default case.
0 commit comments