summaryrefslogtreecommitdiff
path: root/view/elf
diff options
context:
space:
mode:
authorAlexander Taylor <alex@vector35.com>2026-01-21 17:24:05 -0500
committerAlexander Taylor <alex@vector35.com>2026-01-23 10:35:45 -0500
commit15e3a9fe618df912948b08c56b10dab035aa8f01 (patch)
tree57dd18460da73924eb1343c56d7d71d2a342b035 /view/elf
parent4e72219707ba28e7ca18816cb74c664006696d99 (diff)
Implement R_386_IRELATIVE relocation handling.
Closes #7851.
Diffstat (limited to 'view/elf')
-rw-r--r--view/elf/elfview.cpp15
-rw-r--r--view/elf/elfview.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp
index 3a4b37fe..46039e80 100644
--- a/view/elf/elfview.cpp
+++ b/view/elf/elfview.cpp
@@ -3,6 +3,7 @@
#include <cxxabi.h>
#endif
#include <inttypes.h>
+#include <cstring>
#include "elfview.h"
#define STRING_READ_CHUNK_SIZE 32
@@ -1471,6 +1472,20 @@ bool ElfView::Init()
if (relocInfo.type == IgnoredRelocation)
continue;
+ if ((relocInfo.symbolIndex == 0) && (m_arch && (m_arch->GetName() == "x86"))
+ && (relocInfo.nativeType == R_386_IRELATIVE))
+ {
+ uint64_t addend = relocInfo.addend;
+ if (relocInfo.implicitAddend && (relocInfo.size > 0) && (relocInfo.size <= sizeof(addend)))
+ memcpy(&addend, relocInfo.relocationDataCache, relocInfo.size);
+ uint64_t target = addend;
+ if (imageBaseAdjustment != 0)
+ target += imageBaseAdjustment;
+ if (auto targetSymbol = GetSymbolByAddress(target); targetSymbol && !GetSymbolByAddress(relocInfo.address))
+ DefineElfSymbol(ImportAddressSymbol, targetSymbol->GetRawName(), relocInfo.address, true,
+ targetSymbol->GetBinding());
+ }
+
// Define absolute relocations with no symbol specified such as R_PPC_RELATIVE and R_ARM_IRELATIVE
// Define unhandled relocations in order to detect them and avoid creating functions at invalid target addresses
if ((relocInfo.symbolIndex == 0) || (relocInfo.type == UnhandledRelocation))
diff --git a/view/elf/elfview.h b/view/elf/elfview.h
index b9690bef..0e8679b3 100644
--- a/view/elf/elfview.h
+++ b/view/elf/elfview.h
@@ -340,6 +340,9 @@
// #define ELF_SHN_MIPS_SCOMMON 0xff03
// #define ELF_SHN_MIPS_SUNDEFINED 0xff04
+// x86 ONLY
+#define R_386_IRELATIVE 0x2a
+
// ARM ONLY
#define R_ARM_TLS_DTPMOD32 0x11
#define R_ARM_TLS_DTPOFF32 0x12