From 2e2f9d90126397c3fb31281b0ce8957575a3554a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 18 May 2021 07:23:04 -0700 Subject: [PATCH 1/3] Add basic support for mips64/powerpc/powerpc64/riscv64 Added for rust-lang/rust#84449 --- src/common.rs | 8 ++++++++ src/write/elf.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/common.rs b/src/common.rs index 864e9292..3b0d08a1 100644 --- a/src/common.rs +++ b/src/common.rs @@ -7,8 +7,12 @@ pub enum Architecture { Arm, I386, Mips, + Mips64, S390x, Wasm32, + PowerPc, + PowerPc64, + Riscv64, X86_64, } @@ -23,9 +27,13 @@ impl Architecture { Architecture::Arm => Some(AddressSize::U32), Architecture::I386 => Some(AddressSize::U32), Architecture::Mips => Some(AddressSize::U32), + Architecture::Mips64 => Some(AddressSize::U64), Architecture::S390x => Some(AddressSize::U64), Architecture::Wasm32 => Some(AddressSize::U32), Architecture::X86_64 => Some(AddressSize::U64), + Architecture::PowerPc => Some(AddressSize::U32), + Architecture::PowerPc64 => Some(AddressSize::U64), + Architecture::Riscv64 => Some(AddressSize::U64), } } } diff --git a/src/write/elf.rs b/src/write/elf.rs index d3ce541e..43df68b9 100644 --- a/src/write/elf.rs +++ b/src/write/elf.rs @@ -77,6 +77,10 @@ impl Object { Architecture::X86_64 => true, Architecture::S390x => true, Architecture::Mips => false, + Architecture::Mips64 => false, + Architecture::PowerPc => false, + Architecture::PowerPc64 => false, + Architecture::Riscv64 => false, _ => { return Err(Error(format!( "unimplemented architecture {:?}", @@ -349,6 +353,10 @@ impl Object { Architecture::X86_64 => elf::EM_X86_64, Architecture::S390x => elf::EM_S390, Architecture::Mips => elf::EM_MIPS, + Architecture::Mips64 => elf::EM_MIPS, + Architecture::PowerPc => elf::EM_PPC, + Architecture::PowerPc64 => elf::EM_PPC64, + Architecture::Riscv64 => elf::EM_RISCV, _ => { return Err(Error(format!( "unimplemented architecture {:?}", From 1410b1adc706411c06684b5cb88bedb053e1c64d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 18 May 2021 07:56:17 -0700 Subject: [PATCH 2/3] Add SHF_EXCLUDE constant for ELF --- src/elf.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elf.rs b/src/elf.rs index 69e7d109..249ce8da 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -735,6 +735,8 @@ pub const SHF_COMPRESSED: u32 = 1 << 11; pub const SHF_MASKOS: u32 = 0x0ff0_0000; /// Processor-specific section flags. pub const SHF_MASKPROC: u32 = 0xf000_0000; +/// This section is excluded from the final executable or shared library. +pub const SHF_EXCLUDE: u32 = 0x8000_0000; /// Section compression header. /// From 10479b6e8dc5d0886de368b07e14d4e844f0b7fa Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 20 May 2021 07:18:49 -0700 Subject: [PATCH 3/3] Add basic riscv32 support --- src/common.rs | 2 ++ src/write/elf.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/common.rs b/src/common.rs index 3b0d08a1..872cc6ce 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,6 +12,7 @@ pub enum Architecture { Wasm32, PowerPc, PowerPc64, + Riscv32, Riscv64, X86_64, } @@ -34,6 +35,7 @@ impl Architecture { Architecture::PowerPc => Some(AddressSize::U32), Architecture::PowerPc64 => Some(AddressSize::U64), Architecture::Riscv64 => Some(AddressSize::U64), + Architecture::Riscv32 => Some(AddressSize::U32), } } } diff --git a/src/write/elf.rs b/src/write/elf.rs index 43df68b9..e93a193b 100644 --- a/src/write/elf.rs +++ b/src/write/elf.rs @@ -81,6 +81,7 @@ impl Object { Architecture::PowerPc => false, Architecture::PowerPc64 => false, Architecture::Riscv64 => false, + Architecture::Riscv32 => false, _ => { return Err(Error(format!( "unimplemented architecture {:?}", @@ -357,6 +358,7 @@ impl Object { Architecture::PowerPc => elf::EM_PPC, Architecture::PowerPc64 => elf::EM_PPC64, Architecture::Riscv64 => elf::EM_RISCV, + Architecture::Riscv32 => elf::EM_RISCV, _ => { return Err(Error(format!( "unimplemented architecture {:?}",