@@ -6,6 +6,7 @@ use crate::prelude::*;
66use rustc_ast:: expand:: allocator:: { AllocatorKind , AllocatorTy , ALLOCATOR_METHODS } ;
77use rustc_codegen_ssa:: base:: allocator_kind_for_codegen;
88use rustc_session:: config:: OomStrategy ;
9+ use rustc_span:: symbol:: sym;
910
1011/// Returns whether an allocator shim was created
1112pub ( crate ) fn codegen (
@@ -14,14 +15,21 @@ pub(crate) fn codegen(
1415 unwind_context : & mut UnwindContext ,
1516) -> bool {
1617 let Some ( kind) = allocator_kind_for_codegen ( tcx) else { return false } ;
17- codegen_inner ( module, unwind_context, kind, tcx. sess . opts . unstable_opts . oom ) ;
18+ codegen_inner (
19+ module,
20+ unwind_context,
21+ kind,
22+ tcx. alloc_error_handler_kind ( ( ) ) . unwrap ( ) ,
23+ tcx. sess . opts . unstable_opts . oom ,
24+ ) ;
1825 true
1926}
2027
2128fn codegen_inner (
2229 module : & mut impl Module ,
2330 unwind_context : & mut UnwindContext ,
2431 kind : AllocatorKind ,
32+ alloc_error_handler_kind : AllocatorKind ,
2533 oom_strategy : OomStrategy ,
2634) {
2735 let usize_ty = module. target_config ( ) . pointer_type ( ) ;
@@ -63,6 +71,19 @@ fn codegen_inner(
6371 ) ;
6472 }
6573
74+ let sig = Signature {
75+ call_conv : module. target_config ( ) . default_call_conv ,
76+ params : vec ! [ AbiParam :: new( usize_ty) , AbiParam :: new( usize_ty) ] ,
77+ returns : vec ! [ ] ,
78+ } ;
79+ crate :: common:: create_wrapper_function (
80+ module,
81+ unwind_context,
82+ sig,
83+ "__rust_alloc_error_handler" ,
84+ & alloc_error_handler_kind. fn_name ( sym:: oom) ,
85+ ) ;
86+
6687 let data_id = module. declare_data ( OomStrategy :: SYMBOL , Linkage :: Export , false , false ) . unwrap ( ) ;
6788 let mut data_ctx = DataContext :: new ( ) ;
6889 data_ctx. set_align ( 1 ) ;
0 commit comments