[llvm] r272911 - [PATCH] Fix RuntimeDyldCOFFI386 to handle relocations with a non-zero addend
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 16 09:21:41 PDT 2016
Author: rnk
Date: Thu Jun 16 11:21:41 2016
New Revision: 272911
URL: http://llvm.org/viewvc/llvm-project?rev=272911&view=rev
Log:
[PATCH] Fix RuntimeDyldCOFFI386 to handle relocations with a non-zero addend
This fixes IMAGE_REL_I386_DIR32, IMAGE_REL_I386_DIR32NB,
IMAGE_REL_I386_SECREL, and IMAGE_REL_I386_REL32 relocations.
Based on patch by Jon Turney <jon.turney at dronecode.org.uk>
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h?rev=272911&r1=272910&r2=272911&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h Thu Jun 16 11:21:41 2016
@@ -58,13 +58,31 @@ public:
uint64_t RelType = RelI->getType();
uint64_t Offset = RelI->getOffset();
+ // Determine the Addend used to adjust the relocation value.
+ uint64_t Addend = 0;
+ SectionEntry &AddendSection = Sections[SectionID];
+ uintptr_t ObjTarget = AddendSection.getObjAddress() + Offset;
+ uint8_t *Displacement = (uint8_t *)ObjTarget;
+
+ switch (RelType) {
+ case COFF::IMAGE_REL_I386_DIR32:
+ case COFF::IMAGE_REL_I386_DIR32NB:
+ case COFF::IMAGE_REL_I386_SECREL:
+ case COFF::IMAGE_REL_I386_REL32: {
+ Addend = readBytesUnaligned(Displacement, 4);
+ break;
+ }
+ default:
+ break;
+ }
+
#if !defined(NDEBUG)
SmallString<32> RelTypeName;
RelI->getTypeName(RelTypeName);
#endif
DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
<< " RelType: " << RelTypeName << " TargetName: " << TargetName
- << "\n");
+ << " Addend " << Addend << "\n");
unsigned TargetSectionID = -1;
if (Section == Obj.section_end()) {
@@ -85,7 +103,7 @@ public:
case COFF::IMAGE_REL_I386_DIR32NB:
case COFF::IMAGE_REL_I386_REL32: {
RelocationEntry RE =
- RelocationEntry(SectionID, Offset, RelType, 0, TargetSectionID,
+ RelocationEntry(SectionID, Offset, RelType, Addend, TargetSectionID,
getSymbolOffset(*Symbol), 0, 0, false, 0);
addRelocationForSection(RE, TargetSectionID);
break;
@@ -98,7 +116,7 @@ public:
}
case COFF::IMAGE_REL_I386_SECREL: {
RelocationEntry RE = RelocationEntry(SectionID, Offset, RelType,
- getSymbolOffset(*Symbol));
+ getSymbolOffset(*Symbol) + Addend);
addRelocationForSection(RE, TargetSectionID);
break;
}
Modified: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s?rev=272911&r1=272910&r2=272911&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s Thu Jun 16 11:21:41 2016
@@ -64,3 +64,16 @@ rel7:
# rtdyld-check: *{4}rel7 = relocations - section_addr(COFF_i386.s.tmp.obj, .data)
.secrel32 relocations // IMAGE_REL_I386_SECREL
+# Test that addends work.
+rel8:
+# rtdyld-check: *{4}rel8 = string
+ .long string // IMAGE_REL_I386_DIR32
+rel9:
+# rtdyld-check: *{4}rel9 = string+1
+ .long string+1 // IMAGE_REL_I386_DIR32
+rel10:
+# rtdyld-check: *{4}rel10 = string - section_addr(COFF_i386.s.tmp.obj, .text) + 1
+ .long string at imgrel+1 // IMAGE_REL_I386_DIR32NB
+rel11:
+# rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.s.tmp.obj, .data) + 1
+ .long string at SECREL32+1 // IMAGE_REL_I386_SECREL
More information about the llvm-commits
mailing list