From 0568f4fb02f68b577653f81f7a62cb6881c67121 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 9 Nov 2020 18:19:33 +0100 Subject: [PATCH] Support building big-endian objects (#2382) The JIT build_object routine currently rejects building object files for any big-endian platform. However, most of the object builder code works fine for either byte order, with the exception of a small change in the ObjectBuilderTarget::new routine. This patch adds that change and removes the assert in build_object. --- crates/jit/src/object.rs | 4 ---- crates/obj/src/builder.rs | 9 ++++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/jit/src/object.rs b/crates/jit/src/object.rs index 0f83a8482e..f492d645fa 100644 --- a/crates/jit/src/object.rs +++ b/crates/jit/src/object.rs @@ -28,10 +28,6 @@ pub(crate) fn build_object( dwarf_sections: Vec, ) -> Result<(Object, Vec), anyhow::Error> { const CODE_SECTION_ALIGNMENT: u64 = 0x1000; - assert_eq!( - isa.triple().architecture.endianness(), - Ok(target_lexicon::Endianness::Little) - ); let mut unwind_info = Vec::new(); diff --git a/crates/obj/src/builder.rs b/crates/obj/src/builder.rs index ac83cde67e..046ae5f784 100644 --- a/crates/obj/src/builder.rs +++ b/crates/obj/src/builder.rs @@ -122,10 +122,6 @@ fn process_unwind_info(info: &UnwindInfo, obj: &mut Object, code_section: Sectio /// Builds ELF image from the module `Compilation`. // const CODE_SECTION_ALIGNMENT: u64 = 0x1000; -// assert_eq!( -// isa.triple().architecture.endianness(), -// Ok(target_lexicon::Endianness::Little) -// ); /// Iterates through all `LibCall` members and all runtime exported functions. #[macro_export] @@ -223,7 +219,10 @@ impl ObjectBuilderTarget { Ok(Self { binary_format: BinaryFormat::Elf, architecture: to_object_architecture(arch)?, - endianness: Endianness::Little, + endianness: match arch.endianness().unwrap() { + target_lexicon::Endianness::Little => object::Endianness::Little, + target_lexicon::Endianness::Big => object::Endianness::Big, + }, }) }