Skip to content

Commit 9495eb5

Browse files
committed
Pass Module to UnwindContext
Once writing the LSDA, it will need access to the Module to get a reference to the personality function and to define a data object for the LSDA. Part of #1567
1 parent ab514c9 commit 9495eb5

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Diff for: src/debuginfo/unwind.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Unwind info generation (`.eh_frame`)
22
33
use cranelift_codegen::ir::Endianness;
4-
use cranelift_codegen::isa::TargetIsa;
54
use cranelift_codegen::isa::unwind::UnwindInfo;
65
use cranelift_object::ObjectProduct;
76
use gimli::RunTimeEndian;
@@ -18,14 +17,14 @@ pub(crate) struct UnwindContext {
1817
}
1918

2019
impl UnwindContext {
21-
pub(crate) fn new(isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self {
22-
let endian = match isa.endianness() {
20+
pub(crate) fn new(module: &mut dyn Module, pic_eh_frame: bool) -> Self {
21+
let endian = match module.isa().endianness() {
2322
Endianness::Little => RunTimeEndian::Little,
2423
Endianness::Big => RunTimeEndian::Big,
2524
};
2625
let mut frame_table = FrameTable::default();
2726

28-
let cie_id = if let Some(mut cie) = isa.create_systemv_cie() {
27+
let cie_id = if let Some(mut cie) = module.isa().create_systemv_cie() {
2928
if pic_eh_frame {
3029
cie.fde_address_encoding =
3130
gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0);
@@ -38,8 +37,15 @@ impl UnwindContext {
3837
UnwindContext { endian, frame_table, cie_id }
3938
}
4039

41-
pub(crate) fn add_function(&mut self, func_id: FuncId, context: &Context, isa: &dyn TargetIsa) {
42-
if let target_lexicon::OperatingSystem::MacOSX { .. } = isa.triple().operating_system {
40+
pub(crate) fn add_function(
41+
&mut self,
42+
module: &mut dyn Module,
43+
func_id: FuncId,
44+
context: &Context,
45+
) {
46+
if let target_lexicon::OperatingSystem::MacOSX { .. } =
47+
module.isa().triple().operating_system
48+
{
4349
// The object crate doesn't currently support DW_GNU_EH_PE_absptr, which macOS
4450
// requires for unwinding tables. In addition on arm64 it currently doesn't
4551
// support 32bit relocations as we currently use for the unwinding table.
@@ -48,7 +54,7 @@ impl UnwindContext {
4854
}
4955

5056
let unwind_info = if let Some(unwind_info) =
51-
context.compiled_code().unwrap().create_unwind_info(isa).unwrap()
57+
context.compiled_code().unwrap().create_unwind_info(module.isa()).unwrap()
5258
{
5359
unwind_info
5460
} else {

Diff for: src/unwind_module.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub(crate) struct UnwindModule<T> {
1717
}
1818

1919
impl<T: Module> UnwindModule<T> {
20-
pub(crate) fn new(module: T, pic_eh_frame: bool) -> Self {
21-
let unwind_context = UnwindContext::new(module.isa(), pic_eh_frame);
20+
pub(crate) fn new(mut module: T, pic_eh_frame: bool) -> Self {
21+
let unwind_context = UnwindContext::new(&mut module, pic_eh_frame);
2222
UnwindModule { module, unwind_context }
2323
}
2424
}
@@ -37,7 +37,7 @@ impl UnwindModule<cranelift_jit::JITModule> {
3737
self.module.finalize_definitions().unwrap();
3838
let prev_unwind_context = std::mem::replace(
3939
&mut self.unwind_context,
40-
UnwindContext::new(self.module.isa(), false),
40+
UnwindContext::new(&mut self.module, false),
4141
);
4242
unsafe { prev_unwind_context.register_jit(&self.module) };
4343
}
@@ -94,7 +94,7 @@ impl<T: Module> Module for UnwindModule<T> {
9494
ctrl_plane: &mut ControlPlane,
9595
) -> ModuleResult<()> {
9696
self.module.define_function_with_control_plane(func, ctx, ctrl_plane)?;
97-
self.unwind_context.add_function(func, ctx, self.module.isa());
97+
self.unwind_context.add_function(&mut self.module, func, ctx);
9898
Ok(())
9999
}
100100

0 commit comments

Comments
 (0)