From d14513b4abcd436082a768b73de9932fe67646e6 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Mon, 2 Dec 2024 11:18:21 -0500 Subject: Multiple fixes for HI16/LO16 relocs for MIPS64 Some binaries consist of LO16 entires that are BEFORE associated HI16 entries. Also, prior to this commit we don't appear to be applying HI16 relocations at all for MIPS64. mips_decompose was being called with MIPS_32 and failing prior to fixing up the relocation --- arch/mips/arch_mips.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'arch/mips') diff --git a/arch/mips/arch_mips.cpp b/arch/mips/arch_mips.cpp index 83f3177c..4079519a 100644 --- a/arch/mips/arch_mips.cpp +++ b/arch/mips/arch_mips.cpp @@ -3011,7 +3011,7 @@ public: uint32_t inst2 = *(uint32_t*)(cur->relocationDataCache); Instruction instruction; memset(&instruction, 0, sizeof(instruction)); - if (mips_decompose(&inst2, sizeof(uint32_t), &instruction, MIPS_32, cur->address, arch->GetEndianness(), DECOMPOSE_FLAGS_PSEUDO_OP)) + if (mips_decompose(&inst2, sizeof(uint32_t), &instruction, arch->GetAddressSize() == 8 ? MIPS_64 : MIPS_32, cur->address, arch->GetEndianness(), DECOMPOSE_FLAGS_PSEUDO_OP)) break; int32_t immediate = swap(inst2) & 0xffff; @@ -3115,8 +3115,9 @@ public: case R_MIPS_HI16: result[i].dataRelocation = false; result[i].pcRelative = false; - // MIPS_HI16 relocations can have multiple MIPS_LO16 relocations following them - for (size_t j = i + 1; j < result.size(); j++) + // MIPS_HI16 relocations usually come before multiple MIPS_LO16 relocations. But, this is not always + // the case. Some binaries have MIPS_HI16 relocations after an associated MIPS_LO16 relocation. + for (size_t j = 0; j < result.size(); j++) { if (result[j].nativeType == R_MIPS_LO16 && result[j].symbolIndex == result[i].symbolIndex) { @@ -3128,6 +3129,7 @@ public: break; } } + break; case R_MIPS_LO16: result[i].pcRelative = false; -- cgit v1.3.1