mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Autodetect endianness based on target triple
This commit is contained in:
@@ -200,7 +200,9 @@ impl Compiler for CraneliftCompiler {
|
||||
let (custom_sections, dwarf) = {
|
||||
let mut custom_sections = PrimaryMap::new();
|
||||
let dwarf = if let Some((dwarf_frametable, _cie_id)) = dwarf_frametable {
|
||||
let mut eh_frame = EhFrame(WriterRelocate::default());
|
||||
let mut eh_frame = EhFrame(WriterRelocate::new(
|
||||
self.target().triple().endianness().ok(),
|
||||
));
|
||||
dwarf_frametable
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ pub use crate::relocation::{Relocation, RelocationKind, RelocationTarget, Reloca
|
||||
pub use crate::section::{CustomSection, CustomSectionProtection, SectionBody, SectionIndex};
|
||||
pub use crate::sourceloc::SourceLoc;
|
||||
pub use crate::target::{
|
||||
Architecture, BinaryFormat, CallingConvention, CpuFeature, OperatingSystem,
|
||||
ParseCpuFeatureError, Target, Triple,
|
||||
Architecture, BinaryFormat, CallingConvention, CpuFeature, Endianness, OperatingSystem,
|
||||
ParseCpuFeatureError, PointerWidth, Target, Triple,
|
||||
};
|
||||
#[cfg(feature = "translator")]
|
||||
pub use crate::translator::{
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
use enumset::{EnumSet, EnumSetType};
|
||||
use std::str::FromStr;
|
||||
use std::string::ToString;
|
||||
pub use target_lexicon::{Architecture, BinaryFormat, CallingConvention, OperatingSystem, Triple};
|
||||
pub use target_lexicon::{
|
||||
Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth,
|
||||
Triple,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
|
||||
@@ -38,6 +38,10 @@ impl UnwindRegistry {
|
||||
|
||||
/// Publishes all registered functions.
|
||||
pub fn publish(&mut self, eh_frame: Option<&[u8]>) -> Result<(), String> {
|
||||
if self.published {
|
||||
return Err("unwind registry has already been published".to_string());
|
||||
}
|
||||
|
||||
if let Some(eh_frame) = eh_frame {
|
||||
unsafe {
|
||||
self.register_frames(eh_frame);
|
||||
|
||||
Reference in New Issue
Block a user