LLVM: include/llvm/ExecutionEngine/JITLink/JITLink.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
15
38#include
39
40#include
41#include
42#include <system_error>
43
44namespace llvm {
46
50
51
52
54public:
56
58
61 std::error_code convertToErrorCode() const override;
62
63private:
64 std::string ErrMsg;
65};
66
67
69public:
71
78
81
83 : Target(&Target), Offset(Offset), Addend(Addend), K(K) {}
84
99
100private:
103 AddendT Addend = 0;
104 Kind K = 0;
105};
106
107
108
110
111
114
115protected:
117 : Address(Address), IsDefined(IsDefined), IsAbsolute(false) {}
118
120 : Address(Address), IsDefined(false), IsAbsolute(true) {
121 assert(!(IsDefined && IsAbsolute) &&
122 "Block cannot be both defined and absolute");
123 }
124
125public:
130
133
134
135
136 bool isDefined() const { return static_cast<bool>(IsDefined); }
137 bool isAbsolute() const { return static_cast<bool>(IsAbsolute); }
138
139private:
140 void setAbsolute(bool IsAbsolute) {
141 assert(!IsDefined && "Cannot change the Absolute flag on a defined block");
142 this->IsAbsolute = IsAbsolute;
143 }
144
148
149protected:
150
154};
155
157
158
161
162private:
163
166 : Addressable(Address, true), Parent(&Parent), Size(Size) {
169 "Alignment offset cannot exceed alignment");
171 "Alignment offset exceeds maximum");
175 }
176
177
178
179
186 "Alignment offset cannot exceed alignment");
188 "Alignment offset exceeds maximum");
192 }
193
194
195
196
197
198
205 "Alignment offset cannot exceed alignment");
207 "Alignment offset exceeds maximum");
211 }
212
213public:
217
218 Block(const Block &) = delete;
222
223
225
226
227
228
229
231
232
233 size_t getSize() const { return Size; }
234
235
237 Data = nullptr;
238 this->Size = Size;
239 }
240
241
245
246
248 assert(Data && "Block does not contain content");
250 }
251
252
253
254
256 assert(Content.data() && "Setting null content");
257 Data = Content.data();
258 Size = Content.size();
260 }
261
262
263
264
265
266
268
269
270
271
272
273
275 assert(Data && "Block does not contain content");
278 }
279
280
281
282
283
285 assert(MutableContent.data() && "Setting null content");
286 Data = MutableContent.data();
287 Size = MutableContent.size();
289 }
290
291
292
293
294
295
296
298
299
301
302
307
308
310
311
314 "Alignment offset can't exceed alignment");
316 }
317
318
320 Edge::AddendT Addend) {
322 "Adding edge to zero-fill block?");
324 }
325
326
327
329
330
332 return make_range(Edges.begin(), Edges.end());
333 }
334
335
337 return make_range(Edges.begin(), Edges.end());
338 }
339
340
343 [O](const Edge &E) { return E.getOffset() == O; });
344 }
345
346
349 [O](const Edge &E) { return E.getOffset() == O; });
350 }
351
352
353 size_t edges_size() const { return Edges.size(); }
354
355
357
358
359
361
362
363
367
368private:
369 static constexpr uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
370
371 void setSection(Section &Parent) { this->Parent = &Parent; }
372
373 Section *Parent;
374 const char *Data = nullptr;
375 size_t Size = 0;
376 std::vector Edges;
377};
378
379
381 uint64_t Delta = (B.getAlignmentOffset() - Addr) % B.getAlignment();
382 return Addr + Delta;
383}
384
385
389
390
391
392
394
395
400
401
403
404
406
407
408
409
410
411
412
414
415
417
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433class Symbol {
435
436private:
439 Scope S, bool IsLive, bool IsCallable)
440 : Name(std::move(Name)), Base(&Base), Offset(Offset), WeakRef(0),
441 Size(Size) {
442 assert(Offset <= MaxOffset && "Offset out of range");
448 }
449
451 Addressable &Base,
454 bool WeaklyReferenced) {
456 "Cannot create external symbol from defined block");
457 assert(Name && "External symbol name cannot be empty");
458 auto *Sym = Allocator.Allocate();
459 new (Sym)
461 Sym->setWeaklyReferenced(WeaklyReferenced);
462 return *Sym;
463 }
464
466 Addressable &Base,
467 orc::SymbolStringPtr &&Name,
469 Scope S, bool IsLive) {
471 "Cannot create absolute symbol from a defined block");
472 auto *Sym = Allocator.Allocate();
473 new (Sym) Symbol(Base, 0, std::move(Name), Size, L, S, IsLive, false);
474 return *Sym;
475 }
476
480 bool IsLive) {
481 assert((Offset + Size) <= Base.getSize() &&
482 "Symbol extends past end of block");
483 auto *Sym = Allocator.Allocate();
485 IsLive, IsCallable);
486 return *Sym;
487 }
488
491 orc::SymbolStringPtr Name,
493 Scope S, bool IsLive, bool IsCallable) {
494 assert((Offset + Size) <= Base.getSize() &&
495 "Symbol extends past end of block");
496 assert(Name && "Name cannot be empty");
497 auto *Sym = Allocator.Allocate();
498 new (Sym)
499 Symbol(Base, Offset, std::move(Name), Size, L, S, IsLive, IsCallable);
500 return *Sym;
501 }
502
503public:
504
505
506
508
509
514
515
516 bool hasName() const { return Name != nullptr; }
517
518
521 "Anonymous symbol has non-local scope");
522
523 return Name;
524 }
525
526
527
529
530
531
533 assert(Base && "Attempt to access null symbol");
534 return Base->isDefined();
535 }
536
537
538
540 assert(Base && "Attempting to access null symbol");
541 return IsLive;
542 }
543
544
545 void setLive(bool IsLive) { this->IsLive = IsLive; }
546
547
549
550
551 void setCallable(bool IsCallable) { this->IsCallable = IsCallable; }
552
553
555 assert(Base && "Attempt to access null symbol");
556 return !Base->isDefined() && !Base->isAbsolute();
557 }
558
559
561 assert(Base && "Attempt to access null symbol");
562 return Base->isAbsolute();
563 }
564
565
567 assert(Base && "Cannot get underlying addressable for null symbol");
568 return *Base;
569 }
570
571
573 assert(Base && "Cannot get underlying addressable for null symbol");
574 return *Base;
575 }
576
577
579 assert(Base && "Cannot get block for null symbol");
580 assert(Base->isDefined() && "Not a defined symbol");
581 return static_cast<Block &>(*Base);
582 }
583
584
586 assert(Base && "Cannot get block for null symbol");
587 assert(Base->isDefined() && "Not a defined symbol");
588 return static_cast<const Block &>(*Base);
589 }
590
591
593
594
596
599 Offset = NewOffset;
600 }
601
602
604
605
607
608
610 assert(Base && "Cannot set size for null Symbol");
611 assert((Size == 0 || Base->isDefined()) &&
612 "Non-zero size can only be set for defined symbols");
613 assert((Offset + Size <= static_cast<const Block &>(*Base).getSize()) &&
614 "Symbol size cannot extend past the end of its containing block");
615 this->Size = Size;
616 }
617
618
622
623
624
626
627
628
632
633
635
636
639 "Linkage can only be applied to defined named symbols");
640 this->L = static_cast<uint8_t>(L);
641 }
642
643
645
646
649 "Can not set anonymous symbol to non-local scope");
650 assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) &&
651 "Invalid visibility for symbol type");
652 this->S = static_cast<uint8_t>(S);
653 }
654
655
657
658
660 assert(Flags <= 1 && "Add more bits to store more than single flag");
661 TargetFlags = Flags;
662 }
663
664
665
667 assert(isExternal() && "isWeaklyReferenced called on non-external");
668 return WeakRef;
669 }
670
671
672
674 assert(isExternal() && "setWeaklyReferenced called on non-external");
675 this->WeakRef = WeakRef;
676 }
677
678private:
680 assert(.isDefined() &&
.isAbsolute() &&
681 "Attempting to make external with defined or absolute block");
685 IsLive = 0;
686
687 }
688
690 assert(.isDefined() && A.isAbsolute() &&
691 "Attempting to make absolute with defined or external block");
694 }
695
697
698 static constexpr uint64_t MaxOffset = (1ULL << 59) - 1;
699
700 orc::SymbolStringPtr Name = nullptr;
701 Addressable *Base = nullptr;
702 uint64_t Offset : 57;
703 uint64_t L : 1;
704 uint64_t S : 2;
705 uint64_t IsLive : 1;
706 uint64_t IsCallable : 1;
707 uint64_t WeakRef : 1;
708 uint64_t TargetFlags : 1;
709 size_t Size = 0;
710};
711
713
715 StringRef EdgeKindName);
716
717
718class Section {
720
721private:
723 : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
724
727
728public:
731
734
736
737
739 Section &operator=(const Section &) = delete;
742
743
745
746
748
749
751
752
754
755
757
758
760
761
762
764
765
766 bool empty() const { return Blocks.empty(); }
767
768
770 return make_range(Blocks.begin(), Blocks.end());
771 }
772
773
775 return make_range(Blocks.begin(), Blocks.end());
776 }
777
778
780
781
783 return make_range(Symbols.begin(), Symbols.end());
784 }
785
786
788 return make_range(Symbols.begin(), Symbols.end());
789 }
790
791
793
794private:
796 assert(!Symbols.count(&Sym) && "Symbol is already in this section");
797 Symbols.insert(&Sym);
798 }
799
800 void removeSymbol(Symbol &Sym) {
801 assert(Symbols.count(&Sym) && "symbol is not in this section");
802 Symbols.erase(&Sym);
803 }
804
806 assert(!Blocks.count(&B) && "Block is already in this section");
808 }
809
810 void removeBlock(Block &B) {
811 assert(Blocks.count(&B) && "Block is not in this section");
812 Blocks.erase(&B);
813 }
814
815 void transferContentTo(Section &DstSection) {
816 if (&DstSection == this)
817 return;
818 for (auto *S : Symbols)
819 DstSection.addSymbol(*S);
820 for (auto *B : Blocks)
821 DstSection.addBlock(*B);
822 Symbols.clear();
823 Blocks.clear();
824 }
825
826 StringRef Name;
830 BlockSet Blocks;
831 SymbolSet Symbols;
832};
833
834
835
837public:
841 return;
843 for (auto *B : Sec.blocks()) {
844 if (B->getAddress() < First->getAddress())
845 First = B;
846 if (B->getAddress() > Last->getAddress())
847 Last = B;
848 }
849 }
851 assert((!Last || First) && "First can not be null if end is non-null");
852 return First;
853 }
855 assert((First || !Last) && "Last can not be null if start is non-null");
856 return Last;
857 }
859 assert((First || !Last) && "Last can not be null if start is non-null");
860 return !First;
861 }
869
873
874private:
877};
878
880private:
885
886 template <typename... ArgTs>
887 Addressable &createAddressable(ArgTs &&... Args) {
890 new (A) Addressable(std::forward(Args)...);
891 return *A;
892 }
893
895 A.~Addressable();
896 Allocator.Deallocate(&A);
897 }
898
899 template <typename... ArgTs> Block &createBlock(ArgTs &&... Args) {
900 Block *B = reinterpret_cast<Block *>(Allocator.Allocate<Block>());
901 new (B) Block(std::forward(Args)...);
902 B->getSection().addBlock(*B);
903 return *B;
904 }
905
906 void destroyBlock(Block &B) {
907 B.~Block();
908 Allocator.Deallocate(&B);
909 }
910
911 void destroySymbol(Symbol &S) {
912 S.~Symbol();
913 Allocator.Deallocate(&S);
914 }
915
918 }
919
921 getSectionConstBlocks(const Section &S) {
923 }
924
926 getSectionSymbols(Section &S) {
928 }
929
931 getSectionConstSymbols(const Section &S) {
933 }
934
935 struct GetExternalSymbolMapEntryValue {
938 }
939 };
940
941 struct GetSectionMapEntryValue {
942 Section &operator()(SectionMap::value_type &KV) const { return *KV.second; }
943 };
944
945 struct GetSectionMapEntryConstValue {
946 const Section &operator()(const SectionMap::value_type &KV) const {
947 return *KV.second;
948 }
949 };
950
951public:
954 GetExternalSymbolMapEntryValue>;
956
961
962 template <typename OuterItrT, typename InnerItrT, typename T,
964 typename OuterItrT::reference)>
967 nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
968 std::forward_iterator_tag, T> {
969 public:
971
973 : OuterI(OuterI), OuterE(OuterE),
974 InnerI(getInnerBegin(OuterI, OuterE)) {
975 moveToNonEmptyInnerOrEnd();
976 }
977
979 return (OuterI == RHS.OuterI) && (InnerI == RHS.InnerI);
980 }
981
983 assert(InnerI != getInnerRange(*OuterI).end() && "Dereferencing end?");
984 return *InnerI;
985 }
986
988 ++InnerI;
989 moveToNonEmptyInnerOrEnd();
990 return *this;
991 }
992
993 private:
994 static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
995 return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
996 }
997
998 void moveToNonEmptyInnerOrEnd() {
999 while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
1000 ++OuterI;
1001 InnerI = getInnerBegin(OuterI, OuterE);
1002 }
1003 }
1004
1005 OuterItrT OuterI, OuterE;
1006 InnerItrT InnerI;
1007 };
1008
1011 Symbol *, getSectionSymbols>;
1012
1016 getSectionConstSymbols>;
1017
1020 Block *, getSectionBlocks>;
1021
1025 getSectionConstBlocks>;
1026
1028
1029 LinkGraph(std::string Name, std::shared_ptrorc::SymbolStringPool SSP,
1033 Features(std::move(Features)),
1034 GetEdgeKindName(std::move(GetEdgeKindName)) {
1036 "Arch bitwidth is not a multiple of 8");
1037 }
1038
1044
1045
1046
1047 const std::string &getName() const { return Name; }
1048
1049
1051
1052
1054
1055
1056 unsigned getPointerSize() const { return TT.getArchPointerBitWidth() / 8; }
1057
1058
1062
1063 const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }
1064
1066
1067
1068
1070 return {Allocator.Allocate<char>(Size), Size};
1071 }
1072
1073
1074
1075
1077 auto *AllocatedBuffer = Allocator.Allocate<char>(Source.size());
1078 llvm::copy(Source, AllocatedBuffer);
1080 }
1081
1082
1083
1084
1085
1086
1087
1088
1091 auto SourceStr = Source.toStringRef(TmpBuffer);
1092 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size());
1093 llvm::copy(SourceStr, AllocatedBuffer);
1095 }
1096
1097
1098
1099
1100
1101
1104 return {Buf.data(), Buf.size()};
1105 }
1106
1107
1108
1109
1110
1111
1113 char *AllocatedBuffer = Allocator.Allocate<char>(Source.size() + 1);
1114 llvm::copy(Source, AllocatedBuffer);
1115 AllocatedBuffer[Source.size()] = '\0';
1117 }
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1130 auto SourceStr = Source.toStringRef(TmpBuffer);
1131 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size() + 1);
1132 llvm::copy(SourceStr, AllocatedBuffer);
1133 AllocatedBuffer[SourceStr.size()] = '\0';
1135 }
1136
1137
1139 assert(!Sections.count(Name) && "Duplicate section name");
1140 std::unique_ptr
1141 return *Sections.insert(std::make_pair(Name, std::move(Sec))).first->second;
1142 }
1143
1144
1148 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1149 }
1150
1151
1157 return createBlock(Parent, MutableContent, Address, Alignment,
1158 AlignmentOffset);
1159 }
1160
1161
1162
1163
1164
1168 bool ZeroInitialize = true) {
1170 if (ZeroInitialize)
1171 memset(Content.data(), 0, Content.size());
1172 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1173 }
1174
1175
1179 return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
1180 }
1181
1182
1185 reinterpret_cast<const uint8_t *>(B.getContent().data()), B.getSize());
1187 }
1188
1189
1190
1193 reinterpret_cast<uint8_t *>(B.getMutableContent(*this).data()),
1194 B.getSize());
1196 }
1197
1198
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 template
1241 std::vector<Block *> Blocks;
1242 Blocks.push_back(&B);
1243
1244 if (std::empty(SplitOffsets))
1245 return Blocks;
1246
1247
1248 if (B.isZeroFill()) {
1249 size_t OrigSize = B.getSize();
1250 for (Edge::OffsetT Offset : SplitOffsets) {
1252 "Split offset must be inside block content");
1253 Blocks.back()->setZeroFillSize(
1254 Offset - (Blocks.back()->getAddress() - B.getAddress()));
1256 B.getSection(), B.getSize(), B.getAddress() + Offset,
1257 B.getAlignment(),
1258 (B.getAlignmentOffset() + Offset) % B.getAlignment()));
1259 }
1260 Blocks.back()->setZeroFillSize(
1261 OrigSize - (Blocks.back()->getAddress() - B.getAddress()));
1262 return Blocks;
1263 }
1264
1265
1266
1267
1268 for (Edge::OffsetT Offset : SplitOffsets) {
1270 "Split offset must be inside block content");
1273 B.getAlignment(),
1274 (B.getAlignmentOffset() + Offset) % B.getAlignment()));
1275 }
1276
1277 return splitBlockImpl(std::move(Blocks), Cache);
1278 }
1279
1280
1282 return SSP->intern(SymbolName);
1283 }
1284
1285
1286
1287
1288
1289
1290
1291
1292
1295 bool IsWeaklyReferenced) {
1296 assert(!ExternalSymbols.contains(*Name) && "Duplicate external symbol");
1297 auto &Sym = Symbol::constructExternal(
1300 ExternalSymbols.insert({*Sym.getName(), &Sym});
1301 return Sym;
1302 }
1303
1305 bool IsWeaklyReferenced) {
1307 }
1308
1309
1313 bool IsLive) {
1315 [&](const Symbol *Sym) {
1316 return Sym->getName() == Name;
1317 })) &&
1318 "Duplicate absolute symbol");
1319 auto &Sym = Symbol::constructAbsolute(Allocator, createAddressable(Address),
1320 std::move(Name), Size, L, S, IsLive);
1321 AbsoluteSymbols.insert(&Sym);
1322 return Sym;
1323 }
1324
1327 bool IsLive) {
1328
1330 }
1331
1332
1335 bool IsLive) {
1336 auto &Sym = Symbol::constructAnonDef(Allocator, Content, Offset, Size,
1337 IsCallable, IsLive);
1338 Content.getSection().addSymbol(Sym);
1339 return Sym;
1340 }
1341
1342
1345 Linkage L, Scope S, bool IsCallable, bool IsLive) {
1347 IsCallable, IsLive);
1348 }
1349
1353 bool IsCallable, bool IsLive) {
1355 [&](const Symbol *Sym) {
1356 return Sym->getName() == Name;
1357 })) &&
1358 "Duplicate defined symbol");
1359 auto &Sym =
1360 Symbol::constructNamedDef(Allocator, Content, Offset, std::move(Name),
1361 Size, L, S, IsLive, IsCallable);
1362 Content.getSection().addSymbol(Sym);
1363 return Sym;
1364 }
1365
1371
1375 GetSectionMapEntryConstValue()),
1377 }
1378
1380
1381
1382
1384 auto I = Sections.find(Name);
1385 if (I == Sections.end())
1386 return nullptr;
1387 return I->second.get();
1388 }
1389
1395
1401
1405 GetExternalSymbolMapEntryValue()),
1407 GetExternalSymbolMapEntryValue()));
1408 }
1409
1410
1411
1414 if (Sym->getName() == Name)
1415 return Sym;
1416 return nullptr;
1417 }
1418
1420 return make_range(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
1421 }
1422
1425 if (Sym->getName() == Name)
1426 return Sym;
1427 return nullptr;
1428 }
1429
1435
1441
1442
1443
1446 if (Sym->hasName() && Sym->getName() == Name)
1447 return Sym;
1448 return nullptr;
1449 }
1450
1451
1452
1453
1454
1458 assert(AbsoluteSymbols.count(&Sym) &&
1459 "Sym is not in the absolute symbols set");
1460 assert(Sym.getOffset() == 0 && "Absolute not at offset 0");
1461 AbsoluteSymbols.erase(&Sym);
1463 A.setAbsolute(false);
1465 } else {
1466 assert(Sym.isDefined() && "Sym is not a defined symbol");
1468 Sec.removeSymbol(Sym);
1469 Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
1470 }
1471 ExternalSymbols.insert({*Sym.getName(), &Sym});
1472 }
1473
1474
1475
1476
1477
1478
1479
1480
1481
1485 assert(ExternalSymbols.contains(*Sym.getName()) &&
1486 "Sym is not in the absolute symbols set");
1487 assert(Sym.getOffset() == 0 && "External is not at offset 0");
1488 ExternalSymbols.erase(*Sym.getName());
1490 A.setAbsolute(true);
1493 } else {
1494 assert(Sym.isDefined() && "Sym is not a defined symbol");
1496 Sec.removeSymbol(Sym);
1497 Sym.makeAbsolute(createAddressable(Address));
1498 }
1499 AbsoluteSymbols.insert(&Sym);
1500 }
1501
1502
1503
1506 bool IsLive) {
1507 assert(!Sym.isDefined() && "Sym is already a defined symbol");
1509 assert(AbsoluteSymbols.count(&Sym) &&
1510 "Symbol is not in the absolutes set");
1511 AbsoluteSymbols.erase(&Sym);
1512 } else {
1513 assert(ExternalSymbols.contains(*Sym.getName()) &&
1514 "Symbol is not in the externals set");
1515 ExternalSymbols.erase(*Sym.getName());
1516 }
1518 Sym.setBlock(Content);
1524 Content.getSection().addSymbol(Sym);
1525 destroyAddressable(OldBase);
1526 }
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537 void
1540 std::optionalorc::ExecutorAddrDiff ExplicitNewSize) {
1541 auto &OldSection = Sym.getSection();
1542 Sym.setBlock(DestBlock);
1544 if (ExplicitNewSize)
1545 Sym.setSize(*ExplicitNewSize);
1546 else {
1547 auto RemainingBlockSize = DestBlock.getSize() - NewOffset;
1548 if (Sym.getSize() > RemainingBlockSize)
1549 Sym.setSize(RemainingBlockSize);
1550 }
1551 if (&DestBlock.getSection() != &OldSection) {
1552 OldSection.removeSymbol(Sym);
1553 DestBlock.getSection().addSymbol(Sym);
1554 }
1555 }
1556
1557
1558
1559
1560
1561
1562
1563
1565 auto &OldSection = B.getSection();
1566 if (&OldSection == &NewSection)
1567 return;
1569 for (auto *S : OldSection.symbols())
1572 for (auto *S : AttachedSymbols) {
1573 OldSection.removeSymbol(*S);
1574 NewSection.addSymbol(*S);
1575 }
1576 OldSection.removeBlock(B);
1577 NewSection.addBlock(B);
1578 }
1579
1580
1581
1582
1583
1584
1586 bool PreserveSrcSection = false) {
1587 if (&DstSection == &SrcSection)
1588 return;
1589 for (auto *B : SrcSection.blocks())
1590 B->setSection(DstSection);
1591 SrcSection.transferContentTo(DstSection);
1592 if (!PreserveSrcSection)
1594 }
1595
1596
1599 "Sym is not an external symbol");
1600 assert(ExternalSymbols.contains(*Sym.getName()) &&
1601 "Symbol is not in the externals set");
1602 ExternalSymbols.erase(*Sym.getName());
1605 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1606 "Base addressable still in use");
1607 destroySymbol(Sym);
1608 destroyAddressable(Base);
1609 }
1610
1611
1614 "Sym is not an absolute symbol");
1615 assert(AbsoluteSymbols.count(&Sym) &&
1616 "Symbol is not in the absolute symbols set");
1617 AbsoluteSymbols.erase(&Sym);
1620 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1621 "Base addressable still in use");
1622 destroySymbol(Sym);
1623 destroyAddressable(Base);
1624 }
1625
1626
1628 assert(Sym.isDefined() && "Sym is not a defined symbol");
1630 destroySymbol(Sym);
1631 }
1632
1633
1634
1637 [&](const Symbol *Sym) {
1638 return &Sym->getBlock() == &B;
1639 }) &&
1640 "Block still has symbols attached");
1641 B.getSection().removeBlock(B);
1642 destroyBlock(B);
1643 }
1644
1645
1646
1648 assert(Sections.count(Sec.getName()) && "Section not found");
1649 assert(Sections.find(Sec.getName())->second.get() == &Sec &&
1650 "Section map entry invalid");
1651 Sections.erase(Sec.getName());
1652 }
1653
1654
1655
1656
1657
1658
1660
1661
1663
1664private:
1665 LLVM_ABI std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
1667
1668
1669
1671
1672 std::string Name;
1673 std::shared_ptrorc::SymbolStringPool SSP;
1678
1679 ExternalSymbolMap ExternalSymbols;
1680 AbsoluteSymbolSet AbsoluteSymbols;
1682};
1683
1689
1690
1692public:
1695
1696
1698
1699
1701
1703
1704
1705
1706 template
1708 if (!Pred(B))
1710
1711 auto I = AddrToBlock.upper_bound(B.getAddress());
1712
1713
1714
1715 if (I != AddrToBlock.end()) {
1716 if (B.getAddress() + B.getSize() > I->second->getAddress())
1717 return overlapError(B, *I->second);
1718 }
1719
1720
1721
1722 if (I != AddrToBlock.begin()) {
1723 auto &PrevBlock = *std::prev(I)->second;
1724 if (PrevBlock.getAddress() + PrevBlock.getSize() > B.getAddress())
1725 return overlapError(B, PrevBlock);
1726 }
1727
1728 AddrToBlock.insert(I, std::make_pair(B.getAddress(), &B));
1730 }
1731
1732
1733
1734
1736
1737
1738
1739
1740 template <typename BlockPtrRange,
1743 for (auto *B : Blocks)
1744 if (auto Err = addBlock(*B, Pred))
1745 return Err;
1747 }
1748
1749
1750
1751
1752 template
1754 for (auto *B : Blocks)
1756 }
1757
1758
1761
1762
1763
1765 auto I = AddrToBlock.find(Addr);
1766 if (I == AddrToBlock.end())
1767 return nullptr;
1768 return I->second;
1769 }
1770
1771
1772
1774 auto I = AddrToBlock.upper_bound(Addr);
1775 if (I == AddrToBlock.begin())
1776 return nullptr;
1777 auto *B = std::prev(I)->second;
1778 if (Addr < B->getAddress() + B->getSize())
1779 return B;
1780 return nullptr;
1781 }
1782
1783private:
1784 Error overlapError(Block &NewBlock, Block &ExistingBlock) {
1786 auto ExistingBlockEnd =
1789 "Block at " +
1791 NewBlockEnd.getValue()) +
1792 " overlaps " +
1794 ExistingBlockEnd.getValue()));
1795 }
1796
1798};
1799
1800
1802public:
1804
1805
1807 AddrToSymbols[Sym.getAddress()].push_back(&Sym);
1808 }
1809
1810
1811 template
1813 for (auto *Sym : Symbols)
1815 }
1816
1817
1818
1820 auto I = AddrToSymbols.find(Addr);
1821 if (I == AddrToSymbols.end())
1822 return nullptr;
1823 return &I->second;
1824 }
1825
1826private:
1827 std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1828};
1829
1830
1832
1833
1835
1836
1837
1839
1840
1841
1842
1843
1844
1845
1847
1848
1849
1850
1851
1852
1853
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1881
1882
1883
1884
1885
1886
1887
1888
1890};
1891
1892
1893
1894
1895
1897
1899
1900
1903
1904
1905
1907public:
1910
1911private:
1912 virtual void anchor();
1913};
1914
1915
1916template
1917std::unique_ptr
1919
1921 public:
1922 Impl(Continuation C) : C(std::move(C)) {}
1924
1925 private:
1926 Continuation C;
1927 };
1928
1929 return std::make_unique(std::move(Cont));
1930}
1931
1932
1934public:
1936
1937
1939
1940
1942
1943
1945
1946
1948
1949
1950
1952
1953
1954
1955
1957 std::unique_ptr LC) = 0;
1958
1959
1960
1961
1962
1963
1964
1965
1966
1968
1969
1970
1971
1972
1974
1975
1976
1977
1978
1980
1981
1982
1983
1984
1985
1986
1988
1989
1990
1992
1993private:
1995};
1996
1997
1998
2000
2001
2004
2007
2008
2009
2010
2011
2012
2013
2014
2018
2019
2021
2022
2023
2024
2025
2028
2029
2031
2032
2034
2035
2036
2037
2038template <typename VisitorT, typename... VisitorTs>
2040 VisitorTs &&...Vs) {
2041 if (!V.visitEdge(G, B, E))
2042 visitEdge(G, B, E, std::forward(Vs)...);
2043}
2044
2045
2046
2047
2048
2049
2050
2051template <typename... VisitorTs>
2053
2054
2055 std::vector<Block *> Worklist(G.blocks().begin(), G.blocks().end());
2056
2057 for (auto *B : Worklist)
2058 for (auto &E : B->edges())
2059 visitEdge(G, B, E, std::forward(Vs)...);
2060}
2061
2062
2063
2064
2065
2066
2069 std::shared_ptrorc::SymbolStringPool SSP);
2070
2071
2072LLVM_ABI std::unique_ptr
2075
2076
2078 std::unique_ptr Ctx);
2079
2080}
2081}
2082
2083#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
static void makeAbsolute(vfs::FileSystem &VFS, SmallVectorImpl< char > &Path)
Make Path absolute.
std::unordered_set< BasicBlock * > BlockSet
std::pair< BasicBlock *, BasicBlock * > Edge
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Provides read only access to a subclass of BinaryStream.
Provides write only access to a subclass of WritableBinaryStream.
Implements a dense probed hash-table based set.
Base class for user error types.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringMapIterBase< Symbol *, false > iterator
StringMapEntry< Symbol * > value_type
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
static LLVM_ABI unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch)
Returns the pointer width of this architecture.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
DenseSetIterator< false > iterator
DenseSetIterator< true > const_iterator
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
Base class for Addressable entities (externals, absolutes, blocks).
Definition JITLink.h:112
void setAddress(orc::ExecutorAddr Address)
Definition JITLink.h:132
Addressable & operator=(Addressable &&)=default
bool isDefined() const
Returns true if this is a defined addressable, in which case you can downcast this to a Block.
Definition JITLink.h:136
uint64_t AlignmentOffset
Definition JITLink.h:153
orc::ExecutorAddr getAddress() const
Definition JITLink.h:131
bool isAbsolute() const
Definition JITLink.h:137
uint64_t P2Align
Definition JITLink.h:152
Addressable(Addressable &&)=delete
Addressable(orc::ExecutorAddr Address)
Definition JITLink.h:119
Addressable(const Addressable &)=delete
uint64_t ContentMutable
Definition JITLink.h:151
Addressable(orc::ExecutorAddr Address, bool IsDefined)
Definition JITLink.h:116
friend class LinkGraph
Definition JITLink.h:113
Addressable & operator=(const Addressable &)=default
const_iterator end() const
Definition JITLink.h:1760
const_iterator begin() const
Iterates over (Address, Block*) pairs in ascending order of address.
Definition JITLink.h:1759
Block * getBlockCovering(orc::ExecutorAddr Addr) const
Returns the block covering the given address, or nullptr if no such block exists.
Definition JITLink.h:1773
Error addBlock(Block &B, PredFn Pred=includeAllBlocks)
Add a block to the map.
Definition JITLink.h:1707
std::map< orc::ExecutorAddr, Block * > AddrToBlockMap
Definition JITLink.h:1693
void addBlockWithoutChecking(Block &B)
Add a block to the map without checking for overlap with existing blocks.
Definition JITLink.h:1735
BlockAddressMap()=default
static bool includeAllBlocks(const Block &B)
A block predicate that always adds all blocks.
Definition JITLink.h:1697
AddrToBlockMap::const_iterator const_iterator
Definition JITLink.h:1694
Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred=includeAllBlocks)
Add a range of blocks to the map.
Definition JITLink.h:1742
Block * getBlockAt(orc::ExecutorAddr Addr) const
Returns the block starting at the given address, or nullptr if no such block exists.
Definition JITLink.h:1764
static bool includeNonNull(const Block &B)
A block predicate that always includes blocks with non-null addresses.
Definition JITLink.h:1700
void addBlocksWithoutChecking(BlockPtrRange &&Blocks)
Add a range of blocks to the map without checking for overlap with existing blocks.
Definition JITLink.h:1753
An Addressable with content and edges.
Definition JITLink.h:159
Block(const Block &)=delete
void addEdge(const Edge &E)
Add an edge by copying an existing one.
Definition JITLink.h:328
bool isContentMutable() const
Returns true if this block's content is mutable.
Definition JITLink.h:297
ArrayRef< char > getContent() const
Get the content for this block. Block must not be a zero-fill block.
Definition JITLink.h:247
iterator_range< const_edge_iterator > edges() const
Returns the list of edges attached to this content.
Definition JITLink.h:336
auto edges_at(Edge::OffsetT O) const
Returns an iterator over all edges at the given offset within the block.
Definition JITLink.h:347
uint64_t getAlignmentOffset() const
Get the alignment offset for this content.
Definition JITLink.h:309
uint64_t getAlignment() const
Get the alignment for this content.
Definition JITLink.h:300
bool isZeroFill() const
Returns true if this is a zero-fill block.
Definition JITLink.h:230
void setZeroFillSize(size_t Size)
Turns this block into a zero-fill block of the given size.
Definition JITLink.h:236
Block & operator=(Block &&)=delete
size_t edges_size() const
Return the size of the edges list.
Definition JITLink.h:353
edge_iterator removeEdge(edge_iterator I)
Remove the edge pointed to by the given iterator.
Definition JITLink.h:360
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
Definition JITLink.h:319
void setMutableContent(MutableArrayRef< char > MutableContent)
Set mutable content for this block.
Definition JITLink.h:284
MutableArrayRef< char > getMutableContent(LinkGraph &G)
Get mutable content for this block.
Definition JITLink.h:1684
void setContent(ArrayRef< char > Content)
Set the content for this block.
Definition JITLink.h:255
orc::ExecutorAddrRange getRange() const
Returns the address range of this defined addressable.
Definition JITLink.h:242
Section & getSection() const
Return the parent section for this block.
Definition JITLink.h:224
size_t getSize() const
Returns the size of this defined addressable.
Definition JITLink.h:233
void setAlignment(uint64_t Alignment)
Set the alignment for this content.
Definition JITLink.h:303
Block & operator=(const Block &)=delete
void setAlignmentOffset(uint64_t AlignmentOffset)
Set the alignment offset for this content.
Definition JITLink.h:312
iterator_range< edge_iterator > edges()
Return the list of edges attached to this content.
Definition JITLink.h:331
MutableArrayRef< char > getAlreadyMutableContent()
Get mutable content for this block.
Definition JITLink.h:274
friend class LinkGraph
Definition JITLink.h:160
orc::ExecutorAddr getFixupAddress(const Edge &E) const
Returns the address of the fixup for the given edge, which is equal to this block's address plus the ...
Definition JITLink.h:364
auto edges_at(Edge::OffsetT O)
Returns an iterator over all edges at the given offset within the block.
Definition JITLink.h:341
EdgeVector::iterator edge_iterator
Definition JITLink.h:215
EdgeVector::const_iterator const_edge_iterator
Definition JITLink.h:216
std::vector< Edge > EdgeVector
Definition JITLink.h:214
bool edges_empty() const
Returns true if the list of edges is empty.
Definition JITLink.h:356
Represents fixups and constraints in the LinkGraph.
Definition JITLink.h:68
Symbol & getTarget() const
Definition JITLink.h:95
Kind getRelocation() const
Definition JITLink.h:90
AddendT getAddend() const
Definition JITLink.h:97
bool isRelocation() const
Definition JITLink.h:89
OffsetT getOffset() const
Definition JITLink.h:85
void setTarget(Symbol &Target)
Definition JITLink.h:96
void setKind(Kind K)
Definition JITLink.h:88
uint32_t OffsetT
Definition JITLink.h:79
GenericEdgeKind
Definition JITLink.h:72
@ FirstKeepAlive
Definition JITLink.h:74
@ Invalid
Definition JITLink.h:73
@ FirstRelocation
Definition JITLink.h:76
@ KeepAlive
Definition JITLink.h:75
Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
Definition JITLink.h:82
int64_t AddendT
Definition JITLink.h:80
void setAddend(AddendT Addend)
Definition JITLink.h:98
Kind getKind() const
Definition JITLink.h:87
uint8_t Kind
Definition JITLink.h:70
void setOffset(OffsetT Offset)
Definition JITLink.h:86
bool isKeepAlive() const
Definition JITLink.h:94
A function object to call with a resolved symbol map (See AsyncLookupResult) or an error if resolutio...
Definition JITLink.h:1906
virtual ~JITLinkAsyncLookupContinuation()=default
virtual void run(Expected< AsyncLookupResult > LR)=0
virtual void notifyFinalized(JITLinkMemoryManager::FinalizedAlloc Alloc)=0
Called by JITLink to notify the context that the object has been finalized (i.e.
JITLinkContext(const JITLinkDylib *JD)
Create a JITLinkContext.
Definition JITLink.h:1938
virtual ~JITLinkContext()
Destroy a JITLinkContext.
virtual Error modifyPassConfig(LinkGraph &G, PassConfiguration &Config)
Called by JITLink to modify the pass pipeline prior to linking.
const JITLinkDylib * getJITLinkDylib() const
Return the JITLinkDylib that this link is targeting, if any.
Definition JITLink.h:1944
virtual void notifyFailed(Error Err)=0
Notify this context that linking failed.
DenseMap< orc::SymbolStringPtr, SymbolLookupFlags > LookupMap
Definition JITLink.h:1935
virtual JITLinkMemoryManager & getMemoryManager()=0
Return the MemoryManager to be used for this link.
virtual void lookup(const LookupMap &Symbols, std::unique_ptr< JITLinkAsyncLookupContinuation > LC)=0
Called by JITLink to resolve external symbols.
virtual Error notifyResolved(LinkGraph &G)=0
Called by JITLink once all defined symbols in the graph have been assigned their final memory locatio...
virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const
Called by JITLink prior to linking to determine whether default passes for the target should be added...
virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const
Returns the mark-live pass to be used for this link.
static char ID
Definition JITLink.h:55
JITLinkError(Twine ErrMsg)
Definition JITLink.h:57
const std::string & getErrorMessage() const
Definition JITLink.h:60
Represents a finalized allocation.
Manages allocations of JIT memory.
bool operator==(const nested_collection_iterator &RHS) const
Definition JITLink.h:978
nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
Definition JITLink.h:972
nested_collection_iterator()=default
T operator*() const
Definition JITLink.h:982
nested_collection_iterator operator++()
Definition JITLink.h:987
Symbol * findExternalSymbolByName(const orc::SymbolStringPtrBase &Name)
Returns the external symbol with the given name if one exists, otherwise returns nullptr.
Definition JITLink.h:1412
MutableArrayRef< char > allocateCString(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Definition JITLink.h:1128
void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address)
Make the given symbol an absolute with the given address (must not already be absolute).
Definition JITLink.h:1482
orc::SymbolStringPtr intern(StringRef SymbolName)
Intern the given string in the LinkGraph's SymbolStringPool.
Definition JITLink.h:1281
void mergeSections(Section &DstSection, Section &SrcSection, bool PreserveSrcSection=false)
Move all blocks and symbols from the source section to the destination section.
Definition JITLink.h:1585
Symbol & addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, StringRef Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
Add a named symbol.
Definition JITLink.h:1343
void removeExternalSymbol(Symbol &Sym)
Removes an external symbol. Also removes the underlying Addressable.
Definition JITLink.h:1597
Block & createContentBlock(Section &Parent, ArrayRef< char > Content, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block.
Definition JITLink.h:1145
void removeDefinedSymbol(Symbol &Sym)
Removes defined symbols. Does not remove the underlying block.
Definition JITLink.h:1627
MutableArrayRef< char > allocateContent(ArrayRef< char > Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Definition JITLink.h:1076
BinaryStreamWriter getBlockContentWriter(Block &B)
Returns a BinaryStreamWriter for the given block.
Definition JITLink.h:1191
nested_collection_iterator< section_iterator, Section::symbol_iterator, Symbol *, getSectionSymbols > defined_symbol_iterator
Definition JITLink.h:1009
nested_collection_iterator< const_section_iterator, Section::const_block_iterator, const Block *, getSectionConstBlocks > const_block_iterator
Definition JITLink.h:1022
nested_collection_iterator< const_section_iterator, Section::const_symbol_iterator, const Symbol *, getSectionConstSymbols > const_defined_symbol_iterator
Definition JITLink.h:1013
const std::string & getName() const
Returns the name of this graph (usually the name of the original underlying MemoryBuffer).
Definition JITLink.h:1047
iterator_range< absolute_symbol_iterator > absolute_symbols()
Definition JITLink.h:1419
Symbol & addExternalSymbol(orc::SymbolStringPtr Name, orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced)
Add an external symbol.
Definition JITLink.h:1293
size_t sections_size() const
Definition JITLink.h:1379
void removeAbsoluteSymbol(Symbol &Sym)
Remove an absolute symbol. Also removes the underlying Addressable.
Definition JITLink.h:1612
StringRef allocateName(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator and return it as a StringRef.
Definition JITLink.h:1102
MutableArrayRef< char > allocateCString(StringRef Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Definition JITLink.h:1112
Symbol & addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::SymbolStringPtr Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
Definition JITLink.h:1350
const SubtargetFeatures & getFeatures() const
Return the subtarget features for this Graph.
Definition JITLink.h:1053
void removeSection(Section &Sec)
Remove a section.
Definition JITLink.h:1647
void makeExternal(Symbol &Sym)
Make the given symbol external (must not already be external).
Definition JITLink.h:1455
LinkGraph(LinkGraph &&)=delete
Symbol & addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Definition JITLink.h:1325
Block & createZeroFillBlock(Section &Parent, orc::ExecutorAddrDiff Size, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a zero-fill block.
Definition JITLink.h:1176
orc::shared::AllocActions & allocActions()
Accessor for the AllocActions object for this graph.
Definition JITLink.h:1659
mapped_iterator< SectionMap::const_iterator, GetSectionMapEntryConstValue > const_section_iterator
Definition JITLink.h:959
LLVM_ABI void dump(raw_ostream &OS)
Dump the graph.
MutableArrayRef< char > allocateContent(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Definition JITLink.h:1089
nested_collection_iterator< section_iterator, Section::block_iterator, Block *, getSectionBlocks > block_iterator
Definition JITLink.h:1018
iterator_range< const_defined_symbol_iterator > defined_symbols() const
Definition JITLink.h:1436
mapped_iterator< ExternalSymbolMap::iterator, GetExternalSymbolMapEntryValue > external_symbol_iterator
Definition JITLink.h:952
void removeBlock(Block &B)
Remove a block.
Definition JITLink.h:1635
LinkGraph(std::string Name, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features, GetEdgeKindNameFunction GetEdgeKindName)
Definition JITLink.h:1029
iterator_range< const_section_iterator > sections() const
Definition JITLink.h:1372
AbsoluteSymbolSet::iterator absolute_symbol_iterator
Definition JITLink.h:955
std::vector< Block * > splitBlock(Block &B, SplitOffsetRange &&SplitOffsets, LinkGraph::SplitBlockCache *Cache=nullptr)
Splits block B into a sequence of smaller blocks.
Definition JITLink.h:1239
LinkGraph & operator=(const LinkGraph &)=delete
iterator_range< external_symbol_iterator > external_symbols()
Definition JITLink.h:1402
Block & createMutableContentBlock(Section &Parent, MutableArrayRef< char > MutableContent, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block with initially mutable data.
Definition JITLink.h:1152
mapped_iterator< SectionMap::iterator, GetSectionMapEntryValue > section_iterator
Definition JITLink.h:957
unsigned getPointerSize() const
Returns the pointer size for use in this graph.
Definition JITLink.h:1056
LinkGraph(const LinkGraph &)=delete
Symbol & addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced)
Definition JITLink.h:1304
iterator_range< block_iterator > blocks()
Definition JITLink.h:1390
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
Definition JITLink.h:1027
void makeDefined(Symbol &Sym, Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Turn an absolute or external symbol into a defined one by attaching it to a block.
Definition JITLink.h:1504
std::shared_ptr< orc::SymbolStringPool > getSymbolStringPool()
Definition JITLink.h:1065
Section * findSectionByName(StringRef Name)
Returns the section with the given name if it exists, otherwise returns null.
Definition JITLink.h:1383
Block & createMutableContentBlock(Section &Parent, size_t ContentSize, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset, bool ZeroInitialize=true)
Create a content block with initially mutable data of the given size.
Definition JITLink.h:1165
iterator_range< section_iterator > sections()
Definition JITLink.h:1366
Symbol * findAbsoluteSymbolByName(const orc::SymbolStringPtrBase &Name)
Definition JITLink.h:1423
Symbol & addAbsoluteSymbol(orc::SymbolStringPtr Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Add an absolute symbol.
Definition JITLink.h:1310
void transferBlock(Block &B, Section &NewSection)
Transfers the given Block and all Symbols pointing to it to the given Section.
Definition JITLink.h:1564
const Triple & getTargetTriple() const
Returns the target triple for this Graph.
Definition JITLink.h:1050
iterator_range< const_block_iterator > blocks() const
Definition JITLink.h:1396
Symbol & addAnonymousSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, bool IsCallable, bool IsLive)
Add an anonymous symbol.
Definition JITLink.h:1333
const char * getEdgeKindName(Edge::Kind K) const
Definition JITLink.h:1063
Section & createSection(StringRef Name, orc::MemProt Prot)
Create a section with the given name, protection flags.
Definition JITLink.h:1138
LinkGraph & operator=(LinkGraph &&)=delete
BinaryStreamReader getBlockContentReader(Block &B)
Returns a BinaryStreamReader for the given block.
Definition JITLink.h:1183
MutableArrayRef< char > allocateBuffer(size_t Size)
Allocate a mutable buffer of the given size using the LinkGraph's allocator.
Definition JITLink.h:1069
Symbol * findDefinedSymbolByName(const orc::SymbolStringPtrBase &Name)
Returns the defined symbol with the given name if one exists, otherwise returns nullptr.
Definition JITLink.h:1444
llvm::endianness getEndianness() const
Returns the endianness of content in this graph.
Definition JITLink.h:1059
iterator_range< defined_symbol_iterator > defined_symbols()
Definition JITLink.h:1430
std::optional< SmallVector< Symbol *, 8 > > SplitBlockCache
Cache type for the splitBlock function.
Definition JITLink.h:1199
void transferDefinedSymbol(Symbol &Sym, Block &DestBlock, orc::ExecutorAddrDiff NewOffset, std::optional< orc::ExecutorAddrDiff > ExplicitNewSize)
Transfer a defined symbol from one block to another.
Definition JITLink.h:1538
Block * getFirstBlock() const
Definition JITLink.h:850
orc::ExecutorAddrRange getRange() const
Definition JITLink.h:870
orc::ExecutorAddr getEnd() const
Definition JITLink.h:865
bool empty() const
Definition JITLink.h:858
orc::ExecutorAddrDiff getSize() const
Definition JITLink.h:868
orc::ExecutorAddr getStart() const
Definition JITLink.h:862
SectionRange(const Section &Sec)
Definition JITLink.h:839
Block * getLastBlock() const
Definition JITLink.h:854
Represents an object file section.
Definition JITLink.h:718
iterator_range< symbol_iterator > symbols()
Returns an iterator over the symbols defined in this section.
Definition JITLink.h:782
Section & operator=(const Section &)=delete
Section(const Section &)=delete
StringRef getName() const
Returns the name of this section.
Definition JITLink.h:744
SymbolSet::const_iterator const_symbol_iterator
Definition JITLink.h:730
SymbolSet::iterator symbol_iterator
Definition JITLink.h:729
SectionOrdinal getOrdinal() const
Returns the ordinal for this section.
Definition JITLink.h:759
BlockSet::const_iterator const_block_iterator
Definition JITLink.h:733
BlockSet::iterator block_iterator
Definition JITLink.h:732
iterator_range< block_iterator > blocks()
Returns an iterator over the blocks defined in this section.
Definition JITLink.h:769
orc::MemProt getMemProt() const
Returns the protection flags for this section.
Definition JITLink.h:747
iterator_range< const_symbol_iterator > symbols() const
Returns an iterator over the symbols defined in this section.
Definition JITLink.h:787
bool empty() const
Returns true if this section is empty (contains no blocks or symbols).
Definition JITLink.h:766
SymbolSet::size_type symbols_size() const
Return the number of symbols in this section.
Definition JITLink.h:792
iterator_range< const_block_iterator > blocks() const
Returns an iterator over the blocks defined in this section.
Definition JITLink.h:774
BlockSet::size_type blocks_size() const
Returns the number of blocks in this section.
Definition JITLink.h:779
void setMemProt(orc::MemProt Prot)
Set the protection flags for this section.
Definition JITLink.h:750
friend class LinkGraph
Definition JITLink.h:719
Section(Section &&)=delete
Section & operator=(Section &&)=delete
void setOrdinal(SectionOrdinal SecOrdinal)
Set the ordinal for this section.
Definition JITLink.h:763
void setMemLifetime(orc::MemLifetime ML)
Set the memory lifetime policy for this section.
Definition JITLink.h:756
orc::MemLifetime getMemLifetime() const
Get the memory lifetime policy for this section.
Definition JITLink.h:753
A map of addresses to Symbols.
Definition JITLink.h:1801
const SymbolVector * getSymbolsAt(orc::ExecutorAddr Addr) const
Returns the list of symbols that start at the given address, or nullptr if no such symbols exist.
Definition JITLink.h:1819
void addSymbols(SymbolPtrCollection &&Symbols)
Add all symbols in a given range to the SymbolAddressMap.
Definition JITLink.h:1812
void addSymbol(Symbol &Sym)
Add a symbol to the SymbolAddressMap.
Definition JITLink.h:1806
SmallVector< Symbol *, 1 > SymbolVector
Definition JITLink.h:1803
Symbol representation.
Definition JITLink.h:433
bool isExternal() const
Returns true if the underlying addressable is an unresolved external.
Definition JITLink.h:554
Symbol & operator=(Symbol &&)=delete
bool isCallable() const
Returns true is this symbol is callable.
Definition JITLink.h:548
void setScope(Scope S)
Set the visibility for this Symbol.
Definition JITLink.h:647
Symbol()=default
Create a null Symbol.
void setName(const orc::SymbolStringPtr Name)
Rename this symbol.
Definition JITLink.h:528
TargetFlagsType getTargetFlags() const
Get the target flags of this Symbol.
Definition JITLink.h:656
bool isLive() const
Returns true if this symbol is live (i.e.
Definition JITLink.h:539
const orc::SymbolStringPtr & getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
Definition JITLink.h:519
bool isDefined() const
Returns true if this Symbol has content (potentially) defined within this object file (i....
Definition JITLink.h:532
Scope getScope() const
Get the visibility for this Symbol.
Definition JITLink.h:644
bool isAbsolute() const
Returns true if the underlying addressable is an absolute symbol.
Definition JITLink.h:560
const Block & getBlock() const
Return the Block for this Symbol (Symbol must be defined).
Definition JITLink.h:585
Addressable & getAddressable()
Return the addressable that this symbol points to.
Definition JITLink.h:566
Linkage getLinkage() const
Get the linkage for this Symbol.
Definition JITLink.h:634
void setTargetFlags(TargetFlagsType Flags)
Set the target flags for this Symbol.
Definition JITLink.h:659
orc::ExecutorAddrRange getRange() const
Returns the address range of this symbol.
Definition JITLink.h:619
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
Definition JITLink.h:603
ArrayRef< char > getSymbolContent() const
Returns the content in the underlying block covered by this symbol.
Definition JITLink.h:629
Section & getSection() const
Return the Section for this Symbol (Symbol must be defined).
Definition JITLink.h:592
Symbol & operator=(const Symbol &)=delete
void setLive(bool IsLive)
Set this symbol's live bit.
Definition JITLink.h:545
void setLinkage(Linkage L)
Set the linkage for this Symbol.
Definition JITLink.h:637
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
Definition JITLink.h:578
orc::ExecutorAddrDiff getSize() const
Returns the size of this symbol.
Definition JITLink.h:606
bool isSymbolZeroFill() const
Returns true if this symbol is backed by a zero-fill block.
Definition JITLink.h:625
orc::ExecutorAddrDiff getOffset() const
Returns the offset for this symbol within the underlying addressable.
Definition JITLink.h:595
void setOffset(orc::ExecutorAddrDiff NewOffset)
Definition JITLink.h:597
friend class LinkGraph
Definition JITLink.h:434
Symbol(const Symbol &)=delete
void setSize(orc::ExecutorAddrDiff Size)
Set the size of this symbol.
Definition JITLink.h:609
void setWeaklyReferenced(bool WeakRef)
Set the WeaklyReferenced value for this symbol.
Definition JITLink.h:673
const Addressable & getAddressable() const
Return the addressable that this symbol points to.
Definition JITLink.h:572
void setCallable(bool IsCallable)
Set this symbol's callable bit.
Definition JITLink.h:551
bool isWeaklyReferenced() const
Returns true if this is a weakly referenced external symbol.
Definition JITLink.h:666
bool hasName() const
Returns true if this symbol has a name.
Definition JITLink.h:516
Represents an address in the executor process.
uint64_t getValue() const
Base class for both owning and non-owning symbol-string ptrs.
Pointer to a pooled string representing a symbol name.
This class implements an extremely fast bulk output stream that can only output to a stream.
unique_function is a type-erasing functor similar to std::function.
@ C
The default llvm calling convention, compatible with C.
unique_function< Error(LinkGraph &)> LinkGraphPassFunction
A function for mutating LinkGraphs.
Definition JITLink.h:1831
LLVM_ABI Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, const Edge &E)
Create an out of range error for the given edge in the given block.
std::unique_ptr< JITLinkAsyncLookupContinuation > createLookupContinuation(Continuation Cont)
Create a lookup continuation from a function object.
Definition JITLink.h:1918
LLVM_ABI const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
LLVM_ABI const char * getLinkageName(Linkage L)
For errors and debugging output.
SymbolLookupFlags
Flags for symbol lookup.
Definition JITLink.h:1896
@ WeaklyReferencedSymbol
Definition JITLink.h:1896
@ RequiredSymbol
Definition JITLink.h:1896
LLVM_ABI std::unique_ptr< LinkGraph > absoluteSymbolsLinkGraph(Triple TT, std::shared_ptr< orc::SymbolStringPool > SSP, orc::SymbolMap Symbols)
Create a LinkGraph defining the given absolute symbols.
uint64_t alignToBlock(uint64_t Addr, const Block &B)
Definition JITLink.h:380
LLVM_ABI Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N, const Edge &E)
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const Block &B)
LLVM_ABI PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT)
Get target-specific PointerJumpStubCreator.
unique_function< Symbol &( LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)> PointerJumpStubCreator
Create a jump stub that jumps via the pointer at the given symbol and an anonymous symbol pointing to...
Definition JITLink.h:2026
LLVM_ABI void link(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
Link the given graph.
void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs)
For each edge in the given graph, apply a list of visitors to the edge, stopping when the first visit...
Definition JITLink.h:2052
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
LLVM_ABI const char * getScopeName(Scope S)
For debugging output.
LLVM_ABI Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromObject(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from the given object buffer.
DenseMap< orc::SymbolStringPtr, orc::ExecutorSymbolDef > AsyncLookupResult
A map of symbol names to resolved addresses.
Definition JITLink.h:1901
uint8_t TargetFlagsType
Holds target-specific properties for a symbol.
Definition JITLink.h:402
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
Definition JITLink.h:396
@ Weak
Definition JITLink.h:398
@ Strong
Definition JITLink.h:397
unique_function< Symbol &(LinkGraph &G, Section &PointerSection, Symbol *InitialTarget, uint64_t InitialAddend)> AnonymousPointerCreator
Creates a new pointer block in the given section and returns an Anonymous symbol pointing to it.
Definition JITLink.h:2015
LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
std::vector< LinkGraphPassFunction > LinkGraphPassList
A list of LinkGraph passes.
Definition JITLink.h:1834
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
Definition JITLink.h:413
@ SideEffectsOnly
Definition JITLink.h:413
@ Local
Definition JITLink.h:413
@ Default
Definition JITLink.h:413
@ Hidden
Definition JITLink.h:413
LLVM_ABI bool isCStringBlock(Block &B)
void visitEdge(LinkGraph &G, Block *B, Edge &E)
Base case for edge-visitors where the visitor-list is empty.
Definition JITLink.h:2033
unsigned SectionOrdinal
Definition JITLink.h:156
LLVM_ABI AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT)
Get target-specific AnonymousPointerCreator.
MemProt
Describes Read/Write/Exec permissions for memory.
uint64_t ExecutorAddrDiff
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
MemLifetime
Describes a memory lifetime policy for memory to be allocated by a JITLinkMemoryManager.
@ Standard
Standard memory should be allocated by the allocator and then deallocated when the deallocate method ...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Implement std::hash so that hash_code can be used in STL containers.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
Definition JITLink.h:1838
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
Definition JITLink.h:1869
LinkGraphPassList PreFixupPasses
Pre-fixup passes.
Definition JITLink.h:1880
LinkGraphPassList PostFixupPasses
Post-fixup passes.
Definition JITLink.h:1889
LinkGraphPassList PostPrunePasses
Post-prune passes.
Definition JITLink.h:1854
LinkGraphPassList PrePrunePasses
Pre-prune passes.
Definition JITLink.h:1846
Represents an address range in the exceutor process.