Skip to content

Commit 349430c

Browse files
committed
Avoid creating a second UnwindContext in finalize_definitions
Once UnwindContext sets the personality function it will need to define a DW.ref.rust_eh_personality function which would cause a duplicate definition if UnwindContext is called a second time.
1 parent eef57cb commit 349430c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
8484

8585
tcx.dcx().abort_if_errors();
8686

87-
jit_module.finalize_definitions();
87+
let mut jit_module = jit_module.finalize_definitions();
8888

8989
println!(
9090
"Rustc codegen cranelift will JIT run the executable, because -Cllvm-args=mode=jit was passed"
@@ -104,7 +104,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
104104
call_conv: jit_module.target_config().default_call_conv,
105105
};
106106
let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap();
107-
let finalized_start: *const u8 = jit_module.module.get_finalized_function(start_func_id);
107+
let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id);
108108

109109
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
110110
unsafe { ::std::mem::transmute(finalized_start) };

src/unwind_module.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ impl UnwindModule<ObjectModule> {
3333

3434
#[cfg(feature = "jit")]
3535
impl UnwindModule<cranelift_jit::JITModule> {
36-
pub(crate) fn finalize_definitions(&mut self) {
36+
pub(crate) fn finalize_definitions(mut self) -> cranelift_jit::JITModule {
3737
self.module.finalize_definitions().unwrap();
38-
let prev_unwind_context = std::mem::replace(
39-
&mut self.unwind_context,
40-
UnwindContext::new(&mut self.module, false),
41-
);
42-
unsafe { prev_unwind_context.register_jit(&self.module) };
38+
unsafe { self.unwind_context.register_jit(&self.module) };
39+
self.module
4340
}
4441
}
4542

0 commit comments

Comments
 (0)