mirror of
https://github.com/mii443/wasmer.git
synced 2025-09-01 23:19:14 +00:00
Autodetect endianness based on target triple
This commit is contained in:
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user