Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mips64 N32 ABI #743

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ pub enum Architecture {
M68k,
Mips,
Mips64,
#[allow(non_camel_case_types)]
Mips64_N32,
Msp430,
PowerPc,
PowerPc64,
@@ -70,6 +72,7 @@ impl Architecture {
Architecture::M68k => Some(AddressSize::U32),
Architecture::Mips => Some(AddressSize::U32),
Architecture::Mips64 => Some(AddressSize::U64),
Architecture::Mips64_N32 => Some(AddressSize::U32),
Architecture::Msp430 => Some(AddressSize::U16),
Architecture::PowerPc => Some(AddressSize::U32),
Architecture::PowerPc64 => Some(AddressSize::U64),
8 changes: 7 additions & 1 deletion src/read/elf/file.rs
Original file line number Diff line number Diff line change
@@ -217,7 +217,13 @@ where
(elf::EM_HEXAGON, _) => Architecture::Hexagon,
(elf::EM_LOONGARCH, true) => Architecture::LoongArch64,
(elf::EM_68K, false) => Architecture::M68k,
(elf::EM_MIPS, false) => Architecture::Mips,
(elf::EM_MIPS, false) => {
if (self.header.e_flags(self.endian) & elf::EF_MIPS_ABI2) != 0 {
Architecture::Mips64_N32
} else {
Architecture::Mips
}
}
(elf::EM_MIPS, true) => Architecture::Mips64,
(elf::EM_MSP430, _) => Architecture::Msp430,
(elf::EM_PPC, _) => Architecture::PowerPc,
25 changes: 18 additions & 7 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@ impl<'a> Object<'a> {
Architecture::M68k => false,
Architecture::Mips => false,
Architecture::Mips64 => true,
Architecture::Mips64_N32 => true,
Architecture::Msp430 => true,
Architecture::PowerPc => true,
Architecture::PowerPc64 => true,
@@ -276,12 +277,16 @@ impl<'a> Object<'a> {
(RelocationKind::PltRelative, _, 32) => elf::R_68K_PLT32,
_ => return unsupported_reloc(),
},
Architecture::Mips | Architecture::Mips64 => match (kind, encoding, size) {
(K::Absolute, _, 16) => elf::R_MIPS_16,
(K::Absolute, _, 32) => elf::R_MIPS_32,
(K::Absolute, _, 64) => elf::R_MIPS_64,
_ => return unsupported_reloc(),
},
Architecture::Mips | Architecture::Mips64 | Architecture::Mips64_N32 => {
match (kind, encoding, size) {
(K::Absolute, _, 16) => elf::R_MIPS_16,
(K::Absolute, _, 32) => elf::R_MIPS_32,
(K::Absolute, _, 64) => elf::R_MIPS_64,
_ => {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
Tazdevil971 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Architecture::Msp430 => match (kind, encoding, size) {
(K::Absolute, _, 32) => elf::R_MSP430_32,
(K::Absolute, _, 16) => elf::R_MSP430_16_BYTE,
@@ -562,6 +567,7 @@ impl<'a> Object<'a> {
(Architecture::M68k, None) => elf::EM_68K,
(Architecture::Mips, None) => elf::EM_MIPS,
(Architecture::Mips64, None) => elf::EM_MIPS,
(Architecture::Mips64_N32, None) => elf::EM_MIPS,
(Architecture::Msp430, None) => elf::EM_MSP430,
(Architecture::PowerPc, None) => elf::EM_PPC,
(Architecture::PowerPc64, None) => elf::EM_PPC64,
@@ -581,7 +587,7 @@ impl<'a> Object<'a> {
)));
}
};
let (os_abi, abi_version, e_flags) = if let FileFlags::Elf {
let (os_abi, abi_version, mut e_flags) = if let FileFlags::Elf {
os_abi,
abi_version,
e_flags,
@@ -591,6 +597,11 @@ impl<'a> Object<'a> {
} else {
(elf::ELFOSABI_NONE, 0, 0)
};

if self.architecture == Architecture::Mips64_N32 {
e_flags |= elf::EF_MIPS_ABI2;
}

writer.write_file_header(&FileHeader {
os_abi,
abi_version,
1 change: 1 addition & 0 deletions tests/round_trip/mod.rs
Original file line number Diff line number Diff line change
@@ -275,6 +275,7 @@ fn elf_any() {
(Architecture::M68k, Endianness::Big),
(Architecture::Mips, Endianness::Little),
(Architecture::Mips64, Endianness::Little),
(Architecture::Mips64_N32, Endianness::Little),
(Architecture::Msp430, Endianness::Little),
(Architecture::PowerPc, Endianness::Big),
(Architecture::PowerPc64, Endianness::Big),