llvm.org GIT mirror llvm / 60b28ca
[RuntimeDyld][MachO] Add support for MachO::ARM64_RELOC_POINTER_TO_GOT reloc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333130 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 2 years ago
2 changed file(s) with 60 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
4848 return make_error(std::move(ErrMsg),
4949 inconvertibleErrorCode());
5050 }
51 case MachO::ARM64_RELOC_UNSIGNED:
52 if (NumBytes != 4 && NumBytes != 8)
53 return make_error("Invalid relocation size for "
54 "ARM64_RELOC_UNSIGNED",
51 case MachO::ARM64_RELOC_POINTER_TO_GOT:
52 case MachO::ARM64_RELOC_UNSIGNED: {
53 if (NumBytes != 4 && NumBytes != 8) {
54 std::string ErrMsg;
55 {
56 raw_string_ostream ErrStream(ErrMsg);
57 ErrStream << "Invalid relocation size for relocation "
58 << getRelocName(RE.RelType);
59 }
60 return make_error(std::move(ErrMsg),
5561 inconvertibleErrorCode());
56 break;
62 }
63 break;
64 }
5765 case MachO::ARM64_RELOC_BRANCH26:
5866 case MachO::ARM64_RELOC_PAGE21:
5967 case MachO::ARM64_RELOC_PAGEOFF12:
6876 switch (RE.RelType) {
6977 default:
7078 llvm_unreachable("Unsupported relocation type!");
79 case MachO::ARM64_RELOC_POINTER_TO_GOT:
7180 case MachO::ARM64_RELOC_UNSIGNED:
7281 // This could be an unaligned memory location.
7382 if (NumBytes == 4)
149158 switch (RelType) {
150159 default:
151160 llvm_unreachable("Unsupported relocation type!");
161 case MachO::ARM64_RELOC_POINTER_TO_GOT:
152162 case MachO::ARM64_RELOC_UNSIGNED:
153163 assert((NumBytes == 4 || NumBytes == 8) && "Invalid relocation size.");
154164 break;
166176 switch (RelType) {
167177 default:
168178 llvm_unreachable("Unsupported relocation type!");
179 case MachO::ARM64_RELOC_POINTER_TO_GOT:
169180 case MachO::ARM64_RELOC_UNSIGNED:
170181 // This could be an unaligned memory location.
171182 if (NumBytes == 4)
292303 return processSubtractRelocation(SectionID, RelI, Obj, ObjSectionToID);
293304
294305 RelocationEntry RE(getRelocationEntry(SectionID, Obj, RelI));
306
307 if (RE.RelType == MachO::ARM64_RELOC_POINTER_TO_GOT) {
308 bool Valid =
309 (RE.Size == 2 && RE.IsPCRel) || (RE.Size == 3 && !RE.IsPCRel);
310 if (!Valid)
311 return make_error("ARM64_RELOC_POINTER_TO_GOT supports "
312 "32-bit pc-rel or 64-bit absolute only",
313 inconvertibleErrorCode());
314 }
315
295316 if (auto Addend = decodeAddend(RE))
296317 RE.Addend = *Addend;
297318 else
309330 return ValueOrErr.takeError();
310331
311332 bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
312 if (!IsExtern && RE.IsPCRel)
333 if (RE.RelType == MachO::ARM64_RELOC_POINTER_TO_GOT) {
334 // We'll take care of the offset in processGOTRelocation.
335 Value.Offset = 0;
336 } else if (!IsExtern && RE.IsPCRel)
313337 makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
314338
315339 RE.Addend = Value.Offset;
316340
317341 if (RE.RelType == MachO::ARM64_RELOC_GOT_LOAD_PAGE21 ||
318 RE.RelType == MachO::ARM64_RELOC_GOT_LOAD_PAGEOFF12)
342 RE.RelType == MachO::ARM64_RELOC_GOT_LOAD_PAGEOFF12 ||
343 RE.RelType == MachO::ARM64_RELOC_POINTER_TO_GOT)
319344 processGOTRelocation(RE, Value, Stubs);
320345 else {
321346 if (Value.SymbolName)
348373 encodeAddend(LocalAddress, 1 << RE.Size, RelType, Value + RE.Addend);
349374 break;
350375 }
376
377 case MachO::ARM64_RELOC_POINTER_TO_GOT: {
378 assert(((RE.Size == 2 && RE.IsPCRel) || (RE.Size == 3 && !RE.IsPCRel)) &&
379 "ARM64_RELOC_POINTER_TO_GOT only supports 32-bit pc-rel or 64-bit "
380 "absolute");
381 // Addend is the GOT entry address and RE.Offset the target of the
382 // relocation.
383 uint64_t Result =
384 RE.IsPCRel ? (RE.Addend - RE.Offset) : (Value + RE.Addend);
385 encodeAddend(LocalAddress, 1 << RE.Size, RelType, Result);
386 break;
387 }
388
351389 case MachO::ARM64_RELOC_BRANCH26: {
352390 assert(RE.IsPCRel && "not PCRel and ARM64_RELOC_BRANCH26 not supported");
353391 // Check if branch is in range.
385423 writeBytesUnaligned(Value, LocalAddress, 1 << RE.Size);
386424 break;
387425 }
388 case MachO::ARM64_RELOC_POINTER_TO_GOT:
426
389427 case MachO::ARM64_RELOC_TLVP_LOAD_PAGE21:
390428 case MachO::ARM64_RELOC_TLVP_LOAD_PAGEOFF12:
391429 llvm_unreachable("Relocation type not yet implemented!");
403441 private:
404442 void processGOTRelocation(const RelocationEntry &RE,
405443 RelocationValueRef &Value, StubMap &Stubs) {
406 assert(RE.Size == 2);
444 assert((RE.RelType == MachO::ARM64_RELOC_POINTER_TO_GOT &&
445 (RE.Size == 2 || RE.Size == 3)) ||
446 RE.Size == 2);
407447 SectionEntry &Section = Sections[RE.SectionID];
408448 StubMap::const_iterator i = Stubs.find(Value);
409449 int64_t Offset;
0 # RUN: rm -rf %t && mkdir -p %t
11 # RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o %t/foo.o %s
2 # RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -map-section foo.o,__text=0x10bc0 -verify -check=%s %t/foo.o
2 # RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -map-section foo.o,__text=0x10bc0 -dummy-extern _dummy1=0x100000 -verify -check=%s %t/foo.o
33
44 .section __TEXT,__text,regular,pure_instructions
55 .ios_version_min 7, 0
9090 _subtractor_result:
9191 .quad _test_branch_reloc - _foo
9292
93 # Test 32-bit relative ARM64_RELOC_POINTER_TO_GOT
94 # rtdyld-check: *{4}_pointer_to_got_32_rel = (stub_addr(foo.o, __data, _dummy1) - _pointer_to_got_32_rel)
95 _pointer_to_got_32_rel:
96 .long _dummy1@got - .
97
98 # Test 64-bit absolute ARM64_RELOC_POINTER_TO_GOT
99 # rtdyld-check: *{8}_pointer_to_got_64_abs = stub_addr(foo.o, __data, _dummy1)
100 _pointer_to_got_64_abs:
101 .quad _dummy1@got
102
93103 .subsections_via_symbols