diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index 6e9c682661..270889c86c 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -49,7 +49,7 @@ use crate::flowgraph; use crate::ir::{self, Function}; #[cfg(feature = "unwind")] use crate::isa::unwind::systemv::RegisterMappingError; -use crate::machinst::{MachBackend, MachCompileResult, UnwindInfoKind}; +use crate::machinst::{MachBackend, MachCompileResult, TextSectionBuilder, UnwindInfoKind}; use crate::settings; use crate::settings::SetResult; use crate::CodegenResult; @@ -263,6 +263,17 @@ pub trait TargetIsa: fmt::Display + Send + Sync { None } + /// Returns an object that can be used to build the text section of an + /// executable. + /// + /// This object will internally attempt to handle as many relocations as + /// possible using relative calls/jumps/etc between functions. + /// + /// The `num_labeled_funcs` argument here is the number of functions which + /// will be "labeled" or might have calls between them, typically the number + /// of defined functions in the object file. + fn text_section_builder(&self, num_labeled_funcs: u32) -> Box; + /// Get the new-style MachBackend. fn get_mach_backend(&self) -> &dyn MachBackend; } diff --git a/cranelift/codegen/src/machinst/adapter.rs b/cranelift/codegen/src/machinst/adapter.rs index e97be9a4cd..e95c579333 100644 --- a/cranelift/codegen/src/machinst/adapter.rs +++ b/cranelift/codegen/src/machinst/adapter.rs @@ -86,4 +86,8 @@ impl TargetIsa for TargetIsaAdapter { fn map_regalloc_reg_to_dwarf(&self, r: Reg) -> Result { self.backend.map_reg_to_dwarf(r) } + + fn text_section_builder(&self, num_labeled_funcs: u32) -> Box { + self.backend.text_section_builder(num_labeled_funcs) + } } diff --git a/crates/cranelift/src/obj.rs b/crates/cranelift/src/obj.rs index 763ae1afcd..62c7ed9ba0 100644 --- a/crates/cranelift/src/obj.rs +++ b/crates/cranelift/src/obj.rs @@ -205,7 +205,6 @@ impl<'a> ObjectBuilder<'a> { systemv_unwind_info: Vec::new(), relocations: Vec::new(), text: isa - .get_mach_backend() .text_section_builder((module.functions.len() - module.num_imported_funcs) as u32), added_unwind_info: false, }