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:
@@ -221,6 +221,9 @@ pub struct EmitResult<I: VCodeInst> {
|
||||
|
||||
/// Stack frame size.
|
||||
pub frame_size: u32,
|
||||
|
||||
/// The alignment requirement for pc-relative loads.
|
||||
pub alignment: u32,
|
||||
}
|
||||
|
||||
/// A builder for a VCode function body.
|
||||
@@ -1058,7 +1061,10 @@ impl<I: VCodeInst> VCode<I> {
|
||||
}
|
||||
|
||||
// Emit the constants used by the function.
|
||||
let mut alignment = 1;
|
||||
for (constant, data) in self.constants.iter() {
|
||||
alignment = data.alignment().max(alignment);
|
||||
|
||||
let label = buffer.get_label_for_constant(constant);
|
||||
buffer.defer_constant(label, data.alignment(), data.as_slice(), u32::max_value());
|
||||
}
|
||||
@@ -1101,6 +1107,7 @@ impl<I: VCodeInst> VCode<I> {
|
||||
dynamic_stackslot_offsets: self.abi.dynamic_stackslot_offsets().clone(),
|
||||
value_labels_ranges,
|
||||
frame_size,
|
||||
alignment,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user