mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[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@dronecode.org.uk> llvm-svn: 272911
This commit is contained in:
parent
0ed05f79e1
commit
3afea7f7d2
@ -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;
|
||||
}
|
||||
|
@ -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@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
|
||||
|
Loading…
x
Reference in New Issue
Block a user