Skip to content

Commit

Permalink
add LoongArch64 ELF absolute relocation support
Browse files Browse the repository at this point in the history
  • Loading branch information
xry111 committed Mar 31, 2022
1 parent 7d84f88 commit 4f286da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/read/elf/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ fn parse_relocation<Elf: FileHeader>(
elf::R_HEX_32 => (RelocationKind::Absolute, 32),
r_type => (RelocationKind::Elf(r_type), 0),
},
elf::EM_LOONGARCH => match reloc.r_type(endian, false) {
elf::R_LARCH_32 => (RelocationKind::Absolute, 32),
elf::R_LARCH_64 => (RelocationKind::Absolute, 64),
r_type => (RelocationKind::Elf(r_type), 0),
},
elf::EM_MIPS => match reloc.r_type(endian, is_mips64el) {
elf::R_MIPS_16 => (RelocationKind::Absolute, 16),
elf::R_MIPS_32 => (RelocationKind::Absolute, 32),
Expand Down
9 changes: 9 additions & 0 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@ impl<'a> Object<'a> {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
Architecture::LoongArch64 => match (reloc.kind, reloc.encoding, reloc.size)
{
(RelocationKind::Absolute, _, 32) => elf::R_LARCH_32,
(RelocationKind::Absolute, _, 64) => elf::R_LARCH_64,
(RelocationKind::Elf(x), _, _) => x,
_ => {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
Architecture::Mips | Architecture::Mips64 => {
match (reloc.kind, reloc.encoding, reloc.size) {
(RelocationKind::Absolute, _, 16) => elf::R_MIPS_16,
Expand Down
1 change: 1 addition & 0 deletions tests/round_trip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ fn elf_any() {
(Architecture::X86_64, Endianness::Little),
(Architecture::X86_64_X32, Endianness::Little),
(Architecture::Hexagon, Endianness::Little),
(Architecture::LoongArch64, Endianness::Little),
(Architecture::Mips, Endianness::Little),
(Architecture::Mips64, Endianness::Little),
(Architecture::Msp430, Endianness::Little),
Expand Down

0 comments on commit 4f286da

Please sign in to comment.