Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIPS: Support orphaned lo16 relocs. Fixes #627 #628

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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