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()) {
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;
}
case COFF::IMAGE_REL_I386_SECREL: {
RelocationEntry RE = RelocationEntry(SectionID, Offset, RelType,
- getSymbolOffset(*Symbol));
+ getSymbolOffset(*Symbol) + Addend);
addRelocationForSection(RE, TargetSectionID);
break;
}
# 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@imgrel+1 // IMAGE_REL_I386_DIR32NB
+rel11:
+# rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.s.tmp.obj, .data) + 1
+ .long string@SECREL32+1 // IMAGE_REL_I386_SECREL