about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-04-24 13:08:32 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-04-24 13:08:32 +0000
commit349430c08ecc4c98325f8231d3fafee69cc3ba29 (patch)
tree7b3f8309143fa180ce6c123fdfd86d09b6d1e691
parenteef57cb4e290ea44bae26a1320c37c76b13275b6 (diff)
downloadrust-349430c08ecc4c98325f8231d3fafee69cc3ba29.tar.gz
rust-349430c08ecc4c98325f8231d3fafee69cc3ba29.zip
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.
-rw-r--r--src/driver/jit.rs4
-rw-r--r--src/unwind_module.rs9
2 files changed, 5 insertions, 8 deletions
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 0e2e1f6fc0a..6315935a221 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -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) };
diff --git a/src/unwind_module.rs b/src/unwind_module.rs
index 0864bd8d84f..b4eb939cf25 100644
--- a/src/unwind_module.rs
+++ b/src/unwind_module.rs
@@ -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
     }
 }