LLVM 24.0.0git
MachO_arm64.cpp
Go to the documentation of this file.
1//===---- MachO_arm64.cpp - JIT linker implementation for MachO/arm64 -----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// MachO/arm64 jit-link implementation.
10//
11//===----------------------------------------------------------------------===//
12
17
21
22#define DEBUG_TYPE "jitlink"
23
24using namespace llvm;
25using namespace llvm::jitlink;
26
27namespace {
28
29class MachOLinkGraphBuilder_arm64 : public MachOLinkGraphBuilder {
30public:
31 MachOLinkGraphBuilder_arm64(const object::MachOObjectFile &Obj,
32 std::shared_ptr<orc::SymbolStringPool> SSP,
33 SubtargetFeatures Features)
34 : MachOLinkGraphBuilder(Obj, std::move(SSP), getObjectTriple(Obj),
35 std::move(Features), aarch64::getEdgeKindName) {}
36
37private:
38 enum MachOARM64RelocationKind : Edge::Kind {
39 MachOBranch26 = Edge::FirstRelocation,
40 MachOPointer32,
41 MachOPointer64,
42 MachOPointer64Anon,
43 MachOPointer64Authenticated,
44 MachOPage21,
45 MachOPageOffset12,
46 MachOGOTPage21,
47 MachOGOTPageOffset12,
48 MachOTLVPage21,
49 MachOTLVPageOffset12,
50 MachOPointerToGOT,
51 MachOPairedAddend,
52 MachOLDRLiteral19,
53 MachODelta32,
54 MachODelta64,
55 MachONegDelta32,
56 MachONegDelta64,
57 };
58
59 static Triple getObjectTriple(const object::MachOObjectFile &Obj) {
60 // Get the CPU sub-type from the header.
61 // jitLink_MachO should already have validated that the buffer is big enough
62 // to cover a mach_header64 so this is safe.
63 uint32_t CPUSubType =
64 *(const support::ulittle32_t *)(Obj.getData().data() + 8);
65 CPUSubType &= ~MachO::CPU_SUBTYPE_MASK;
66 if (CPUSubType == MachO::CPU_SUBTYPE_ARM64E)
67 return Triple("arm64e-apple-darwin");
68 return Triple("arm64-apple-darwin");
69 }
70
72 getRelocationKind(const MachO::relocation_info &RI) {
73 switch (RI.r_type) {
75 if (!RI.r_pcrel) {
76 if (RI.r_length == 3)
77 return RI.r_extern ? MachOPointer64 : MachOPointer64Anon;
78 else if (RI.r_length == 2)
79 return MachOPointer32;
80 }
81 break;
83 // SUBTRACTOR must be non-pc-rel, extern, with length 2 or 3.
84 // Initially represent SUBTRACTOR relocations with 'Delta<W>'.
85 // They may be turned into NegDelta<W> by parsePairRelocation.
86 if (!RI.r_pcrel && RI.r_extern) {
87 if (RI.r_length == 2)
88 return MachODelta32;
89 else if (RI.r_length == 3)
90 return MachODelta64;
91 }
92 break;
94 if (RI.r_pcrel && RI.r_extern && RI.r_length == 2)
95 return MachOBranch26;
96 break;
98 if (RI.r_pcrel && RI.r_extern && RI.r_length == 2)
99 return MachOPage21;
100 break;
102 if (!RI.r_pcrel && RI.r_extern && RI.r_length == 2)
103 return MachOPageOffset12;
104 break;
106 if (RI.r_pcrel && RI.r_extern && RI.r_length == 2)
107 return MachOGOTPage21;
108 break;
110 if (!RI.r_pcrel && RI.r_extern && RI.r_length == 2)
111 return MachOGOTPageOffset12;
112 break;
114 if (RI.r_pcrel && RI.r_extern && RI.r_length == 2)
115 return MachOPointerToGOT;
116 break;
118 if (!RI.r_pcrel && !RI.r_extern && RI.r_length == 2)
119 return MachOPairedAddend;
120 break;
122 if (!RI.r_pcrel && RI.r_extern && RI.r_length == 3)
123 return MachOPointer64Authenticated;
124 break;
126 if (RI.r_pcrel && RI.r_extern && RI.r_length == 2)
127 return MachOTLVPage21;
128 break;
130 if (!RI.r_pcrel && RI.r_extern && RI.r_length == 2)
131 return MachOTLVPageOffset12;
132 break;
133 }
134
136 "Unsupported arm64 relocation: address=" +
137 formatv("{0:x8}", RI.r_address) +
138 ", symbolnum=" + formatv("{0:x6}", RI.r_symbolnum) +
139 ", kind=" + formatv("{0:x1}", RI.r_type) +
140 ", pc_rel=" + (RI.r_pcrel ? "true" : "false") +
141 ", extern=" + (RI.r_extern ? "true" : "false") +
142 ", length=" + formatv("{0:d}", RI.r_length));
143 }
144
145 using PairRelocInfo = std::tuple<Edge::Kind, Symbol *, uint64_t>;
146
147 // Parses paired SUBTRACTOR/UNSIGNED relocations and, on success,
148 // returns the edge kind and addend to be used.
150 parsePairRelocation(Block &BlockToFix, Edge::Kind SubtractorKind,
151 const MachO::relocation_info &SubRI,
152 orc::ExecutorAddr FixupAddress, const char *FixupContent,
153 object::relocation_iterator &UnsignedRelItr,
155 using namespace support;
156
157 assert(((SubtractorKind == MachODelta32 && SubRI.r_length == 2) ||
158 (SubtractorKind == MachODelta64 && SubRI.r_length == 3)) &&
159 "Subtractor kind should match length");
160 assert(SubRI.r_extern && "SUBTRACTOR reloc symbol should be extern");
161 assert(!SubRI.r_pcrel && "SUBTRACTOR reloc should not be PCRel");
162
163 if (UnsignedRelItr == RelEnd)
164 return make_error<JITLinkError>("arm64 SUBTRACTOR without paired "
165 "UNSIGNED relocation");
166
167 auto UnsignedRI = getRelocationInfo(UnsignedRelItr);
168
169 if (SubRI.r_address != UnsignedRI.r_address)
170 return make_error<JITLinkError>("arm64 SUBTRACTOR and paired UNSIGNED "
171 "point to different addresses");
172
173 if (SubRI.r_length != UnsignedRI.r_length)
174 return make_error<JITLinkError>("length of arm64 SUBTRACTOR and paired "
175 "UNSIGNED reloc must match");
176
177 Symbol *FromSymbol;
178 if (auto FromSymbolOrErr = findSymbolByIndex(SubRI.r_symbolnum))
179 FromSymbol = FromSymbolOrErr->GraphSymbol;
180 else
181 return FromSymbolOrErr.takeError();
182
183 // Read the current fixup value.
184 uint64_t FixupValue = 0;
185 if (SubRI.r_length == 3)
186 FixupValue = *(const little64_t *)FixupContent;
187 else
188 FixupValue = *(const little32_t *)FixupContent;
189
190 // Find 'ToSymbol' using symbol number or address, depending on whether the
191 // paired UNSIGNED relocation is extern.
192 Symbol *ToSymbol = nullptr;
193 if (UnsignedRI.r_extern) {
194 // Find target symbol by symbol index.
195 if (auto ToSymbolOrErr = findSymbolByIndex(UnsignedRI.r_symbolnum))
196 ToSymbol = ToSymbolOrErr->GraphSymbol;
197 else
198 return ToSymbolOrErr.takeError();
199 } else {
200 auto ToSymbolSec = findSectionByIndex(UnsignedRI.r_symbolnum - 1);
201 if (!ToSymbolSec)
202 return ToSymbolSec.takeError();
203 ToSymbol = getSymbolByAddress(*ToSymbolSec, ToSymbolSec->Address);
204 assert(ToSymbol && "No symbol for section");
205 FixupValue -= ToSymbol->getAddress().getValue();
206 }
207
208 Edge::Kind DeltaKind;
209 Symbol *TargetSymbol;
210 uint64_t Addend;
211
212 bool FixingFromSymbol = true;
213 if (&BlockToFix == &FromSymbol->getAddressable()) {
214 if (LLVM_UNLIKELY(&BlockToFix == &ToSymbol->getAddressable())) {
215 // From and To are symbols in the same block. Decide direction by offset
216 // instead.
217 if (ToSymbol->getAddress() > FixupAddress)
218 FixingFromSymbol = true;
219 else if (FromSymbol->getAddress() > FixupAddress)
220 FixingFromSymbol = false;
221 else
222 FixingFromSymbol = FromSymbol->getAddress() >= ToSymbol->getAddress();
223 } else
224 FixingFromSymbol = true;
225 } else {
226 if (&BlockToFix == &ToSymbol->getAddressable())
227 FixingFromSymbol = false;
228 else {
229 // BlockToFix was neither FromSymbol nor ToSymbol.
230 return make_error<JITLinkError>("SUBTRACTOR relocation must fix up "
231 "either 'A' or 'B' (or a symbol in one "
232 "of their alt-entry groups)");
233 }
234 }
235
236 if (FixingFromSymbol) {
237 TargetSymbol = ToSymbol;
238 DeltaKind = (SubRI.r_length == 3) ? aarch64::Delta64 : aarch64::Delta32;
239 Addend = FixupValue + (FixupAddress - FromSymbol->getAddress());
240 // FIXME: handle extern 'from'.
241 } else {
242 TargetSymbol = &*FromSymbol;
243 DeltaKind =
245 Addend = FixupValue - (FixupAddress - ToSymbol->getAddress());
246 }
247
248 return PairRelocInfo(DeltaKind, TargetSymbol, Addend);
249 }
250
251 Error addRelocations() override {
252 using namespace support;
253 auto &Obj = getObject();
254
255 LLVM_DEBUG(dbgs() << "Processing relocations:\n");
256
257 for (auto &S : Obj.sections()) {
258
259 orc::ExecutorAddr SectionAddress(S.getAddress());
260
261 // Skip relocations virtual sections.
262 if (S.isVirtual()) {
263 if (!S.relocations().empty())
264 return make_error<JITLinkError>("Virtual section contains "
265 "relocations");
266 continue;
267 }
268
269 auto NSec =
270 findSectionByIndex(Obj.getSectionIndex(S.getRawDataRefImpl()));
271 if (!NSec)
272 return NSec.takeError();
273
274 // Skip relocations for MachO sections without corresponding graph
275 // sections.
276 {
277 if (!NSec->GraphSection) {
278 LLVM_DEBUG({
279 dbgs() << " Skipping relocations for MachO section "
280 << NSec->SegName << "/" << NSec->SectName
281 << " which has no associated graph section\n";
282 });
283 continue;
284 }
285 }
286
287 for (auto RelItr = S.relocation_begin(), RelEnd = S.relocation_end();
288 RelItr != RelEnd; ++RelItr) {
289
290 MachO::relocation_info RI = getRelocationInfo(RelItr);
291
292 // Validate the relocation kind.
293 auto MachORelocKind = getRelocationKind(RI);
294 if (!MachORelocKind)
295 return MachORelocKind.takeError();
296
297 // Find the address of the value to fix up.
298 orc::ExecutorAddr FixupAddress =
299 SectionAddress + (uint32_t)RI.r_address;
300 LLVM_DEBUG({
301 dbgs() << " " << NSec->SectName << " + "
302 << formatv("{0:x8}", RI.r_address) << ":\n";
303 });
304
305 // Find the block that the fixup points to.
306 Block *BlockToFix = nullptr;
307 {
308 auto SymbolToFixOrErr = findSymbolByAddress(*NSec, FixupAddress);
309 if (!SymbolToFixOrErr)
310 return SymbolToFixOrErr.takeError();
311 BlockToFix = &SymbolToFixOrErr->getBlock();
312 }
313
314 if (FixupAddress + orc::ExecutorAddrDiff(1ULL << RI.r_length) >
315 BlockToFix->getAddress() + BlockToFix->getContent().size())
317 "Relocation content extends past end of fixup block");
318
319 Edge::Kind Kind = Edge::Invalid;
320
321 // Get a pointer to the fixup content.
322 const char *FixupContent = BlockToFix->getContent().data() +
323 (FixupAddress - BlockToFix->getAddress());
324
325 // The target symbol and addend will be populated by the switch below.
326 Symbol *TargetSymbol = nullptr;
327 uint64_t Addend = 0;
328
329 if (*MachORelocKind == MachOPairedAddend) {
330 // If this is an Addend relocation then process it and move to the
331 // paired reloc.
332
333 Addend = SignExtend64(RI.r_symbolnum, 24);
334
335 ++RelItr;
336 if (RelItr == RelEnd)
337 return make_error<JITLinkError>("Unpaired Addend reloc at " +
338 formatv("{0:x16}", FixupAddress));
339 RI = getRelocationInfo(RelItr);
340
341 MachORelocKind = getRelocationKind(RI);
342 if (!MachORelocKind)
343 return MachORelocKind.takeError();
344
345 if (*MachORelocKind != MachOBranch26 &&
346 *MachORelocKind != MachOPage21 &&
347 *MachORelocKind != MachOPageOffset12)
349 "Invalid relocation pair: Addend + " +
350 StringRef(getMachOARM64RelocationKindName(*MachORelocKind)));
351
352 LLVM_DEBUG({
353 dbgs() << " Addend: value = " << formatv("{0:x6}", Addend)
354 << ", pair is "
355 << getMachOARM64RelocationKindName(*MachORelocKind) << "\n";
356 });
357
358 // Find the address of the value to fix up.
359 orc::ExecutorAddr PairedFixupAddress =
360 SectionAddress + (uint32_t)RI.r_address;
361 if (PairedFixupAddress != FixupAddress)
362 return make_error<JITLinkError>("Paired relocation points at "
363 "different target");
364 }
365
366 switch (*MachORelocKind) {
367 case MachOBranch26: {
368 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
369 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
370 else
371 return TargetSymbolOrErr.takeError();
372 uint32_t Instr = *(const ulittle32_t *)FixupContent;
373 if ((Instr & 0x7fffffff) != 0x14000000)
374 return make_error<JITLinkError>("BRANCH26 target is not a B or BL "
375 "instruction with a zero addend");
377 break;
378 }
379 case MachOPointer32:
380 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
381 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
382 else
383 return TargetSymbolOrErr.takeError();
384 Addend = *(const ulittle32_t *)FixupContent;
385 Kind = aarch64::Pointer32;
386 break;
387 case MachOPointer64:
388 case MachOPointer64Authenticated:
389 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
390 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
391 else
392 return TargetSymbolOrErr.takeError();
393 Addend = *(const ulittle64_t *)FixupContent;
394 Kind = *MachORelocKind == MachOPointer64
397 break;
398 case MachOPointer64Anon: {
399 orc::ExecutorAddr TargetAddress(*(const ulittle64_t *)FixupContent);
400 auto TargetNSec = findSectionByIndex(RI.r_symbolnum - 1);
401 if (!TargetNSec)
402 return TargetNSec.takeError();
403 if (auto TargetSymbolOrErr =
404 findSymbolByAddress(*TargetNSec, TargetAddress))
405 TargetSymbol = &*TargetSymbolOrErr;
406 else
407 return TargetSymbolOrErr.takeError();
408 Addend = TargetAddress - TargetSymbol->getAddress();
409 Kind = aarch64::Pointer64;
410 break;
411 }
412 case MachOPage21:
413 case MachOGOTPage21:
414 case MachOTLVPage21: {
415 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
416 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
417 else
418 return TargetSymbolOrErr.takeError();
419 uint32_t Instr = *(const ulittle32_t *)FixupContent;
420 if ((Instr & 0xffffffe0) != 0x90000000)
421 return make_error<JITLinkError>("PAGE21/GOTPAGE21 target is not an "
422 "ADRP instruction with a zero "
423 "addend");
424
425 if (*MachORelocKind == MachOPage21) {
426 Kind = aarch64::Page21;
427 } else if (*MachORelocKind == MachOGOTPage21) {
429 } else if (*MachORelocKind == MachOTLVPage21) {
431 }
432 break;
433 }
434 case MachOPageOffset12: {
435 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
436 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
437 else
438 return TargetSymbolOrErr.takeError();
439 uint32_t Instr = *(const ulittle32_t *)FixupContent;
440 uint32_t EncodedAddend = (Instr & 0x003FFC00) >> 10;
441 if (EncodedAddend != 0)
442 return make_error<JITLinkError>("GOTPAGEOFF12 target has non-zero "
443 "encoded addend");
445 break;
446 }
447 case MachOGOTPageOffset12:
448 case MachOTLVPageOffset12: {
449 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
450 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
451 else
452 return TargetSymbolOrErr.takeError();
453 uint32_t Instr = *(const ulittle32_t *)FixupContent;
454 if ((Instr & 0xfffffc00) != 0xf9400000)
455 return make_error<JITLinkError>("GOTPAGEOFF12 target is not an LDR "
456 "immediate instruction with a zero "
457 "addend");
458
459 if (*MachORelocKind == MachOGOTPageOffset12) {
461 } else if (*MachORelocKind == MachOTLVPageOffset12) {
463 }
464 break;
465 }
466 case MachOPointerToGOT:
467 if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
468 TargetSymbol = TargetSymbolOrErr->GraphSymbol;
469 else
470 return TargetSymbolOrErr.takeError();
471
473 break;
474 case MachODelta32:
475 case MachODelta64: {
476 // We use Delta32/Delta64 to represent SUBTRACTOR relocations.
477 // parsePairRelocation handles the paired reloc, and returns the
478 // edge kind to be used (either Delta32/Delta64, or
479 // NegDelta32/NegDelta64, depending on the direction of the
480 // subtraction) along with the addend.
481 auto PairInfo =
482 parsePairRelocation(*BlockToFix, *MachORelocKind, RI,
483 FixupAddress, FixupContent, ++RelItr, RelEnd);
484 if (!PairInfo)
485 return PairInfo.takeError();
486 std::tie(Kind, TargetSymbol, Addend) = *PairInfo;
487 assert(TargetSymbol && "No target symbol from parsePairRelocation?");
488 break;
489 }
490 default:
491 llvm_unreachable("Special relocation kind should not appear in "
492 "mach-o file");
493 }
494
495 LLVM_DEBUG({
496 dbgs() << " ";
497 Edge GE(Kind, FixupAddress - BlockToFix->getAddress(), *TargetSymbol,
498 Addend);
499 printEdge(dbgs(), *BlockToFix, GE, aarch64::getEdgeKindName(Kind));
500 dbgs() << "\n";
501 });
502 BlockToFix->addEdge(Kind, FixupAddress - BlockToFix->getAddress(),
503 *TargetSymbol, Addend);
504 }
505 }
506 return Error::success();
507 }
508
509 /// Return the string name of the given MachO arm64 edge kind.
510 const char *getMachOARM64RelocationKindName(Edge::Kind R) {
511 switch (R) {
512 case MachOBranch26:
513 return "MachOBranch26";
514 case MachOPointer64:
515 return "MachOPointer64";
516 case MachOPointer64Anon:
517 return "MachOPointer64Anon";
518 case MachOPointer64Authenticated:
519 return "MachOPointer64Authenticated";
520 case MachOPage21:
521 return "MachOPage21";
522 case MachOPageOffset12:
523 return "MachOPageOffset12";
524 case MachOGOTPage21:
525 return "MachOGOTPage21";
526 case MachOGOTPageOffset12:
527 return "MachOGOTPageOffset12";
528 case MachOTLVPage21:
529 return "MachOTLVPage21";
530 case MachOTLVPageOffset12:
531 return "MachOTLVPageOffset12";
532 case MachOPointerToGOT:
533 return "MachOPointerToGOT";
534 case MachOPairedAddend:
535 return "MachOPairedAddend";
536 case MachOLDRLiteral19:
537 return "MachOLDRLiteral19";
538 case MachODelta32:
539 return "MachODelta32";
540 case MachODelta64:
541 return "MachODelta64";
542 case MachONegDelta32:
543 return "MachONegDelta32";
544 case MachONegDelta64:
545 return "MachONegDelta64";
546 default:
547 return getGenericEdgeKindName(R);
548 }
549 }
550};
551
552} // namespace
553
554namespace llvm {
555namespace jitlink {
556
558 LLVM_DEBUG(dbgs() << "Visiting edges in graph:\n");
559
561 aarch64::PLTTableManager PLT(G, GOT);
562 visitExistingEdges(G, GOT, PLT);
563 return Error::success();
564}
565
566class MachOJITLinker_arm64 : public JITLinker<MachOJITLinker_arm64> {
567 friend class JITLinker<MachOJITLinker_arm64>;
568
569public:
570 MachOJITLinker_arm64(std::unique_ptr<JITLinkContext> Ctx,
571 std::unique_ptr<LinkGraph> G,
572 PassConfiguration PassConfig)
573 : JITLinker(std::move(Ctx), std::move(G), std::move(PassConfig)) {}
574
575private:
576 Error applyFixup(LinkGraph &G, Block &B, const Edge &E) const {
578 }
579};
580
582 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
583 auto MachOObj = object::ObjectFile::createMachOObjectFile(ObjectBuffer);
584 if (!MachOObj)
585 return MachOObj.takeError();
586
587 auto Features = (*MachOObj)->getFeatures();
588 if (!Features)
589 return Features.takeError();
590
591 return MachOLinkGraphBuilder_arm64(**MachOObj, std::move(SSP),
592 std::move(*Features))
593 .buildGraph();
594}
595
597 assert(G.getTargetTriple().isArm64e() && "PAC signing only valid for arm64e");
598
599 if (auto *ModInitSec = G.findSectionByName("__DATA,__mod_init_func")) {
600 for (auto *B : ModInitSec->blocks()) {
601 for (auto &E : B->edges()) {
602 if (E.getKind() == aarch64::Pointer64) {
603
604 // Check that we have room to encode pointer signing bits.
605 if (E.getAddend() >> 32)
607 "In " + G.getName() + ", __mod_init_func pointer at " +
608 formatv("{0:x}", B->getFixupAddress(E).getValue()) +
609 " has data in high bits of addend (addend >= 2^32)");
610
611 // Change edge to Pointer64Authenticated, encode signing:
612 // key = asia, discriminator = 0, diversity = 0.
613 Edge::AddendT SigningBits = 0x1ULL << 63;
615 E.setAddend(E.getAddend() | SigningBits);
616 }
617 }
618 }
619 }
620
621 return Error::success();
622}
623
625 : public CompactUnwindTraits<CompactUnwindTraits_MachO_arm64,
626 /* PointerSize = */ 8> {
627 // FIXME: Reinstate once we no longer need the MSVC workaround. See
628 // FIXME for CompactUnwindTraits in CompactUnwindSupport.h.
629 // constexpr static size_t PointerSize = 8;
630
632
633 constexpr static uint32_t EncodingModeMask = 0x0f000000;
634 constexpr static uint32_t DWARFSectionOffsetMask = 0x00ffffff;
635
636 constexpr static uint32_t FramelessMode = 0x02000000;
637 constexpr static uint32_t DWARFMode = 0x03000000;
638 constexpr static uint32_t FrameMode = 0x04000000;
639
641
642 static bool encodingSpecifiesDWARF(uint32_t Encoding) {
643 return (Encoding & EncodingModeMask) == DWARFMode;
644 }
645
646 static bool encodingCanBeMerged(uint32_t Encoding) {
647 switch (Encoding & EncodingModeMask) {
648 case FramelessMode:
649 case FrameMode:
650 return true;
651 case DWARFMode:
652 default:
653 return false;
654 }
655 }
656};
657
658void link_MachO_arm64(std::unique_ptr<LinkGraph> G,
659 std::unique_ptr<JITLinkContext> Ctx) {
660
661 PassConfiguration Config;
662
663 if (Ctx->shouldAddDefaultTargetPasses(G->getTargetTriple())) {
664 // Add a mark-live pass.
665 if (auto MarkLive = Ctx->getMarkLivePass(G->getTargetTriple()))
666 Config.PrePrunePasses.push_back(std::move(MarkLive));
667 else
668 Config.PrePrunePasses.push_back(markAllSymbolsLive);
669
670 // Add eh-frame passes.
673
674 // Create a compact-unwind manager for use in passes below.
675 auto CompactUnwindMgr =
676 std::make_shared<CompactUnwindManager<CompactUnwindTraits_MachO_arm64>>(
679
680 // Add compact unwind prepare pass.
681 Config.PrePrunePasses.push_back([CompactUnwindMgr](LinkGraph &G) {
682 return CompactUnwindMgr->prepareForPrune(G);
683 });
684
685 // Resolve any external section start / end symbols.
686 Config.PostAllocationPasses.push_back(
689
690 // Add an in-place GOT/Stubs pass.
692
693 // If this is an arm64e graph then add pointer signing passes.
694 if (G->getTargetTriple().isArm64e()) {
696 Config.PostPrunePasses.push_back(
698 Config.PreFixupPasses.push_back(
700 }
701
702 // Reserve unwind-info space.
703 Config.PostPrunePasses.push_back([CompactUnwindMgr](LinkGraph &G) {
704 return CompactUnwindMgr->processAndReserveUnwindInfo(G);
705 });
706
707 // Translate compact-unwind to unwind-info.
708 Config.PreFixupPasses.push_back([CompactUnwindMgr](LinkGraph &G) {
709 return CompactUnwindMgr->writeUnwindInfo(G);
710 });
711 }
712
713 if (auto Err = Ctx->modifyPassConfig(*G, Config))
714 return Ctx->notifyFailed(std::move(Err));
715
716 // Construct a JITLinker and run the link function.
717 MachOJITLinker_arm64::link(std::move(Ctx), std::move(G), std::move(Config));
718}
719
723
729}
730
731} // end namespace jitlink
732} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:348
#define G(x, y, z)
Definition MD5.cpp:55
#define LLVM_DEBUG(...)
Definition Debug.h:119
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)
Create a MachOObjectFile instance from a given buffer.
Represents an address in the executor process.
uint64_t getValue() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CPU_SUBTYPE_ARM64E
Definition MachO.h:1781
@ ARM64_RELOC_PAGEOFF12
Definition MachO.h:460
@ ARM64_RELOC_POINTER_TO_GOT
Definition MachO.h:466
@ ARM64_RELOC_AUTHENTICATED_POINTER
Definition MachO.h:474
@ ARM64_RELOC_SUBTRACTOR
Definition MachO.h:454
@ ARM64_RELOC_ADDEND
Definition MachO.h:472
@ ARM64_RELOC_UNSIGNED
Definition MachO.h:452
@ ARM64_RELOC_GOT_LOAD_PAGE21
Definition MachO.h:462
@ ARM64_RELOC_TLVP_LOAD_PAGEOFF12
Definition MachO.h:470
@ ARM64_RELOC_PAGE21
Definition MachO.h:458
@ ARM64_RELOC_GOT_LOAD_PAGEOFF12
Definition MachO.h:464
@ ARM64_RELOC_TLVP_LOAD_PAGE21
Definition MachO.h:468
@ ARM64_RELOC_BRANCH26
Definition MachO.h:456
content_iterator< RelocationRef > relocation_iterator
Definition ObjectFile.h:79
LLVM_ABI StringRef MachOEHFrameSectionName
uint64_t ExecutorAddrDiff
LLVM_ABI StringRef MachOCompactUnwindSectionName
LLVM_ABI StringRef MachOUnwindInfoSectionName
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
Definition Endian.h:270
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
endianness
Definition bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879