@@ -14,12 +14,12 @@ use rustc_session::Session;
1414use rustc_span:: Symbol ;
1515
1616use crate :: debuginfo:: TypeDebugContext ;
17+ use crate :: unwind_module:: UnwindModule ;
1718use crate :: { prelude:: * , BackendConfig } ;
1819use crate :: { CodegenCx , CodegenMode } ;
1920
2021struct JitState {
21- backend_config : BackendConfig ,
22- jit_module : JITModule ,
22+ jit_module : UnwindModule < JITModule > ,
2323}
2424
2525thread_local ! {
@@ -63,7 +63,7 @@ fn create_jit_module(
6363 tcx : TyCtxt < ' _ > ,
6464 backend_config : & BackendConfig ,
6565 hotswap : bool ,
66- ) -> ( JITModule , CodegenCx ) {
66+ ) -> ( UnwindModule < JITModule > , CodegenCx ) {
6767 let crate_info = CrateInfo :: new ( tcx, "dummy_target_cpu" . to_string ( ) ) ;
6868
6969 let isa = crate :: build_isa ( tcx. sess , backend_config) ;
@@ -72,17 +72,11 @@ fn create_jit_module(
7272 crate :: compiler_builtins:: register_functions_for_jit ( & mut jit_builder) ;
7373 jit_builder. symbol_lookup_fn ( dep_symbol_lookup_fn ( tcx. sess , crate_info) ) ;
7474 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 ) ;
7676
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" ) ) ;
8478
85- crate :: allocator:: codegen ( tcx, & mut jit_module, & mut cx . unwind_context ) ;
79+ crate :: allocator:: codegen ( tcx, & mut jit_module) ;
8680
8781 ( jit_module, cx)
8882}
@@ -128,7 +122,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
128122 ) ;
129123 }
130124 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)
132126 }
133127 } ,
134128 MonoItem :: Static ( def_id) => {
@@ -146,18 +140,11 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
146140 tcx. dcx ( ) . fatal ( "Inline asm is not supported in JIT mode" ) ;
147141 }
148142
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 ) ;
156144
157145 tcx. dcx ( ) . abort_if_errors ( ) ;
158146
159- jit_module. finalize_definitions ( ) . unwrap ( ) ;
160- unsafe { cx. unwind_context . register_jit ( & jit_module) } ;
147+ jit_module. finalize_definitions ( ) ;
161148
162149 println ! (
163150 "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) -> ! {
177164 call_conv : jit_module. target_config ( ) . default_call_conv ,
178165 } ;
179166 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) ;
181168
182169 LAZY_JIT_STATE . with ( |lazy_jit_state| {
183170 let mut lazy_jit_state = lazy_jit_state. borrow_mut ( ) ;
184171 assert ! ( lazy_jit_state. is_none( ) ) ;
185- * lazy_jit_state = Some ( JitState { backend_config , jit_module } ) ;
172+ * lazy_jit_state = Some ( JitState { jit_module } ) ;
186173 } ) ;
187174
188175 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) ->
268255 let mut lazy_jit_state = lazy_jit_state. borrow_mut ( ) ;
269256 let lazy_jit_state = lazy_jit_state. as_mut ( ) . unwrap ( ) ;
270257 let jit_module = & mut lazy_jit_state. jit_module ;
271- let backend_config = lazy_jit_state. backend_config . clone ( ) ;
272258
273259 let name = tcx. symbol_name ( instance) . name ;
274260 let sig = crate :: abi:: get_function_sig (
@@ -278,7 +264,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
278264 ) ;
279265 let func_id = jit_module. declare_function ( name, Linkage :: Export , & sig) . unwrap ( ) ;
280266
281- let current_ptr = jit_module. read_got_entry ( func_id) ;
267+ let current_ptr = jit_module. module . read_got_entry ( func_id) ;
282268
283269 // If the function's GOT entry has already been updated to point at something other
284270 // 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) ->
288274 return current_ptr;
289275 }
290276
291- jit_module. prepare_for_function_redefine ( func_id) . unwrap ( ) ;
277+ jit_module. module . prepare_for_function_redefine ( func_id) . unwrap ( ) ;
292278
293279 let mut cx = crate :: CodegenCx :: new (
294280 tcx,
295- backend_config,
296281 jit_module. isa ( ) ,
297282 false ,
298283 Symbol :: intern ( "dummy_cgu_name" ) ,
299284 ) ;
300285 codegen_and_compile_fn ( tcx, & mut cx, & mut Context :: new ( ) , jit_module, instance) ;
301286
302287 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)
306290 } )
307291 } )
308292}
@@ -362,9 +346,8 @@ fn dep_symbol_lookup_fn(
362346
363347fn codegen_shim < ' tcx > (
364348 tcx : TyCtxt < ' tcx > ,
365- cx : & mut CodegenCx ,
366349 cached_context : & mut Context ,
367- module : & mut JITModule ,
350+ module : & mut UnwindModule < JITModule > ,
368351 inst : Instance < ' tcx > ,
369352) {
370353 let pointer_type = module. target_config ( ) . pointer_type ( ) ;
@@ -413,5 +396,4 @@ fn codegen_shim<'tcx>(
413396 trampoline_builder. ins ( ) . return_ ( & ret_vals) ;
414397
415398 module. define_function ( func_id, context) . unwrap ( ) ;
416- cx. unwind_context . add_function ( func_id, context, module. isa ( ) ) ;
417399}
0 commit comments