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:
@@ -640,6 +640,7 @@ pub trait Module {
|
||||
&mut self,
|
||||
func_id: FuncId,
|
||||
func: &ir::Function,
|
||||
alignment: u64,
|
||||
bytes: &[u8],
|
||||
relocs: &[MachReloc],
|
||||
) -> ModuleResult<ModuleCompiledFunction>;
|
||||
@@ -736,10 +737,11 @@ impl<M: Module> Module for &mut M {
|
||||
&mut self,
|
||||
func_id: FuncId,
|
||||
func: &ir::Function,
|
||||
alignment: u64,
|
||||
bytes: &[u8],
|
||||
relocs: &[MachReloc],
|
||||
) -> ModuleResult<ModuleCompiledFunction> {
|
||||
(**self).define_function_bytes(func_id, func, bytes, relocs)
|
||||
(**self).define_function_bytes(func_id, func, alignment, bytes, relocs)
|
||||
}
|
||||
|
||||
fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user