summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86/arch_x86.cpp8
-rw-r--r--view/elf/elfview.cpp15
-rw-r--r--view/elf/elfview.h3
3 files changed, 26 insertions, 0 deletions
diff --git a/arch/x86/arch_x86.cpp b/arch/x86/arch_x86.cpp
index 708135a7..22bab67d 100644
--- a/arch/x86/arch_x86.cpp
+++ b/arch/x86/arch_x86.cpp
@@ -4150,6 +4150,14 @@ public:
reloc.truncateSize = 4;
reloc.implicitAddend = false;
break;
+ case R_386_IRELATIVE:
+ reloc.pcRelative = false;
+ reloc.baseRelative = false;
+ reloc.hasSign = false;
+ reloc.size = 4;
+ reloc.truncateSize = 4;
+ reloc.implicitAddend = true;
+ break;
default:
reloc.type = UnhandledRelocation;
relocTypes.insert(reloc.nativeType);
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