summaryrefslogtreecommitdiff
path: root/view/elf/elfview.cpp
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2025-03-03 09:21:58 -0500
committerBrian Potchik <brian@vector35.com>2025-03-03 09:21:58 -0500
commit7f17245620a4ddc6878ae79575dc78a9b10bceaa (patch)
tree084e3f0f159a05db3718e4a65bccfb65c8a07953 /view/elf/elfview.cpp
parent76db1e8e688403625c7949ceae81f98199de1f5a (diff)
Correctly perform fixups for MIPS32 local symbols using synthetic relocation entries.
Diffstat (limited to 'view/elf/elfview.cpp')
-rw-r--r--view/elf/elfview.cpp97
1 files changed, 51 insertions, 46 deletions
diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp
index 29fc03d9..87e126ee 100644
--- a/view/elf/elfview.cpp
+++ b/view/elf/elfview.cpp
@@ -1116,69 +1116,74 @@ bool ElfView::Init()
{
case ELF_STT_OBJECT:
case ELF_STT_NOTYPE:
- if (entry.section != ELF_SHN_UNDEF)
- DefineElfSymbol(DataSymbol, entry.name, gotEntry, true, entry.binding, 4, Type::PointerType(
- GetDefaultPlatform()->GetArchitecture(), Type::VoidType())->WithConfidence(BN_FULL_CONFIDENCE));
- else
+ {
+ bool relocationExists = false;
+ for (auto& reloc : relocs)
{
- bool relocationExists = false;
- for (auto& reloc : relocs)
+ if (reloc.offset == gotEntry)
{
- if (reloc.offset == gotEntry)
- {
- relocationExists = true;
- break;
- }
- }
- if (!relocationExists)
- {
- int relocType = m_arch->GetAddressSize() == 4 ? 126 /* R_MIPS_COPY */ : 125 /* R_MIPS64_COPY */;
- relocs.push_back(ELFRelocEntry(gotEntry, i, relocType, 0, 0, false));
+ relocationExists = true;
+ break;
}
- DefineElfSymbol(ImportAddressSymbol, entry.name, gotEntry, true, entry.binding, entry.size);
}
+ if (!relocationExists)
+ {
+ int relocType = m_arch->GetAddressSize() == 4 ? 126 /* R_MIPS_COPY */ : 125 /* R_MIPS64_COPY */;
+ relocs.push_back(ELFRelocEntry(gotEntry, i, relocType, 0, 0, false));
+ }
+ if (entry.section != ELF_SHN_UNDEF)
+ {
+ DefineElfSymbol(DataSymbol, entry.name, gotEntry, true, entry.binding, 4,
+ Type::PointerType(GetDefaultPlatform()->GetArchitecture(),
+ Type::VoidType())->WithConfidence(BN_FULL_CONFIDENCE));
+ }
+ else
+ DefineElfSymbol(ImportAddressSymbol, entry.name, gotEntry, true, entry.binding, entry.size);
break;
+ }
case ELF_STT_FUNC:
+ {
+ bool relocationExists = false;
+ for (auto& reloc : relocs)
+ {
+ if (reloc.offset == gotEntry)
+ {
+ relocationExists = true;
+ break;
+ }
+ }
+ if (!relocationExists)
+ {
+ int relocType = m_arch->GetAddressSize() == 4 ? 127 /*R_MIPS_JUMP_SLOT*/ : 125 /* R_MIPS64_COPY */;
+ relocs.push_back(ELFRelocEntry(gotEntry, i, relocType, 0, 0, false));
+ }
if (entry.section != ELF_SHN_UNDEF)
+ {
DefineElfSymbol(DataSymbol, entry.name, gotEntry, true, entry.binding, 4,
Type::PointerType(GetDefaultPlatform()->GetArchitecture(),
Type::FunctionType(Type::IntegerType(GetDefaultPlatform()->GetArchitecture()->GetAddressSize(), true),
GetDefaultPlatform()->GetDefaultCallingConvention(), vector<FunctionParameter>())->WithConfidence(0)));
+ }
else
- {
- bool relocationExists = false;
- for (auto& reloc : relocs)
- {
- if (reloc.offset == gotEntry)
- {
- relocationExists = true;
- break;
- }
- }
- if (!relocationExists)
- {
- int relocType = m_arch->GetAddressSize() == 4 ? 127 /*R_MIPS_JUMP_SLOT*/ : 125 /* R_MIPS64_COPY */;
- relocs.push_back(ELFRelocEntry(gotEntry, i, relocType, 0, 0, false));
- }
DefineElfSymbol(ImportAddressSymbol, entry.name, gotEntry, true, entry.binding, entry.size);
- // TODO for now create associated PLT entry if it exists. At some point we could extend the detection in RecognizeELFPLTEntries in arch_mips.
- Ref<Symbol> sym = GetSymbolByAddress(gotEntry);
- if (entry.value && sym && (sym->GetType() == ImportAddressSymbol))
+ // TODO for now create associated PLT entry if it exists. At some point we could extend the detection in RecognizeELFPLTEntries in arch_mips.
+ Ref<Symbol> sym = GetSymbolByAddress(gotEntry);
+ if (entry.value && sym && (sym->GetType() == ImportAddressSymbol))
+ {
+ uint64_t adjustedAddress = entry.value + imageBaseAdjustment;
+ Ref<Platform> targetPlatform = platform->GetAssociatedPlatformByAddress(adjustedAddress);
+ Ref<Function> func = AddFunctionForAnalysis(targetPlatform, adjustedAddress);
+ if (func)
{
- uint64_t adjustedAddress = entry.value + imageBaseAdjustment;
- Ref<Platform> targetPlatform = platform->GetAssociatedPlatformByAddress(adjustedAddress);
- Ref<Function> func = AddFunctionForAnalysis(targetPlatform, adjustedAddress);
- if (func)
- {
- Ref<Symbol> funcSym = new Symbol(ImportedFunctionSymbol,
- sym->GetShortName(), sym->GetFullName(), sym->GetRawName(),
- adjustedAddress, NoBinding, sym->GetNameSpace(), sym->GetOrdinal());
- DefineAutoSymbol(funcSym);
- func->ApplyImportedTypes(funcSym);
- }
+ Ref<Symbol> funcSym = new Symbol(ImportedFunctionSymbol,
+ sym->GetShortName(), sym->GetFullName(), sym->GetRawName(),
+ adjustedAddress, NoBinding, sym->GetNameSpace(), sym->GetOrdinal());
+ DefineAutoSymbol(funcSym);
+ func->ApplyImportedTypes(funcSym);
}
}
break;
+ }
default:
m_logger->LogDebug("ELF symbol type of %d not handled.", entry.type);
break;