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.
This commit is contained in:
parent
eef57cb4e2
commit
349430c08e
2 changed files with 5 additions and 8 deletions
|
|
@ -84,7 +84,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
|
|||
|
||||
tcx.dcx().abort_if_errors();
|
||||
|
||||
jit_module.finalize_definitions();
|
||||
let mut jit_module = jit_module.finalize_definitions();
|
||||
|
||||
println!(
|
||||
"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>) -> ! {
|
|||
call_conv: jit_module.target_config().default_call_conv,
|
||||
};
|
||||
let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap();
|
||||
let finalized_start: *const u8 = jit_module.module.get_finalized_function(start_func_id);
|
||||
let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id);
|
||||
|
||||
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
|
||||
unsafe { ::std::mem::transmute(finalized_start) };
|
||||
|
|
|
|||
|
|
@ -33,13 +33,10 @@ impl UnwindModule<ObjectModule> {
|
|||
|
||||
#[cfg(feature = "jit")]
|
||||
impl UnwindModule<cranelift_jit::JITModule> {
|
||||
pub(crate) fn finalize_definitions(&mut self) {
|
||||
pub(crate) fn finalize_definitions(mut self) -> cranelift_jit::JITModule {
|
||||
self.module.finalize_definitions().unwrap();
|
||||
let prev_unwind_context = std::mem::replace(
|
||||
&mut self.unwind_context,
|
||||
UnwindContext::new(&mut self.module, false),
|
||||
);
|
||||
unsafe { prev_unwind_context.register_jit(&self.module) };
|
||||
unsafe { self.unwind_context.register_jit(&self.module) };
|
||||
self.module
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue