@@ -14,12 +14,12 @@ use rustc_session::Session;
14
14
use rustc_span:: Symbol ;
15
15
16
16
use crate :: debuginfo:: TypeDebugContext ;
17
+ use crate :: unwind_module:: UnwindModule ;
17
18
use crate :: { prelude:: * , BackendConfig } ;
18
19
use crate :: { CodegenCx , CodegenMode } ;
19
20
20
21
struct JitState {
21
- backend_config : BackendConfig ,
22
- jit_module : JITModule ,
22
+ jit_module : UnwindModule < JITModule > ,
23
23
}
24
24
25
25
thread_local ! {
@@ -63,7 +63,7 @@ fn create_jit_module(
63
63
tcx : TyCtxt < ' _ > ,
64
64
backend_config : & BackendConfig ,
65
65
hotswap : bool ,
66
- ) -> ( JITModule , CodegenCx ) {
66
+ ) -> ( UnwindModule < JITModule > , CodegenCx ) {
67
67
let crate_info = CrateInfo :: new ( tcx, "dummy_target_cpu" . to_string ( ) ) ;
68
68
69
69
let isa = crate :: build_isa ( tcx. sess , backend_config) ;
@@ -72,17 +72,11 @@ fn create_jit_module(
72
72
crate :: compiler_builtins:: register_functions_for_jit ( & mut jit_builder) ;
73
73
jit_builder. symbol_lookup_fn ( dep_symbol_lookup_fn ( tcx. sess , crate_info) ) ;
74
74
jit_builder. symbol ( "__clif_jit_fn" , clif_jit_fn as * const u8 ) ;
75
- let mut jit_module = JITModule :: new ( jit_builder) ;
75
+ let mut jit_module = UnwindModule :: new ( JITModule :: new ( jit_builder) , false ) ;
76
76
77
- let mut cx = crate :: CodegenCx :: new (
78
- tcx,
79
- backend_config. clone ( ) ,
80
- jit_module. isa ( ) ,
81
- false ,
82
- Symbol :: intern ( "dummy_cgu_name" ) ,
83
- ) ;
77
+ let cx = crate :: CodegenCx :: new ( tcx, jit_module. isa ( ) , false , Symbol :: intern ( "dummy_cgu_name" ) ) ;
84
78
85
- crate :: allocator:: codegen ( tcx, & mut jit_module, & mut cx . unwind_context ) ;
79
+ crate :: allocator:: codegen ( tcx, & mut jit_module) ;
86
80
87
81
( jit_module, cx)
88
82
}
@@ -128,7 +122,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
128
122
) ;
129
123
}
130
124
CodegenMode :: JitLazy => {
131
- codegen_shim ( tcx, & mut cx , & mut cached_context, & mut jit_module, inst)
125
+ codegen_shim ( tcx, & mut cached_context, & mut jit_module, inst)
132
126
}
133
127
} ,
134
128
MonoItem :: Static ( def_id) => {
@@ -146,18 +140,11 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
146
140
tcx. dcx ( ) . fatal ( "Inline asm is not supported in JIT mode" ) ;
147
141
}
148
142
149
- crate :: main_shim:: maybe_create_entry_wrapper (
150
- tcx,
151
- & mut jit_module,
152
- & mut cx. unwind_context ,
153
- true ,
154
- true ,
155
- ) ;
143
+ crate :: main_shim:: maybe_create_entry_wrapper ( tcx, & mut jit_module, true , true ) ;
156
144
157
145
tcx. dcx ( ) . abort_if_errors ( ) ;
158
146
159
- jit_module. finalize_definitions ( ) . unwrap ( ) ;
160
- unsafe { cx. unwind_context . register_jit ( & jit_module) } ;
147
+ jit_module. finalize_definitions ( ) ;
161
148
162
149
println ! (
163
150
"Rustc codegen cranelift will JIT run the executable, because -Cllvm-args=mode=jit was passed"
@@ -177,12 +164,12 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
177
164
call_conv : jit_module. target_config ( ) . default_call_conv ,
178
165
} ;
179
166
let start_func_id = jit_module. declare_function ( "main" , Linkage :: Import , & start_sig) . unwrap ( ) ;
180
- let finalized_start: * const u8 = jit_module. get_finalized_function ( start_func_id) ;
167
+ let finalized_start: * const u8 = jit_module. module . get_finalized_function ( start_func_id) ;
181
168
182
169
LAZY_JIT_STATE . with ( |lazy_jit_state| {
183
170
let mut lazy_jit_state = lazy_jit_state. borrow_mut ( ) ;
184
171
assert ! ( lazy_jit_state. is_none( ) ) ;
185
- * lazy_jit_state = Some ( JitState { backend_config , jit_module } ) ;
172
+ * lazy_jit_state = Some ( JitState { jit_module } ) ;
186
173
} ) ;
187
174
188
175
let f: extern "C" fn ( c_int , * const * const c_char ) -> c_int =
@@ -268,7 +255,6 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
268
255
let mut lazy_jit_state = lazy_jit_state. borrow_mut ( ) ;
269
256
let lazy_jit_state = lazy_jit_state. as_mut ( ) . unwrap ( ) ;
270
257
let jit_module = & mut lazy_jit_state. jit_module ;
271
- let backend_config = lazy_jit_state. backend_config . clone ( ) ;
272
258
273
259
let name = tcx. symbol_name ( instance) . name ;
274
260
let sig = crate :: abi:: get_function_sig (
@@ -278,7 +264,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
278
264
) ;
279
265
let func_id = jit_module. declare_function ( name, Linkage :: Export , & sig) . unwrap ( ) ;
280
266
281
- let current_ptr = jit_module. read_got_entry ( func_id) ;
267
+ let current_ptr = jit_module. module . read_got_entry ( func_id) ;
282
268
283
269
// If the function's GOT entry has already been updated to point at something other
284
270
// than the shim trampoline, don't re-jit but just return the new pointer instead.
@@ -288,21 +274,19 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
288
274
return current_ptr;
289
275
}
290
276
291
- jit_module. prepare_for_function_redefine ( func_id) . unwrap ( ) ;
277
+ jit_module. module . prepare_for_function_redefine ( func_id) . unwrap ( ) ;
292
278
293
279
let mut cx = crate :: CodegenCx :: new (
294
280
tcx,
295
- backend_config,
296
281
jit_module. isa ( ) ,
297
282
false ,
298
283
Symbol :: intern ( "dummy_cgu_name" ) ,
299
284
) ;
300
285
codegen_and_compile_fn ( tcx, & mut cx, & mut Context :: new ( ) , jit_module, instance) ;
301
286
302
287
assert ! ( cx. global_asm. is_empty( ) ) ;
303
- jit_module. finalize_definitions ( ) . unwrap ( ) ;
304
- unsafe { cx. unwind_context . register_jit ( & jit_module) } ;
305
- jit_module. get_finalized_function ( func_id)
288
+ jit_module. finalize_definitions ( ) ;
289
+ jit_module. module . get_finalized_function ( func_id)
306
290
} )
307
291
} )
308
292
}
@@ -362,9 +346,8 @@ fn dep_symbol_lookup_fn(
362
346
363
347
fn codegen_shim < ' tcx > (
364
348
tcx : TyCtxt < ' tcx > ,
365
- cx : & mut CodegenCx ,
366
349
cached_context : & mut Context ,
367
- module : & mut JITModule ,
350
+ module : & mut UnwindModule < JITModule > ,
368
351
inst : Instance < ' tcx > ,
369
352
) {
370
353
let pointer_type = module. target_config ( ) . pointer_type ( ) ;
@@ -413,5 +396,4 @@ fn codegen_shim<'tcx>(
413
396
trampoline_builder. ins ( ) . return_ ( & ret_vals) ;
414
397
415
398
module. define_function ( func_id, context) . unwrap ( ) ;
416
- cx. unwind_context . add_function ( func_id, context, module. isa ( ) ) ;
417
399
}
0 commit comments