Align functions according to their ISA's requirements (#4826)
Add a function_alignment function to the TargetIsa trait, and use it to align functions when generating objects. Additionally, collect the maximum alignment required for pc-relative constants in functions and pass that value out. Use the max of these two values when padding functions for alignment. This fixes a bug on x86_64 where rip-relative loads to sse registers could cause a segfault, as functions weren't always guaranteed to be aligned to 16-byte addresses. Fixes #4812
This commit is contained in:
@@ -300,6 +300,9 @@ pub struct CompiledCodeBase<T: CompilePhase> {
|
||||
/// This info is generated only if the `machine_code_cfg_info`
|
||||
/// flag is set.
|
||||
pub bb_edges: Vec<(CodeOffset, CodeOffset)>,
|
||||
/// Minimum alignment for the function, derived from the use of any
|
||||
/// pc-relative loads.
|
||||
pub alignment: u32,
|
||||
}
|
||||
|
||||
impl CompiledCodeStencil {
|
||||
@@ -314,6 +317,7 @@ impl CompiledCodeStencil {
|
||||
dynamic_stackslot_offsets: self.dynamic_stackslot_offsets,
|
||||
bb_starts: self.bb_starts,
|
||||
bb_edges: self.bb_edges,
|
||||
alignment: self.alignment,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,7 +359,7 @@ pub trait TextSectionBuilder {
|
||||
///
|
||||
/// This function returns the offset at which the data was placed in the
|
||||
/// text section.
|
||||
fn append(&mut self, labeled: bool, data: &[u8], align: Option<u32>) -> u64;
|
||||
fn append(&mut self, labeled: bool, data: &[u8], align: u32) -> u64;
|
||||
|
||||
/// Attempts to resolve a relocation for this function.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user