Autodetect endianness based on target triple

This commit is contained in:
Syrus
2020-06-11 00:31:04 -07:00
parent b463f738a2
commit ff8f3c8948
5 changed files with 27 additions and 17 deletions

View File

@ -3,7 +3,7 @@ use gimli::{RunTimeEndian, SectionId};
use wasm_common::entity::EntityRef;
use wasm_common::LocalFunctionIndex;
use wasmer_compiler::{CustomSection, CustomSectionProtection, SectionBody};
use wasmer_compiler::{Relocation, RelocationKind, RelocationTarget};
use wasmer_compiler::{Endianness, Relocation, RelocationKind, RelocationTarget};
#[derive(Clone, Debug)]
pub struct WriterRelocate {
@ -12,6 +12,19 @@ pub struct WriterRelocate {
}
impl WriterRelocate {
pub fn new(endianness: Option<Endianness>) -> Self {
let endianness = match endianness {
Some(Endianness::Little) => RunTimeEndian::Little,
Some(Endianness::Big) => RunTimeEndian::Big,
// We autodetect it, based on the host
None => RunTimeEndian::default(),
};
WriterRelocate {
relocs: Vec::new(),
writer: EndianVec::new(endianness),
}
}
pub fn into_section(mut self) -> CustomSection {
// GCC expects a terminating "empty" length, so write a 0 length at the end of the table.
self.writer.write_u32(0).unwrap();
@ -24,18 +37,6 @@ impl WriterRelocate {
}
}
impl Default for WriterRelocate {
fn default() -> Self {
WriterRelocate {
relocs: Vec::new(),
// writer: EndianVec::new(RunTimeEndian::Little),
// TODO: the endian is detected in the host, it should be detected based on
// the chosen target.
writer: EndianVec::new(RunTimeEndian::default()),
}
}
}
impl Writer for WriterRelocate {
type Endian = RunTimeEndian;