diff --git a/src/read/elf/relocation.rs b/src/read/elf/relocation.rs index 5930613a..557b80ef 100644 --- a/src/read/elf/relocation.rs +++ b/src/read/elf/relocation.rs @@ -301,6 +301,11 @@ fn parse_relocation( 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), diff --git a/src/write/elf/object.rs b/src/write/elf/object.rs index 4cf38b27..6c0af424 100644 --- a/src/write/elf/object.rs +++ b/src/write/elf/object.rs @@ -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, diff --git a/tests/round_trip/mod.rs b/tests/round_trip/mod.rs index e83b2c22..120092ee 100644 --- a/tests/round_trip/mod.rs +++ b/tests/round_trip/mod.rs @@ -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),