Skip to content

Commit 770e9c0

Browse files
committed
Implement DTPOFF64 and DTPMOD64 relocations.
Finally closes #5463.
1 parent 0f3abc6 commit 770e9c0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

arch/x86/arch_x86.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4416,6 +4416,16 @@ class x64ElfRelocationHandler: public RelocationHandler
44164416
memcpy(dest, (uint8_t*)&write, sizeof(uint64_t));
44174417
return true;
44184418
}
4419+
case R_X86_64_DTPMOD64: {
4420+
uint64_t write = 0;
4421+
memcpy(dest, (uint8_t*)&write, sizeof(uint64_t));
4422+
return true;
4423+
}
4424+
case R_X86_64_DTPOFF64: {
4425+
uint64_t write = reloc->GetTarget() + info.addend;
4426+
memcpy(dest, (uint8_t*)&write, sizeof(uint64_t));
4427+
return true;
4428+
}
44194429
default:
44204430
return RelocationHandler::ApplyRelocation(view, arch, reloc, dest, len);
44214431
}
@@ -4509,6 +4519,21 @@ class x64ElfRelocationHandler: public RelocationHandler
45094519
reloc.size = 8;
45104520
reloc.truncateSize = 8;
45114521
break;
4522+
case R_X86_64_DTPMOD64:
4523+
reloc.pcRelative = false;
4524+
reloc.baseRelative = false;
4525+
reloc.hasSign = false;
4526+
reloc.size = 8;
4527+
reloc.truncateSize = 8;
4528+
reloc.symbolIndex = 0;
4529+
break;
4530+
case R_X86_64_DTPOFF64:
4531+
reloc.pcRelative = false;
4532+
reloc.baseRelative = false;
4533+
reloc.hasSign = false;
4534+
reloc.size = 8;
4535+
reloc.truncateSize = 8;
4536+
break;
45124537
case R_X86_64_GOTOFF64:
45134538
case R_X86_64_GOT64:
45144539
case R_X86_64_GOTPLT64:

view/elf/elfview.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,13 @@ bool ElfView::Init()
14801480
else if(reloc.relocType == R_ARM_TLS_DTPMOD32)
14811481
tlsModuleStarts.push_back(reloc.offset);
14821482
}
1483+
else if (m_arch && (m_arch->GetName() == "x86_64"))
1484+
{
1485+
if (reloc.relocType == R_X86_64_DTPOFF64)
1486+
tlsOffsets.push_back(reloc.offset);
1487+
else if (reloc.relocType == R_X86_64_DTPMOD64)
1488+
tlsModuleStarts.push_back(reloc.offset);
1489+
}
14831490
}
14841491

14851492
if (relocHandler->GetRelocationInfo(this, m_arch, m_relocationInfo))
@@ -2496,10 +2503,13 @@ bool ElfView::Init()
24962503
}
24972504

24982505
// Add type, data variables for TLS entries
2506+
size_t tlsModuleEntrySize = 4;
2507+
if (m_arch && (m_arch->GetAddressSize() == 8))
2508+
tlsModuleEntrySize = 8;
24992509
for (auto offset : tlsModuleStarts)
25002510
{
25012511
/* All module ID's are set to 0. */
2502-
DefineDataVariable(offset, Type::IntegerType(4, false)->WithConfidence(BN_FULL_CONFIDENCE));
2512+
DefineDataVariable(offset, Type::IntegerType(tlsModuleEntrySize, false)->WithConfidence(BN_FULL_CONFIDENCE));
25032513
}
25042514
for (auto offset : tlsOffsets)
25052515
{

view/elf/elfview.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
// x86 ONLY
344344
#define R_386_IRELATIVE 0x2a
345345

346+
// x86-64 ONLY
347+
#define R_X86_64_DTPMOD64 0x10
348+
#define R_X86_64_DTPOFF64 0x11
349+
346350
// ARM ONLY
347351
#define R_ARM_TLS_DTPMOD32 0x11
348352
#define R_ARM_TLS_DTPOFF32 0x12

0 commit comments

Comments
 (0)