Ensure functions are aligned properly on AArch64 (#3908)

Previously (as in an hour ago) #3905 landed a new ability for fuzzing to
arbitrarily insert padding between functions. Running some fuzzers
locally though this instantly hit a lot of problems on AArch64 because
the arbitrary padding isn't aligned to 4 bytes like all other functions
are. To fix this issue appending functions now correctly aligns the
output as appropriate for the platform. The alignment argument for
appending was switched to `None` where `None` means "use the platform
default" and otherwise and explicit alignment can be specified for
inserting other data (like arbitrary padding or Windows unwind tables).
This commit is contained in:
Alex Crichton
2022-03-09 15:45:30 -06:00
committed by GitHub
parent 1a54826ca8
commit 4d404c90b4
4 changed files with 11 additions and 9 deletions

View File

@@ -1616,7 +1616,7 @@ impl<I: VCodeInst> MachTextSectionBuilder<I> {
}
impl<I: VCodeInst> TextSectionBuilder for MachTextSectionBuilder<I> {
fn append(&mut self, named: bool, func: &[u8], align: u32) -> u64 {
fn append(&mut self, named: bool, func: &[u8], align: Option<u32>) -> u64 {
// Conditionally emit an island if it's necessary to resolve jumps
// between functions which are too far away.
let size = func.len() as u32;
@@ -1624,7 +1624,7 @@ impl<I: VCodeInst> TextSectionBuilder for MachTextSectionBuilder<I> {
self.buf.emit_island_maybe_forced(self.force_veneers, size);
}
self.buf.align_to(align);
self.buf.align_to(align.unwrap_or(I::LabelUse::ALIGN));
let pos = self.buf.cur_offset();
if named {
self.buf.bind_label(MachLabel::from_block(self.next_func));

View File

@@ -370,7 +370,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: u32) -> u64;
fn append(&mut self, labeled: bool, data: &[u8], align: Option<u32>) -> u64;
/// Attempts to resolve a relocation for this function.
///