Skip to content

Commit

Permalink
Added arch-alignment to wasmer-object
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed May 15, 2021
1 parent 0722dd8 commit 96643d8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/object/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ pub fn emit_compilation(

let debug_index = compilation.get_debug().map(|d| d.eh_frame);

let align = match triple.architecture {
Architecture::X86_64 => 1,
// In Arm64 is recommended a 4-byte alignment
Architecture::Aarch64(_) => 4,
_ => 1,
};

// Add sections
let custom_section_ids = custom_sections
.into_iter()
Expand All @@ -147,7 +154,7 @@ pub fn emit_compilation(
let segment = obj.segment_name(StandardSegment::Debug).to_vec();
let section_id =
obj.add_section(segment, DWARF_SECTION_NAME.to_vec(), SectionKind::Debug);
obj.append_section_data(section_id, custom_section.bytes.as_slice(), 1);
obj.append_section_data(section_id, custom_section.bytes.as_slice(), align);
let section_name = symbol_registry.symbol_to_name(Symbol::Section(section_index));
let symbol_id = obj.add_symbol(ObjSymbol {
name: section_name.into_bytes(),
Expand Down Expand Up @@ -179,7 +186,7 @@ pub fn emit_compilation(
section: SymbolSection::Section(section_id),
flags: SymbolFlags::None,
});
obj.add_symbol_data(symbol_id, section_id, custom_section.bytes.as_slice(), 1);
obj.add_symbol_data(symbol_id, section_id, custom_section.bytes.as_slice(), align);
(section_id, symbol_id)
}
})
Expand All @@ -202,7 +209,7 @@ pub fn emit_compilation(
section: SymbolSection::Section(section_id),
flags: SymbolFlags::None,
});
obj.add_symbol_data(symbol_id, section_id, &function.body, 1);
obj.add_symbol_data(symbol_id, section_id, &function.body, align);
(section_id, symbol_id)
})
.collect::<PrimaryMap<LocalFunctionIndex, _>>();
Expand All @@ -222,7 +229,7 @@ pub fn emit_compilation(
section: SymbolSection::Section(section_id),
flags: SymbolFlags::None,
});
obj.add_symbol_data(symbol_id, section_id, &function.body, 1);
obj.add_symbol_data(symbol_id, section_id, &function.body, align);
}

// Add dynamic function trampolines
Expand All @@ -240,7 +247,7 @@ pub fn emit_compilation(
section: SymbolSection::Section(section_id),
flags: SymbolFlags::None,
});
obj.add_symbol_data(symbol_id, section_id, &function.body, 1);
obj.add_symbol_data(symbol_id, section_id, &function.body, align);
}

let mut all_relocations = Vec::new();
Expand Down

0 comments on commit 96643d8

Please sign in to comment.