llvm.org GIT mirror llvm / 71b1fed
[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> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272911 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
2 changed file(s) with 34 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
5757 uint64_t RelType = RelI->getType();
5858 uint64_t Offset = RelI->getOffset();
5959
60 // Determine the Addend used to adjust the relocation value.
61 uint64_t Addend = 0;
62 SectionEntry &AddendSection = Sections[SectionID];
63 uintptr_t ObjTarget = AddendSection.getObjAddress() + Offset;
64 uint8_t *Displacement = (uint8_t *)ObjTarget;
65
66 switch (RelType) {
67 case COFF::IMAGE_REL_I386_DIR32:
68 case COFF::IMAGE_REL_I386_DIR32NB:
69 case COFF::IMAGE_REL_I386_SECREL:
70 case COFF::IMAGE_REL_I386_REL32: {
71 Addend = readBytesUnaligned(Displacement, 4);
72 break;
73 }
74 default:
75 break;
76 }
77
6078 #if !defined(NDEBUG)
6179 SmallString<32> RelTypeName;
6280 RelI->getTypeName(RelTypeName);
6381 #endif
6482 DEBUG(dbgs() << "\t\tIn Section " << SectionID << " Offset " << Offset
6583 << " RelType: " << RelTypeName << " TargetName: " << TargetName
66 << "\n");
84 << " Addend " << Addend << "\n");
6785
6886 unsigned TargetSectionID = -1;
6987 if (Section == Obj.section_end()) {
84102 case COFF::IMAGE_REL_I386_DIR32NB:
85103 case COFF::IMAGE_REL_I386_REL32: {
86104 RelocationEntry RE =
87 RelocationEntry(SectionID, Offset, RelType, 0, TargetSectionID,
105 RelocationEntry(SectionID, Offset, RelType, Addend, TargetSectionID,
88106 getSymbolOffset(*Symbol), 0, 0, false, 0);
89107 addRelocationForSection(RE, TargetSectionID);
90108 break;
97115 }
98116 case COFF::IMAGE_REL_I386_SECREL: {
99117 RelocationEntry RE = RelocationEntry(SectionID, Offset, RelType,
100 getSymbolOffset(*Symbol));
118 getSymbolOffset(*Symbol) + Addend);
101119 addRelocationForSection(RE, TargetSectionID);
102120 break;
103121 }
6363 # rtdyld-check: *{4}rel7 = relocations - section_addr(COFF_i386.s.tmp.obj, .data)
6464 .secrel32 relocations // IMAGE_REL_I386_SECREL
6565
66 # Test that addends work.
67 rel8:
68 # rtdyld-check: *{4}rel8 = string
69 .long string // IMAGE_REL_I386_DIR32
70 rel9:
71 # rtdyld-check: *{4}rel9 = string+1
72 .long string+1 // IMAGE_REL_I386_DIR32
73 rel10:
74 # rtdyld-check: *{4}rel10 = string - section_addr(COFF_i386.s.tmp.obj, .text) + 1
75 .long string@imgrel+1 // IMAGE_REL_I386_DIR32NB
76 rel11:
77 # rtdyld-check: *{4}rel11 = string - section_addr(COFF_i386.s.tmp.obj, .data) + 1
78 .long string@SECREL32+1 // IMAGE_REL_I386_SECREL