Add text_section_builder method to TargetIsa

This commit is contained in:
bjorn3
2022-01-04 19:41:42 +01:00
parent 03dc74d8e7
commit 58c25d9e24
3 changed files with 16 additions and 2 deletions

View File

@@ -49,7 +49,7 @@ use crate::flowgraph;
use crate::ir::{self, Function}; use crate::ir::{self, Function};
#[cfg(feature = "unwind")] #[cfg(feature = "unwind")]
use crate::isa::unwind::systemv::RegisterMappingError; 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;
use crate::settings::SetResult; use crate::settings::SetResult;
use crate::CodegenResult; use crate::CodegenResult;
@@ -263,6 +263,17 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
None 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<dyn TextSectionBuilder>;
/// Get the new-style MachBackend. /// Get the new-style MachBackend.
fn get_mach_backend(&self) -> &dyn MachBackend; fn get_mach_backend(&self) -> &dyn MachBackend;
} }

View File

@@ -86,4 +86,8 @@ impl TargetIsa for TargetIsaAdapter {
fn map_regalloc_reg_to_dwarf(&self, r: Reg) -> Result<u16, RegisterMappingError> { fn map_regalloc_reg_to_dwarf(&self, r: Reg) -> Result<u16, RegisterMappingError> {
self.backend.map_reg_to_dwarf(r) self.backend.map_reg_to_dwarf(r)
} }
fn text_section_builder(&self, num_labeled_funcs: u32) -> Box<dyn TextSectionBuilder> {
self.backend.text_section_builder(num_labeled_funcs)
}
} }

View File

@@ -205,7 +205,6 @@ impl<'a> ObjectBuilder<'a> {
systemv_unwind_info: Vec::new(), systemv_unwind_info: Vec::new(),
relocations: Vec::new(), relocations: Vec::new(),
text: isa text: isa
.get_mach_backend()
.text_section_builder((module.functions.len() - module.num_imported_funcs) as u32), .text_section_builder((module.functions.len() - module.num_imported_funcs) as u32),
added_unwind_info: false, added_unwind_info: false,
} }