Skip to content

Commit

Permalink
MIPS: Support orphaned lo16 relocs. Fixes #627
Browse files Browse the repository at this point in the history
MIPS: Add support for orphaned lo16 relocations.

This fixes issue #627
  • Loading branch information
bmourit authored and PeterMatula committed Sep 12, 2019
1 parent 9837e1a commit 604049a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/loader/loader/elf/elf_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ void ElfImage::resolveRelocation(const retdec::fileformat::Relocation& rel, cons
case retdec::fileformat::Architecture::MIPS:
{
static const retdec::fileformat::Relocation* lastMipsHi16 = nullptr;
static const retdec::fileformat::Relocation* prevMipsHi16 = nullptr;

switch (rel.getType())
{
Expand Down Expand Up @@ -791,6 +792,11 @@ void ElfImage::resolveRelocation(const retdec::fileformat::Relocation& rel, cons
}
case R_MIPS_LO16:
{
// MIPS abi allows a single hi16 value to be used with multiple lo16 values
// if lo16 is found without a matching hi16, use the previous hi16 value
if (lastMipsHi16 == nullptr)
lastMipsHi16 = prevMipsHi16;

if (lastMipsHi16 == nullptr)
return;

Expand All @@ -806,6 +812,7 @@ void ElfImage::resolveRelocation(const retdec::fileformat::Relocation& rel, cons
valueLo = value & 0xFFFF;
set2Byte(lastMipsHi16->getAddress() + 2, valueHi);
set2Byte(rel.getAddress() + 2, valueLo);
prevMipsHi16 = lastMipsHi16;
lastMipsHi16 = nullptr;
break;
}
Expand Down

0 comments on commit 604049a

Please sign in to comment.