@@ -9,10 +9,9 @@ use rustc_hir::def::DefKind;
9
9
use rustc_hir:: def_id:: CrateNum ;
10
10
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
11
11
use rustc_middle:: mir:: interpret:: AllocInit ;
12
- use rustc_middle:: ty:: Ty ;
12
+ use rustc_middle:: ty:: { Instance , Ty } ;
13
13
use rustc_middle:: { mir, ty} ;
14
14
use rustc_span:: Symbol ;
15
- use rustc_symbol_mangling:: mangle_internal_symbol;
16
15
use rustc_target:: callconv:: { Conv , FnAbi } ;
17
16
18
17
use self :: helpers:: { ToHost , ToSoft } ;
@@ -52,19 +51,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
52
51
53
52
// Some shims forward to other MIR bodies.
54
53
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" ) => {
56
55
// Forward to the right symbol that implements this function.
57
56
let Some ( handler_kind) = this. tcx . alloc_error_handler_kind ( ( ) ) else {
58
57
// in real code, this symbol does not exist without an allocator
59
58
throw_unsup_format ! (
60
59
"`__rust_alloc_error_handler` cannot be called when no alloc error handler is set"
61
60
) ;
62
61
} ;
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" ) ;
68
67
return interp_ok ( Some ( handler) ) ;
69
68
}
70
69
_ => { }
@@ -138,30 +137,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
138
137
// Find it if it was not cached.
139
138
let mut instance_and_crate: Option < ( ty:: Instance < ' _ > , CrateNum ) > = None ;
140
139
helpers:: iter_exported_symbols ( tcx, |cnum, def_id| {
140
+ let attrs = tcx. codegen_fn_attrs ( def_id) ;
141
+ // Skip over imports of items.
141
142
if tcx. is_foreign_item ( def_id) {
142
- // Skip over imports of items
143
143
return interp_ok ( ( ) ) ;
144
144
}
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 ) )
152
149
{
153
- tcx. item_name ( def_id)
154
- } else {
155
- // Skip over items without an explicitly defined symbol name.
156
150
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 ( ) {
165
156
if let Some ( ( original_instance, original_cnum) ) = instance_and_crate {
166
157
// Make sure we are consistent wrt what is 'first' and 'second'.
167
158
let original_span = tcx. def_span ( original_instance. def_id ( ) ) . data ( ) ;
@@ -505,9 +496,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
505
496
}
506
497
507
498
// 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" => {
511
500
let default = |ecx : & mut MiriInterpCx < ' tcx > | {
512
501
// Only call `check_shim` when `#[global_allocator]` isn't used. When that
513
502
// 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> {
540
529
_ => return this. emulate_allocator ( default) ,
541
530
}
542
531
}
543
- name if name == mangle_internal_symbol ( * this. tcx , "__rust_alloc_zeroed" ) => {
532
+ name if name == this. mangle_internal_symbol ( "__rust_alloc_zeroed" ) => {
544
533
return this. emulate_allocator ( |this| {
545
534
// See the comment for `__rust_alloc` why `check_shim` is only called in the
546
535
// default case.
@@ -559,7 +548,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
559
548
this. write_pointer ( ptr, dest)
560
549
} ) ;
561
550
}
562
- name if name == mangle_internal_symbol ( * this. tcx , "__rust_dealloc" )
551
+ name if name == this. mangle_internal_symbol ( "__rust_dealloc" )
563
552
|| name == "miri_dealloc" =>
564
553
{
565
554
let default = |ecx : & mut MiriInterpCx < ' tcx > | {
@@ -592,7 +581,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
592
581
_ => return this. emulate_allocator ( default) ,
593
582
}
594
583
}
595
- name if name == mangle_internal_symbol ( * this. tcx , "__rust_realloc" ) => {
584
+ name if name == this. mangle_internal_symbol ( "__rust_realloc" ) => {
596
585
return this. emulate_allocator ( |this| {
597
586
// See the comment for `__rust_alloc` why `check_shim` is only called in the
598
587
// default case.
0 commit comments