44use crate :: prelude:: * ;
55
66use rustc_ast:: expand:: allocator:: { AllocatorKind , AllocatorTy , ALLOCATOR_METHODS } ;
7+ use rustc_session:: config:: OomStrategy ;
78
89/// Returns whether an allocator shim was created
910pub ( crate ) fn codegen (
@@ -18,7 +19,13 @@ pub(crate) fn codegen(
1819 if any_dynamic_crate {
1920 false
2021 } else if let Some ( kind) = tcx. allocator_kind ( ( ) ) {
21- codegen_inner ( module, unwind_context, kind, tcx. lang_items ( ) . oom ( ) . is_some ( ) ) ;
22+ codegen_inner (
23+ module,
24+ unwind_context,
25+ kind,
26+ tcx. lang_items ( ) . oom ( ) . is_some ( ) ,
27+ tcx. sess . opts . debugging_opts . oom ,
28+ ) ;
2229 true
2330 } else {
2431 false
@@ -30,6 +37,7 @@ fn codegen_inner(
3037 unwind_context : & mut UnwindContext ,
3138 kind : AllocatorKind ,
3239 has_alloc_error_handler : bool ,
40+ oom_strategy : OomStrategy ,
3341) {
3442 let usize_ty = module. target_config ( ) . pointer_type ( ) ;
3543
@@ -129,4 +137,11 @@ fn codegen_inner(
129137 }
130138 module. define_function ( func_id, & mut ctx) . unwrap ( ) ;
131139 unwind_context. add_function ( func_id, & ctx, module. isa ( ) ) ;
140+
141+ let data_id = module. declare_data ( OomStrategy :: SYMBOL , Linkage :: Export , false , false ) . unwrap ( ) ;
142+ let mut data_ctx = DataContext :: new ( ) ;
143+ data_ctx. set_align ( 1 ) ;
144+ let val = oom_strategy. should_panic ( ) ;
145+ data_ctx. define ( Box :: new ( [ val] ) ) ;
146+ module. define_data ( data_id, & data_ctx) . unwrap ( ) ;
132147}
0 commit comments