llvm.org GIT mirror llvm / 8c34a3f
[RuntimeDyld][MachO] Add support for SUBTRACTOR relocations between anonymous symbols on x86-64. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270157 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 4 years ago
2 changed file(s) with 79 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
156156
157157 Expected
158158 processSubtractRelocation(unsigned SectionID, relocation_iterator RelI,
159 const ObjectFile &BaseObjT,
159 const MachOObjectFile &BaseObj,
160160 ObjSectionToIDMap &ObjSectionToID) {
161161 const MachOObjectFile &Obj =
162 static_cast(BaseObjT);
162 static_cast(BaseObj);
163163 MachO::any_relocation_info RE =
164164 Obj.getRelocation(RelI->getRawDataRefImpl());
165165
167167 uint64_t Offset = RelI->getOffset();
168168 uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);
169169 unsigned NumBytes = 1 << Size;
170
171 Expected SubtrahendNameOrErr = RelI->getSymbol()->getName();
172 if (!SubtrahendNameOrErr)
173 return SubtrahendNameOrErr.takeError();
174 auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
175 unsigned SectionBID = SubtrahendI->second.getSectionID();
176 uint64_t SectionBOffset = SubtrahendI->second.getOffset();
177170 int64_t Addend =
178171 SignExtend64(readBytesUnaligned(LocalAddress, NumBytes), NumBytes * 8);
179172
173 unsigned SectionBID = ~0U;
174 uint64_t SectionBOffset = 0;
175
176 MachO::any_relocation_info RelInfo =
177 Obj.getRelocation(RelI->getRawDataRefImpl());
178
179 bool AIsExternal = BaseObj.getPlainRelocationExternal(RelInfo);
180
181 if (AIsExternal) {
182 Expected SubtrahendNameOrErr = RelI->getSymbol()->getName();
183 if (!SubtrahendNameOrErr)
184 return SubtrahendNameOrErr.takeError();
185 auto SubtrahendI = GlobalSymbolTable.find(*SubtrahendNameOrErr);
186 SectionBID = SubtrahendI->second.getSectionID();
187 SectionBOffset = SubtrahendI->second.getOffset();
188 } else {
189 SectionRef SecB = Obj.getAnyRelocationSection(RelInfo);
190 bool IsCode = SecB.isText();
191 Expected SectionBIDOrErr =
192 findOrEmitSection(Obj, SecB, IsCode, ObjSectionToID);
193 if (!SectionBIDOrErr)
194 return SectionBIDOrErr.takeError();
195 SectionBID = *SectionBIDOrErr;
196 Addend += SecB.getAddress();
197 }
198
180199 ++RelI;
181 Expected MinuendNameOrErr = RelI->getSymbol()->getName();
182 if (!MinuendNameOrErr)
183 return MinuendNameOrErr.takeError();
184 auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
185 unsigned SectionAID = MinuendI->second.getSectionID();
186 uint64_t SectionAOffset = MinuendI->second.getOffset();
200
201 unsigned SectionAID = ~0U;
202 uint64_t SectionAOffset = 0;
203
204 RelInfo = Obj.getRelocation(RelI->getRawDataRefImpl());
205
206 bool BIsExternal = BaseObj.getPlainRelocationExternal(RelInfo);
207 if (BIsExternal) {
208 Expected MinuendNameOrErr = RelI->getSymbol()->getName();
209 if (!MinuendNameOrErr)
210 return MinuendNameOrErr.takeError();
211 auto MinuendI = GlobalSymbolTable.find(*MinuendNameOrErr);
212 SectionAID = MinuendI->second.getSectionID();
213 SectionAOffset = MinuendI->second.getOffset();
214 } else {
215 SectionRef SecA = Obj.getAnyRelocationSection(RelInfo);
216 bool IsCode = SecA.isText();
217 Expected SectionAIDOrErr =
218 findOrEmitSection(Obj, SecA, IsCode, ObjSectionToID);
219 if (!SectionAIDOrErr)
220 return SectionAIDOrErr.takeError();
221 SectionAID = *SectionAIDOrErr;
222 Addend -= SecA.getAddress();
223 }
187224
188225 RelocationEntry R(SectionID, Offset, MachO::X86_64_RELOC_SUBTRACTOR, (uint64_t)Addend,
189226 SectionAID, SectionAOffset, SectionBID, SectionBOffset,
6161 .globl abssym
6262 abssym = 0xdeadbeef
6363
64 # Test subtractor relocations.
65 # rtdyld-check: *{8}z3 = z4 - z5 + 4
66 z3:
64 # Test subtractor relocations between named symbols.
65 # rtdyld-check: *{8}z3a = z4 - z5 + 4
66 z3a:
6767 .quad z4 - z5 + 4
68
69 # Test subtractor relocations between anonymous symbols.
70 # rtdyld-check: *{8}z3b = (section_addr(test_x86-64.o, _tmp3) + 4) - (section_addr(test_x86-64.o, _tmp4)) + 8
71 z3b:
72 .quad Lanondiff_1 - Lanondiff_2 + 8
73
74 # Test subtractor relocations between named and anonymous symbols.
75 # rtdyld-check: *{8}z3c = z4 - (section_addr(test_x86-64.o, _tmp4)) + 12
76 z3c:
77 .quad z4 - Lanondiff_2 + 12
78
79 # Test subtractor relocations between anonymous and named symbols.
80 # rtdyld-check: *{8}z3d = (section_addr(test_x86-64.o, _tmp3) + 4) - z4 + 16
81 z3d:
82 .quad Lanondiff_1 - z4 + 16
6883
6984 .section __DATA,_tmp1
7085 z4:
7489 z5:
7590 .byte 1
7691
92 .section __DATA,_tmp3
93 .long 1 # padding to make sure we handle non-zero offsets.
94 Lanondiff_1:
95 .byte 1
96
97 .section __DATA,_tmp4
98 Lanondiff_2:
99 .byte 1
100
77101 .subsections_via_symbols