From 15e3a9fe618df912948b08c56b10dab035aa8f01 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 21 Jan 2026 17:24:05 -0500 Subject: Implement R_386_IRELATIVE relocation handling. Closes #7851. --- arch/x86/arch_x86.cpp | 8 ++++++++ view/elf/elfview.cpp | 15 +++++++++++++++ view/elf/elfview.h | 3 +++ 3 files changed, 26 insertions(+) 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 #endif #include +#include #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 -- cgit v1.3.1