4
4
use crate :: prelude:: * ;
5
5
6
6
use rustc_ast:: expand:: allocator:: { AllocatorKind , AllocatorTy , ALLOCATOR_METHODS } ;
7
+ use rustc_session:: config:: OomStrategy ;
7
8
8
9
/// Returns whether an allocator shim was created
9
10
pub ( crate ) fn codegen (
@@ -18,7 +19,13 @@ pub(crate) fn codegen(
18
19
if any_dynamic_crate {
19
20
false
20
21
} 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
+ ) ;
22
29
true
23
30
} else {
24
31
false
@@ -30,6 +37,7 @@ fn codegen_inner(
30
37
unwind_context : & mut UnwindContext ,
31
38
kind : AllocatorKind ,
32
39
has_alloc_error_handler : bool ,
40
+ oom_strategy : OomStrategy ,
33
41
) {
34
42
let usize_ty = module. target_config ( ) . pointer_type ( ) ;
35
43
@@ -129,4 +137,11 @@ fn codegen_inner(
129
137
}
130
138
module. define_function ( func_id, & mut ctx) . unwrap ( ) ;
131
139
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 ( ) ;
132
147
}
0 commit comments