Skip to content

Commit 9b03ef6

Browse files
committed
Fix MIPS64 relocation entry parsing.
1 parent 585882c commit 9b03ef6

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

view/elf/elfview.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,35 @@ void ElfView::GetRelocEntries(BinaryReader& reader, const vector<Elf64SectionHea
430430
for (uint64_t j = 0; j < section.size / relocSize; j++)
431431
{
432432
reader.Seek(section.offset + (j * relocSize));
433+
if (!m_elf32 && (m_commonHeader.arch == EM_MIPS))
434+
{
435+
// MIPS64 relocations apparently use dedicated r_sym/r_type fields.
436+
// See page 40, table 29 of the 64-bit ELF Object File Specification
437+
// published by MIPS/SGCS (document no. 007-4658-001).
438+
uint64_t ofs = reader.Read64();
439+
uint64_t sym = reader.Read32();
440+
uint32_t ssym = reader.Read8();
441+
uint32_t type3 = reader.Read8();
442+
uint32_t type2 = reader.Read8();
443+
uint32_t type = reader.Read8();
444+
uint64_t addend = 0;
445+
if (!implicit)
446+
addend = reader.Read64();
447+
uint64_t relocType = type | (type2 << 8) | (type3 << 16);
448+
(void)ssym;
449+
result.push_back(ELFRelocEntry(ofs, sym, relocType, addend, section.info, implicit));
450+
continue;
451+
}
452+
433453
uint64_t ofs = m_elf32 ? reader.Read32() : reader.Read64();
434454
uint64_t info = m_elf32 ? reader.Read32() : reader.Read64();
435455
uint64_t addend = 0;
436456
if (!implicit)
437457
addend = m_elf32 ? reader.Read32() : reader.Read64();
438458

439-
result.push_back(ELFRelocEntry(ofs, info >> (m_elf32 ? 8 : 32), info & (m_elf32 ? 0xff : 0xffffffff),
440-
addend, section.info, implicit));
459+
uint64_t sym = info >> (m_elf32 ? 8 : 32);
460+
uint64_t relocType = info & (m_elf32 ? 0xff : 0xffffffff);
461+
result.push_back(ELFRelocEntry(ofs, sym, relocType, addend, section.info, implicit));
441462
}
442463
}
443464
}

0 commit comments

Comments
 (0)