@@ -5,7 +5,6 @@ use crate::prelude::*;
5
5
6
6
use cranelift_codegen:: binemit:: { NullStackMapSink , NullTrapSink } ;
7
7
use rustc_ast:: expand:: allocator:: { AllocatorKind , AllocatorTy , ALLOCATOR_METHODS } ;
8
- use rustc_span:: symbol:: sym;
9
8
10
9
/// Returns whether an allocator shim was created
11
10
pub ( crate ) fn codegen (
@@ -20,7 +19,7 @@ pub(crate) fn codegen(
20
19
if any_dynamic_crate {
21
20
false
22
21
} else if let Some ( kind) = tcx. allocator_kind ( ( ) ) {
23
- codegen_inner ( module, unwind_context, kind) ;
22
+ codegen_inner ( module, unwind_context, kind, tcx . lang_items ( ) . oom ( ) . is_some ( ) ) ;
24
23
true
25
24
} else {
26
25
false
@@ -31,6 +30,7 @@ fn codegen_inner(
31
30
module : & mut impl Module ,
32
31
unwind_context : & mut UnwindContext ,
33
32
kind : AllocatorKind ,
33
+ has_alloc_error_handler : bool ,
34
34
) {
35
35
let usize_ty = module. target_config ( ) . pointer_type ( ) ;
36
36
@@ -65,7 +65,6 @@ fn codegen_inner(
65
65
66
66
let caller_name = format ! ( "__rust_{}" , method. name) ;
67
67
let callee_name = kind. fn_name ( method. name ) ;
68
- //eprintln!("Codegen allocator shim {} -> {} ({:?} -> {:?})", caller_name, callee_name, sig.params, sig.returns);
69
68
70
69
let func_id = module. declare_function ( & caller_name, Linkage :: Export , & sig) . unwrap ( ) ;
71
70
@@ -104,13 +103,12 @@ fn codegen_inner(
104
103
returns : vec ! [ ] ,
105
104
} ;
106
105
107
- let callee_name = kind. fn_name ( sym:: oom) ;
108
- //eprintln!("Codegen allocator shim {} -> {} ({:?} -> {:?})", caller_name, callee_name, sig.params, sig.returns);
106
+ let callee_name = if has_alloc_error_handler { "__rg_oom" } else { "__rdl_oom" } ;
109
107
110
108
let func_id =
111
109
module. declare_function ( "__rust_alloc_error_handler" , Linkage :: Export , & sig) . unwrap ( ) ;
112
110
113
- let callee_func_id = module. declare_function ( & callee_name, Linkage :: Import , & sig) . unwrap ( ) ;
111
+ let callee_func_id = module. declare_function ( callee_name, Linkage :: Import , & sig) . unwrap ( ) ;
114
112
115
113
let mut ctx = Context :: new ( ) ;
116
114
ctx. func = Function :: with_name_signature ( ExternalName :: user ( 0 , 0 ) , sig) ;
0 commit comments