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:
@@ -264,9 +264,11 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
traps.push(range.clone(), &func.traps);
|
||||
func_starts.push(range.start);
|
||||
if self.linkopts.padding_between_functions > 0 {
|
||||
builder
|
||||
.text
|
||||
.append(false, &vec![0; self.linkopts.padding_between_functions], 1);
|
||||
builder.text.append(
|
||||
false,
|
||||
&vec![0; self.linkopts.padding_between_functions],
|
||||
Some(1),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,12 +184,12 @@ impl<'a> ObjectBuilder<'a> {
|
||||
/// that the function resides within the text section.
|
||||
fn append_func(
|
||||
&mut self,
|
||||
wat: bool,
|
||||
labeled: bool,
|
||||
name: Vec<u8>,
|
||||
func: &'a CompiledFunction,
|
||||
) -> (SymbolId, Range<u64>) {
|
||||
let body_len = func.body.len() as u64;
|
||||
let off = self.text.append(wat, &func.body, 1);
|
||||
let off = self.text.append(labeled, &func.body, None);
|
||||
|
||||
let symbol_id = self.obj.add_symbol(Symbol {
|
||||
name,
|
||||
@@ -215,7 +215,7 @@ impl<'a> ObjectBuilder<'a> {
|
||||
let unwind_size = info.emit_size();
|
||||
let mut unwind_info = vec![0; unwind_size];
|
||||
info.emit(&mut unwind_info);
|
||||
let unwind_off = self.text.append(false, &unwind_info, 4);
|
||||
let unwind_off = self.text.append(false, &unwind_info, Some(4));
|
||||
self.windows_unwind_info.push(RUNTIME_FUNCTION {
|
||||
begin: u32::try_from(off).unwrap(),
|
||||
end: u32::try_from(off + body_len).unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user