LLVM: lib/CodeGen/TargetLoweringObjectFileImpl.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
69#include
70#include
71
72using namespace llvm;
73using namespace dwarf;
74
77 cl::desc("Putting Jump Table in function section"));
78
82 M.getModuleFlagsMetadata(ModuleFlags);
83
84 for (const auto &MFE: ModuleFlags) {
85
87 continue;
88
89 StringRef Key = MFE.Key->getString();
90 if (Key == "Objective-C Image Info Version") {
91 Version = mdconst::extract(MFE.Val)->getZExtValue();
92 } else if (Key == "Objective-C Garbage Collection" ||
93 Key == "Objective-C GC Only" ||
94 Key == "Objective-C Is Simulated" ||
95 Key == "Objective-C Class Properties" ||
96 Key == "Objective-C Image Swift Version") {
97 Flags |= mdconst::extract(MFE.Val)->getZExtValue();
98 } else if (Key == "Objective-C Image Info Section") {
99 Section = cast(MFE.Val)->getString();
100 }
101
102
103 else if (Key == "Swift ABI Version") {
104 Flags |= (mdconst::extract(MFE.Val)->getZExtValue()) << 8;
105 } else if (Key == "Swift Major Version") {
106 Flags |= (mdconst::extract(MFE.Val)->getZExtValue()) << 24;
107 } else if (Key == "Swift Minor Version") {
108 Flags |= (mdconst::extract(MFE.Val)->getZExtValue()) << 16;
109 }
110 }
111}
112
113
114
115
116
119}
120
124
127
134 break;
135
136 [[fallthrough]];
152 break;
164 } else {
172 }
173 break;
182 }
183 break;
187
188
189
190
191
198 break;
203 break;
208
209
210
212
213
216
217
218
219
223 }
224 break;
232 break;
241 } else {
245 }
247 break;
256 break;
264 } else {
267 }
268 break;
270
271
278 } else {
282 }
283 break;
291 break;
292 default:
293 break;
294 }
295}
296
301 if (auto *GO = dyn_cast(GV))
302 Used.insert(GO);
303}
304
308
309 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
312
314
315 for (const auto *Operand : LinkerOptions->operands()) {
316 if (cast(Operand)->getNumOperands() != 2)
318 for (const auto &Option : cast(Operand)->operands()) {
319 Streamer.emitBytes(cast(Option)->getString());
321 }
322 }
323 }
324
325 if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
328
330
331 for (const auto *Operand : DependentLibraries->operands()) {
333 cast(cast(Operand)->getOperand(0))->getString());
335 }
336 }
337
339
340
341
342
343
344
345 for (const auto *Operand : FuncInfo->operands()) {
346 const auto *MD = cast(Operand);
347 auto *GUID = mdconst::dyn_extract(MD->getOperand(0));
348 auto *Hash = mdconst::dyn_extract(MD->getOperand(1));
349 auto *Name = cast(MD->getOperand(2));
350 auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(
352
354 Streamer.emitInt64(GUID->getZExtValue());
355 Streamer.emitInt64(Hash->getZExtValue());
358 }
359 }
360
361 if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
362
363
364 auto *S = C.getObjectFileInfo()->getLLVMStatsSection();
366 for (const auto *Operand : LLVMStats->operands()) {
367 const auto *MD = cast(Operand);
368 assert(MD->getNumOperands() % 2 == 0 &&
369 ("Operand num should be even for a list of key/value pair"));
370 for (size_t I = 0; I < MD->getNumOperands(); I += 2) {
371
372 auto *Key = cast(MD->getOperand(I));
374 Streamer.emitBytes(Key->getString());
375
377 Twine(mdconst::dyn_extract(MD->getOperand(I + 1))
378 ->getZExtValue())
382 }
383 }
384 }
385
387 unsigned Flags = 0;
389
391 if (!Section.empty()) {
398 }
399
401}
402
413}
414
419 NameData += Sym->getName();
421 cast(getContext().getOrCreateSymbol(NameData));
427 unsigned Size = DL.getPointerSize();
434
436}
437
442}
443
449
451
452
453
458 }
459
463 }
464
466 MMI, Streamer);
467}
468
470
471
472
473
474
475
476
478 false) ||
480 false) ||
482 false) ||
484 false) ||
485 Name == ".llvmbc" || Name == ".llvmcmd")
487
488 if (.starts_with(".")) return K;
489
490
491 if (Name == ".bss" || Name.starts_with(".bss.") ||
492 Name.starts_with(".gnu.linkonce.b.") ||
493 Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
494 Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||
495 Name.starts_with(".llvm.linkonce.sb."))
497
498 if (Name == ".tdata" || Name.starts_with(".tdata.") ||
499 Name.starts_with(".gnu.linkonce.td.") ||
500 Name.starts_with(".llvm.linkonce.td."))
502
503 if (Name == ".tbss" || Name.starts_with(".tbss.") ||
504 Name.starts_with(".gnu.linkonce.tb.") ||
505 Name.starts_with(".llvm.linkonce.tb."))
507
508 return K;
509}
510
512 return SectionName.consume_front(Prefix) &&
514}
515
517
518
519
520 if (Name.starts_with(".note"))
522
525
528
531
534 if (Name == ".llvm.lto")
536
537 if (K.isBSS() || K.isThreadBSS())
539
541}
542
544 unsigned Flags = 0;
545
546 if (!K.isMetadata() && !K.isExclude())
548
549 if (K.isExclude())
551
552 if (K.isText())
554
555 if (K.isExecuteOnly())
557
558 if (K.isWriteable())
560
561 if (K.isThreadLocal())
563
564 if (K.isMergeableCString() || K.isMergeableConst())
566
567 if (K.isMergeableCString())
569
570 return Flags;
571}
572
575 if ()
576 return nullptr;
577
580 report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
581 "SelectionKind::NoDeduplicate, '" +
582 C->getName() + "' cannot be lowered.");
583
584 return C;
585}
586
590 if (!MD)
591 return nullptr;
592
593 auto *VM = cast(MD->getOperand(0).get());
594 auto *OtherGV = dyn_cast(VM->getValue());
595 return OtherGV ? dyn_cast(TM.getSymbol(OtherGV)) : nullptr;
596}
597
599 if (Kind.isMergeable1ByteCString())
600 return 1;
601 else if (Kind.isMergeable2ByteCString())
602 return 2;
603 else if (Kind.isMergeable4ByteCString())
604 return 4;
605 else if (Kind.isMergeableConst4())
606 return 4;
607 else if (Kind.isMergeableConst8())
608 return 8;
609 else if (Kind.isMergeableConst16())
610 return 16;
611 else if (Kind.isMergeableConst32())
612 return 32;
613 else {
614
615
616 assert(!Kind.isMergeableCString() && "unknown string width");
617 assert(!Kind.isMergeableConst() && "unknown data width");
618 return 0;
619 }
620}
621
622
623
625 if (Kind.isText())
626 return IsLarge ? ".ltext" : ".text";
627 if (Kind.isReadOnly())
628 return IsLarge ? ".lrodata" : ".rodata";
629 if (Kind.isBSS())
630 return IsLarge ? ".lbss" : ".bss";
631 if (Kind.isThreadData())
632 return ".tdata";
633 if (Kind.isThreadBSS())
634 return ".tbss";
635 if (Kind.isData())
636 return IsLarge ? ".ldata" : ".data";
637 if (Kind.isReadOnlyWithRel())
638 return IsLarge ? ".ldata.rel.ro" : ".data.rel.ro";
640}
641
645 unsigned EntrySize, bool UniqueSectionName) {
648 if (Kind.isMergeableCString()) {
649
650
651
653 cast(GO));
654
655 Name += ".str";
656 Name += utostr(EntrySize);
658 Name += utostr(Alignment.value());
659 } else if (Kind.isMergeableConst()) {
660 Name += ".cst";
661 Name += utostr(EntrySize);
662 }
663
664 bool HasPrefix = false;
665 if (const auto *F = dyn_cast(GO)) {
666 if (std::optional Prefix = F->getSectionPrefix()) {
668 HasPrefix = true;
669 }
670 }
671
672 if (UniqueSectionName) {
673 Name.push_back('.');
674 TM.getNameWithPrefix(Name, GO, Mang, true);
675 } else if (HasPrefix)
676
677
678 Name.push_back('.');
680}
681
682namespace {
683class LoweringDiagnosticInfo : public DiagnosticInfo {
684 const Twine &Msg;
685
686public:
687 LoweringDiagnosticInfo(const Twine &DiagMsg,
691};
692}
693
694
695
696static unsigned
700 unsigned &EntrySize, unsigned &NextUniqueID,
701 const bool Retain, const bool ForceUnique) {
702
703
704
705 if (ForceUnique)
706 return NextUniqueID++;
707
708
709
710 const bool Associated = GO->getMetadata(LLVMContext::MD_associated);
711 if (Associated) {
713 return NextUniqueID++;
714 }
715
716 if (Retain) {
717 if (TM.getTargetTriple().isOSSolaris())
722 return NextUniqueID++;
723 }
724
725
726
727
728
729
730
733 if (!SupportsUnique) {
734 Flags &= ~ELF::SHF_MERGE;
735 EntrySize = 0;
737 }
738
740 const bool SeenSectionNameBefore =
742
743
744 if (!SymbolMergeable && !SeenSectionNameBefore) {
745 if (TM.getSeparateNamedSections())
746 return NextUniqueID++;
747 else
749 }
750
751
752
753
754 const auto PreviousID =
756 if (PreviousID && (!TM.getSeparateNamedSections() ||
758 return *PreviousID;
759
760
761
762
763
766 if (SymbolMergeable &&
768 SectionName.starts_with(ImplicitSectionNameStem))
770
771
772
773 return NextUniqueID++;
774}
775
776static std::tuple<StringRef, bool, unsigned>
779 bool IsComdat = false;
780 unsigned Flags = 0;
783 Group = C->getName();
784 IsComdat = C->getSelectionKind() == Comdat::Any;
785 }
786 if (TM.isLargeGlobalValue(GO))
788 return {Group, IsComdat, Flags};
789}
790
794 bool Retain, bool ForceUnique) {
796
797
798
799
800 const GlobalVariable *GV = dyn_cast(GO);
803 if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) {
804 SectionName = Attrs.getAttribute("bss-section").getValueAsString();
805 } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) {
806 SectionName = Attrs.getAttribute("rodata-section").getValueAsString();
807 } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) {
808 SectionName = Attrs.getAttribute("relro-section").getValueAsString();
809 } else if (Attrs.hasAttribute("data-section") && Kind.isData()) {
810 SectionName = Attrs.getAttribute("data-section").getValueAsString();
811 }
812 }
813
814
816
819 Flags |= ExtraFlags;
820
823 GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
824 Retain, ForceUnique);
825
829 Group, IsComdat, UniqueID, LinkedToSym);
830
831
832 assert(Section->getLinkedToSymbol() == LinkedToSym &&
833 "Associated symbol mismatch between sections");
834
837
838
839
843 "Symbol '" + GO->getName() + "' from module '" +
845 "' required a section with entry-size=" +
847 SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
848 ": Explicit assignment by pragma or attribute of an incompatible "
849 "symbol to this section?"));
850 }
851
852 return Section;
853}
854
858 NextUniqueID, Used.count(GO),
859 false);
860}
861
864 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
865 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
866
868 Flags |= ExtraFlags;
869
870
872
873 bool UniqueSectionName = false;
875 if (EmitUniqueSection) {
876 if (TM.getUniqueSectionNames()) {
877 UniqueSectionName = true;
878 } else {
879 UniqueID = *NextUniqueID;
880 (*NextUniqueID)++;
881 }
882 }
884 GO, Kind, Mang, TM, EntrySize, UniqueSectionName);
885
886
887 if (Kind.isExecuteOnly())
888 UniqueID = 0;
890 EntrySize, Group, IsComdat, UniqueID,
891 AssociatedSymbol);
892}
893
896 const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
897 unsigned Flags, unsigned *NextUniqueID) {
899 if (LinkedToSym) {
900 EmitUniqueSection = true;
902 }
903 if (Retain) {
904 if (TM.getTargetTriple().isOSSolaris()) {
905 EmitUniqueSection = true;
909 EmitUniqueSection = true;
911 }
912 }
913
915 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
916 NextUniqueID, LinkedToSym);
917 assert(Section->getLinkedToSymbol() == LinkedToSym);
918 return Section;
919}
920
924
925
926
927 bool EmitUniqueSection = false;
929 if (Kind.isText())
931 else
933 }
934 EmitUniqueSection |= GO->hasComdat();
936 Used.count(GO), EmitUniqueSection, Flags,
937 &NextUniqueID);
938}
939
944
945
946 if (F.hasSection())
949 Used.count(&F), true);
950 else
953 true, Flags, &NextUniqueID);
954}
955
958
959
960 const Comdat *C = F.getComdat();
962 if (!EmitUniqueSection)
964
968 nullptr);
969}
970
973
974
977
978 const auto *LSDA = cast(LSDASection);
979 unsigned Flags = LSDA->getFlags();
980 const MCSymbolELF *LinkedToSym = nullptr;
982 bool IsComdat = false;
985 Group = C->getName();
986 IsComdat = C->getSelectionKind() == Comdat::Any;
987 }
988
989
991 (getContext().getAsmInfo()->useIntegratedAssembler() &&
992 getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
994 LinkedToSym = cast(&FnSym);
995 }
996
997
998
1001 : LSDA->getName()),
1003 LinkedToSym);
1004}
1005
1007 bool UsesLabelDifference, const Function &F) const {
1008
1009
1010 return false;
1011}
1012
1013
1014
1017 Align &Alignment) const {
1026 if (Kind.isReadOnly())
1028
1029 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1031}
1032
1033
1039
1040
1041
1042
1043
1044
1047 if (FunctionSectionName == ".text" ||
1048 FunctionSectionName.starts_with(".text.")) {
1049
1053 Name += FunctionName;
1055 Name += ".text.eh.";
1056 Name += FunctionName;
1057 } else {
1058 Name += FunctionSectionName;
1060 if (.ends_with("."))
1061 Name += ".";
1063 } else {
1064 UniqueID = NextUniqueID++;
1065 }
1066 }
1067 } else {
1068
1069
1070 Name = FunctionSectionName;
1071 UniqueID = NextUniqueID++;
1072 }
1073
1075 std::string GroupName;
1076 if (F.hasComdat()) {
1078 GroupName = F.getComdat()->getName().str();
1079 }
1081 0 , GroupName,
1082 F.hasComdat(), UniqueID, nullptr);
1083}
1084
1086 bool IsCtor, unsigned Priority,
1088 std::string Name;
1089 unsigned Type;
1092
1093 if (KeySym)
1095
1096 if (UseInitArray) {
1097 if (IsCtor) {
1099 Name = ".init_array";
1100 } else {
1102 Name = ".fini_array";
1103 }
1104 if (Priority != 65535) {
1105 Name += '.';
1106 Name += utostr(Priority);
1107 }
1108 } else {
1109
1110
1111 if (IsCtor)
1112 Name = ".ctors";
1113 else
1114 Name = ".dtors";
1115 if (Priority != 65535)
1118 }
1119
1121}
1122
1124 unsigned Priority, const MCSymbol *KeySym) const {
1126 KeySym);
1127}
1128
1130 unsigned Priority, const MCSymbol *KeySym) const {
1132 KeySym);
1133}
1134
1138
1139
1140 if (->hasGlobalUnnamedAddr() ||
->getValueType()->isFunctionTy())
1141 return nullptr;
1142
1143
1146 RHS->isThreadLocal())
1147 return nullptr;
1148
1153}
1154
1158
1160
1161
1162 if (GV->isDSOLocal() || GV->isImplicitDSOLocal())
1164
1167}
1168
1170
1171
1172
1175}
1176
1177void
1179 UseInitArray = UseInitArray_;
1181 if (!UseInitArray) {
1184
1187 return;
1188 }
1189
1194}
1195
1196
1197
1198
1199
1202}
1203
1212 } else {
1219 }
1220
1226}
1227
1229 unsigned Priority, const MCSymbol *KeySym) const {
1231
1232
1233
1234
1235
1236}
1237
1240
1241 if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1242 for (const auto *Option : LinkerOptions->operands()) {
1244 for (const auto &Piece : cast(Option)->operands())
1245 StrOptions.push_back(std::string(cast(Piece)->getString()));
1247 }
1248 }
1249
1250 unsigned VersionVal = 0;
1251 unsigned ImageInfoFlags = 0;
1253
1254 GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1256
1257
1258 if (SectionVal.empty())
1259 return;
1260
1262 unsigned TAA = 0, StubSize = 0;
1263 bool TAAParsed;
1265 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1266
1268 "': " + toString(std::move(E)) + ".");
1269 }
1270
1271
1276 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1278 Streamer.emitInt32(ImageInfoFlags);
1280}
1281
1284 if ()
1285 return;
1286
1288 "' cannot be lowered.");
1289}
1290
1293
1295
1296 const GlobalVariable *GV = dyn_cast(GO);
1299 if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) {
1300 SectionName = Attrs.getAttribute("bss-section").getValueAsString();
1301 } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) {
1302 SectionName = Attrs.getAttribute("rodata-section").getValueAsString();
1303 } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) {
1304 SectionName = Attrs.getAttribute("relro-section").getValueAsString();
1305 } else if (Attrs.hasAttribute("data-section") && Kind.isData()) {
1306 SectionName = Attrs.getAttribute("data-section").getValueAsString();
1307 }
1308 }
1309
1310
1312 unsigned TAA = 0, StubSize = 0;
1313 bool TAAParsed;
1314
1316
1318 SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1319
1321 "' has an invalid section specifier '" +
1323 }
1324
1325
1328
1329
1330
1331 if (!TAAParsed)
1333
1334
1335
1336
1338
1340 "' section type or attributes does not match previous"
1341 " section specifier");
1342 }
1343
1344 return S;
1345}
1346
1350
1351
1354
1355 if (Kind.isText())
1357
1358
1359
1361 if (Kind.isReadOnly())
1363 if (Kind.isReadOnlyWithRel())
1366 }
1367
1368
1369 if (Kind.isMergeable1ByteCString() &&
1371 cast(GO)) < Align(32))
1373
1374
1375
1376
1379 cast(GO)) < Align(32))
1381
1382
1383
1385 if (Kind.isMergeableConst4())
1387 if (Kind.isMergeableConst8())
1389 if (Kind.isMergeableConst16())
1391 }
1392
1393
1394
1395 if (Kind.isReadOnly())
1397
1398
1399
1400 if (Kind.isReadOnlyWithRel())
1402
1403
1404
1405 if (Kind.isBSSExtern())
1407
1408
1409
1410 if (Kind.isBSSLocal())
1412
1413
1415}
1416
1419 Align &Alignment) const {
1420
1421
1422 if (Kind.isData() || Kind.isReadOnlyWithRel())
1424
1425 if (Kind.isMergeableConst4())
1427 if (Kind.isMergeableConst8())
1429 if (Kind.isMergeableConst16())
1432}
1433
1437}
1438
1442
1443
1447
1449
1450
1451
1456 }
1457
1461 }
1462
1464 MMI, Streamer);
1465}
1466
1470
1473
1475
1476
1477
1482 }
1483
1484 return SSym;
1485}
1486
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1530
1531
1532
1535
1536
1537
1539 StringRef Suffix = "$non_lazy_ptr";
1542 Name += Suffix;
1543 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1544
1546
1550
1551 const MCExpr *BSymExpr =
1555
1558
1562}
1563
1567 return true;
1568
1569
1570
1571
1572
1573 return false;
1574}
1575
1579 bool CannotUsePrivateLabel = true;
1583 CannotUsePrivateLabel =
1585 }
1587}
1588
1589
1590
1591
1592
1593static unsigned
1595 unsigned Flags = 0;
1597
1598 if (K.isMetadata())
1599 Flags |=
1601 else if (K.isExclude())
1602 Flags |=
1604 else if (K.isText())
1605 Flags |=
1610 else if (K.isBSS())
1611 Flags |=
1615 else if (K.isThreadLocal())
1616 Flags |=
1620 else if (K.isReadOnly() || K.isReadOnlyWithRel())
1621 Flags |=
1624 else if (K.isWriteable())
1625 Flags |=
1629
1630 return Flags;
1631}
1632
1635 assert(C && "expected GV to have a Comdat!");
1636
1637 StringRef ComdatGVName = C->getName();
1639 if (!ComdatGV)
1641 "' does not exist.");
1642
1645 "' is not a key for its COMDAT.");
1646
1647 return ComdatGV;
1648}
1649
1653 if (const auto *GA = dyn_cast(ComdatKey))
1655 if (ComdatKey == GV) {
1656 switch (C->getSelectionKind()) {
1667 }
1668 } else {
1670 }
1671 }
1672 return 0;
1673}
1674
1679 false) ||
1681 false) ||
1683 false) ||
1685 false))
1695 else
1696 ComdatGV = GO;
1697
1700 COMDATSymName = Sym->getName();
1702 } else {
1704 }
1705 }
1706
1709}
1710
1712 if (Kind.isText())
1713 return ".text";
1714 if (Kind.isBSS())
1715 return ".bss";
1716 if (Kind.isThreadLocal())
1717 return ".tls$";
1718 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1719 return ".rdata";
1720 return ".data";
1721}
1722
1725
1726
1727 bool EmitUniquedSection;
1728 if (Kind.isText())
1729 EmitUniquedSection = TM.getFunctionSections();
1730 else
1731 EmitUniquedSection = TM.getDataSections();
1732
1733 if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1735
1737
1745 else
1746 ComdatGV = GO;
1747
1749 if (EmitUniquedSection)
1750 UniqueID = NextUniqueID++;
1751
1755
1756 if (const auto *F = dyn_cast(GO))
1757 if (std::optional Prefix = F->getSectionPrefix())
1759
1760
1761
1762
1763 if (getContext().getTargetTriple().isWindowsGNUEnvironment())
1765
1768 } else {
1773 }
1774 }
1775
1776 if (Kind.isText())
1778
1779 if (Kind.isThreadLocal())
1781
1782 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1784
1785
1786
1787
1788 if (Kind.isBSS() || Kind.isCommon())
1790
1792}
1793
1797 bool CannotUsePrivateLabel = false;
1799 ((isa(GV) && TM.getFunctionSections()) ||
1800 (isa(GV) && TM.getDataSections())))
1801 CannotUsePrivateLabel = true;
1802
1804}
1805
1808
1809
1810 const Comdat *C = F.getComdat();
1811 bool EmitUniqueSection = TM.getFunctionSections() || C;
1812 if (!EmitUniqueSection)
1814
1815
1816 if (F.hasPrivateLinkage())
1818
1821
1826 unsigned UniqueID = NextUniqueID++;
1827
1830 UniqueID);
1831}
1832
1834 bool UsesLabelDifference, const Function &F) const {
1837
1838
1839 return false;
1840 }
1841 }
1843 UsesLabelDifference, F);
1844}
1845
1848 emitLinkerDirectives(Streamer, M);
1849
1851 unsigned Flags = 0;
1853
1855 if (!Section.empty()) {
1864 }
1865
1867}
1868
1869void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
1871 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1872
1873
1874
1877 for (const auto *Option : LinkerOptions->operands()) {
1878 for (const auto &Piece : cast(Option)->operands()) {
1879
1881 Directive.append(std::string(cast(Piece)->getString()));
1883 }
1884 }
1885 }
1886
1887
1888 std::string Flags;
1889 for (const GlobalValue &GV : M.global_values()) {
1894 if (.empty()) {
1897 }
1899 }
1900
1901
1902 if (const auto *LU = M.getNamedGlobal("llvm.used")) {
1903 assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
1904 assert(isa(LU->getValueType()) &&
1905 "expected llvm.used to be an array type");
1906 if (const auto *A = cast(LU->getInitializer())) {
1907 for (const Value *Op : A->operands()) {
1908 const auto *GV = cast(Op->stripPointerCasts());
1909
1910
1911
1912 if (GV->hasLocalLinkage())
1913 continue;
1914
1919
1920 if (.empty()) {
1923 }
1925 }
1926 }
1927 }
1928}
1929
1933 this->TM = &TM;
1934 const Triple &T = TM.getTargetTriple();
1935 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1942 } else {
1949 }
1950}
1951
1953 const Triple &T, bool IsCtor,
1954 unsigned Priority,
1957 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1958
1959 if (Priority == 65535)
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1973 char LastLetter = 'T';
1974 bool AddPrioritySuffix = Priority != 200 && Priority != 400;
1975 if (Priority < 200)
1976 LastLetter = 'A';
1977 else if (Priority < 400)
1978 LastLetter = 'C';
1979 else if (Priority == 400)
1980 LastLetter = 'L';
1982 OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;
1983 if (AddPrioritySuffix)
1984 OS << format("%05u", Priority);
1988 }
1989
1990 std::string Name = IsCtor ? ".ctors" : ".dtors";
1991 if (Priority != 65535)
1993
1998 KeySym, 0);
1999}
2000
2002 unsigned Priority, const MCSymbol *KeySym) const {
2006}
2007
2009 unsigned Priority, const MCSymbol *KeySym) const {
2013}
2014
2018 const Triple &T = TM.getTargetTriple();
2019 if (T.isOSCygMing())
2020 return nullptr;
2021
2022
2023
2026 return nullptr;
2027
2028
2029
2030
2031
2032
2033
2034
2035 if (!isa(LHS) || !isa(RHS) ||
2036 LHS->isThreadLocal() || RHS->isThreadLocal() ||
2037 RHS->getName() != "__ImageBase" || ->hasExternalLinkage() ||
2038 cast(RHS)->hasInitializer() || RHS->hasSection())
2039 return nullptr;
2040
2044}
2045
2047 unsigned Width = (AI.getBitWidth() / 8) * 2;
2048 std::string HexString = toString(AI, 16, false);
2050 unsigned Size = HexString.size();
2051 assert(Width >= Size && "hex string is too large!");
2052 HexString.insert(HexString.begin(), Width - Size, '0');
2053
2054 return HexString;
2055}
2056
2059 if (isa(C)) {
2061 } else if (const auto *CFP = dyn_cast(C)) {
2062 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2063 } else if (const auto *CI = dyn_cast(C)) {
2065 } else {
2066 unsigned NumElements;
2067 if (auto *VTy = dyn_cast(Ty))
2068 NumElements = cast(VTy)->getNumElements();
2069 else
2071 std::string HexString;
2072 for (int I = NumElements - 1, E = -1; I != E; --I)
2074 return HexString;
2075 }
2076}
2077
2080 Align &Alignment) const {
2081 if (Kind.isMergeableConst() && C &&
2082 getContext().getAsmInfo()->hasCOFFComdatConstants()) {
2083
2084
2085
2086
2090 std::string COMDATSymName;
2091 if (Kind.isMergeableConst4()) {
2092 if (Alignment <= 4) {
2094 Alignment = Align(4);
2095 }
2096 } else if (Kind.isMergeableConst8()) {
2097 if (Alignment <= 8) {
2099 Alignment = Align(8);
2100 }
2101 } else if (Kind.isMergeableConst16()) {
2102
2103 if (Alignment <= 16) {
2105 Alignment = Align(16);
2106 }
2107 } else if (Kind.isMergeableConst32()) {
2108 if (Alignment <= 32) {
2110 Alignment = Align(32);
2111 }
2112 }
2113
2114 if (!COMDATSymName.empty())
2116 COMDATSymName,
2118 }
2119
2121 Alignment);
2122}
2123
2124
2125
2126
2127
2130 if ()
2131 return nullptr;
2132
2135 "SelectionKind::Any, '" + C->getName() + "' cannot be "
2136 "lowered.");
2137
2138 return C;
2139}
2140
2142 unsigned Flags = 0;
2143
2144 if (K.isThreadLocal())
2146
2147 if (K.isMergeableCString())
2149
2150 if (Retain)
2152
2153
2154
2155 return Flags;
2156}
2157
2162 if (auto *GO = dyn_cast(GV))
2163 Used.insert(GO);
2164}
2165
2168
2169
2170 if (isa(GO)) {
2172 }
2173
2175
2176
2177
2178
2179
2180
2182 false) ||
2184 false) ||
2185 Name == ".llvmbc" || Name == ".llvmcmd")
2187
2190 Group = C->getName();
2191 }
2192
2196
2197 return Section;
2198}
2199
2203 const TargetMachine &TM, bool EmitUniqueSection,
2204 unsigned *NextUniqueID, bool Retain) {
2207 Group = C->getName();
2208 }
2209
2210 bool UniqueSectionNames = TM.getUniqueSectionNames();
2212
2213 if (const auto *F = dyn_cast(GO)) {
2214 const auto &OptionalPrefix = F->getSectionPrefix();
2215 if (OptionalPrefix)
2217 }
2218
2219 if (EmitUniqueSection && UniqueSectionNames) {
2220 Name.push_back('.');
2221 TM.getNameWithPrefix(Name, GO, Mang, true);
2222 }
2224 if (EmitUniqueSection && !UniqueSectionNames) {
2225 UniqueID = *NextUniqueID;
2226 (*NextUniqueID)++;
2227 }
2228
2231}
2232
2235
2236 if (Kind.isCommon())
2238
2239
2240
2241 bool EmitUniqueSection = false;
2242 if (Kind.isText())
2244 else
2246 EmitUniqueSection |= GO->hasComdat();
2247 bool Retain = Used.count(GO);
2248 EmitUniqueSection |= Retain;
2249
2251 EmitUniqueSection, &NextUniqueID, Retain);
2252}
2253
2255 bool UsesLabelDifference, const Function &F) const {
2256
2257
2258 return false;
2259}
2260
2264
2265
2266 if (->hasGlobalUnnamedAddr() ||
->getValueType()->isFunctionTy())
2267 return nullptr;
2268
2269
2272 RHS->isThreadLocal())
2273 return nullptr;
2274
2279}
2280
2284
2285
2286
2288}
2289
2291 unsigned Priority, const MCSymbol *KeySym) const {
2292 return Priority == UINT16_MAX ?
2296}
2297
2299 unsigned Priority, const MCSymbol *KeySym) const {
2300 report_fatal_error("@llvm.global_dtors should have been lowered already");
2301}
2302
2303
2304
2305
2309 return true;
2310
2312 if (.hasPersonalityFn() ||
.needsUnwindTableEntry())
2313 return false;
2314
2316 dyn_cast(F.getPersonalityFn()->stripPointerCasts());
2317 assert(Per && "Personality routine is not a GlobalValue type.");
2319 return false;
2320
2321 return true;
2322}
2323
2327 if (.hasStackProtectorFnAttr())
2328 return false;
2329
2330
2331
2332 return true;
2333}
2334
2339 cast(EHInfoSym)->setEHInfo();
2340 return EHInfoSym;
2341}
2342
2346
2347
2348
2349
2350
2351
2352
2353
2354 if (const GlobalObject *GO = dyn_cast(GV)) {
2355 if (GO->isDeclarationForLinker())
2357 ->getQualNameSymbol();
2358
2359 if (const GlobalVariable *GVar = dyn_cast(GV))
2360 if (GVar->hasAttribute("toc-data"))
2361 return cast(
2363 ->getQualNameSymbol();
2364
2366 if (GOKind.isText())
2367 return cast(
2369 ->getQualNameSymbol();
2370 if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2373 ->getQualNameSymbol();
2374 }
2375
2376
2377 return nullptr;
2378}
2379
2384
2386
2387
2388 if (const GlobalVariable *GVar = dyn_cast(GO))
2389 if (GVar->hasAttribute("toc-data"))
2393 true);
2394
2396 if (Kind.isText())
2398 else if (Kind.isData() || Kind.isBSS())
2400 else if (Kind.isReadOnlyWithRel())
2401 MappingClass =
2403 else if (Kind.isReadOnly())
2405 else
2406 report_fatal_error("XCOFF other section types not yet implemented.");
2407
2410 true);
2411}
2412
2416 "Tried to get ER section for a defined global.");
2417
2420
2421
2422
2428 }
2429
2434
2435 if (const GlobalVariable *GVar = dyn_cast(GO))
2436 if (GVar->hasAttribute("toc-data"))
2438
2439
2443}
2444
2447
2448 if (const GlobalVariable *GVar = dyn_cast(GO))
2449 if (GVar->hasAttribute("toc-data")) {
2456 true);
2457 }
2458
2459
2460
2461
2462
2463 if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2471 }
2472
2473 if (Kind.isText()) {
2476 ->getRepresentedCsect();
2477 }
2479 }
2480
2484 "ReadOnlyPointers is supported only if data sections is turned on");
2485
2491 }
2492
2493
2494
2495
2496
2497 if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2504 }
2506 }
2507
2508 if (Kind.isReadOnly()) {
2515 }
2517 }
2518
2519
2520
2521
2522
2523 if (Kind.isThreadLocal()) {
2529 }
2531 }
2532
2533 report_fatal_error("XCOFF other section types not yet implemented.");
2534}
2535
2538 assert (.getComdat() && "Comdat not supported on XCOFF.");
2539
2542
2543
2544
2550}
2551
2553 bool UsesLabelDifference, const Function &F) const {
2554 return false;
2555}
2556
2557
2558
2561 Align &Alignment) const {
2562
2563 if (Alignment > Align(16))
2564 report_fatal_error("Alignments greater than 16 not yet supported.");
2565
2566 if (Alignment == Align(8)) {
2569 }
2570
2571 if (Alignment == Align(16)) {
2574 }
2575
2577}
2578
2589
2590
2591
2592
2593
2594
2596}
2597
2599 unsigned Priority, const MCSymbol *KeySym) const {
2601}
2602
2604 unsigned Priority, const MCSymbol *KeySym) const {
2606}
2607
2611
2612 return nullptr;
2613}
2614
2617 assert(!isa(GV) && "GlobalIFunc is not supported on AIX.");
2618
2635 "There is no mapping that implements AppendingLinkage for XCOFF.");
2636 }
2638}
2639
2642 assert((isa(Func) ||
2643 (isa(Func) &&
2644 isa_and_nonnull(
2645 cast(Func)->getAliaseeObject()))) &&
2646 "Func must be a function or an alias which has a function as base "
2647 "object.");
2648
2652
2653
2654
2655
2656
2658 Func->isDeclarationForLinker()) &&
2659 isa(Func)) {
2667 }
2668
2670}
2671
2679}
2680
2686
2687
2688
2691
2692
2693
2694
2697
2698
2702
2707
2711}
2712
2715 auto *LSDA = cast(LSDASection);
2717
2718
2719
2723 LSDA->getCsectProp());
2724 }
2725 return LSDA;
2726}
2727
2728
2729
2731
2735}
2736
2739 std::string Name = ".gcc_exception_table." + F.getName().str();
2741}
2742
2746 if (Kind.isBSS())
2748 nullptr, 0);
2749
2751}
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static bool isThumb(const MCSubtargetInfo &STI)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
COFFYAML::WeakExternalCharacteristics Characteristics
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
static MCSection * selectExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID, bool Retain, bool ForceUnique)
static int getSelectionForCOFF(const GlobalValue *GV)
static MCSectionCOFF * getCOFFStaticStructorSection(MCContext &Ctx, const Triple &T, bool IsCtor, unsigned Priority, const MCSymbol *KeySym, MCSectionCOFF *Default)
static unsigned getEntrySizeForKind(SectionKind Kind)
static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags, StringRef &Section)
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
static unsigned getELFSectionType(StringRef Name, SectionKind K)
static bool hasPrefix(StringRef SectionName, StringRef Prefix)
static MCSectionWasm * selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID, bool Retain)
static const MCSymbolELF * getLinkedToSymbol(const GlobalObject *GO, const TargetMachine &TM)
static unsigned calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &Flags, unsigned &EntrySize, unsigned &NextUniqueID, const bool Retain, const bool ForceUnique)
Calculate an appropriate unique ID for a section, and update Flags, EntrySize and NextUniqueID where ...
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
static const Comdat * getWasmComdat(const GlobalValue *GV)
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
static unsigned getWasmSectionFlags(SectionKind K, bool Retain)
static void checkMachOComdat(const GlobalValue *GV)
static std::string APIntToHexString(const APInt &AI)
static cl::opt< bool > JumpTableInFunctionSection("jumptable-in-function-section", cl::Hidden, cl::init(false), cl::desc("Putting Jump Table in function section"))
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge)
Return the section prefix name used by options FunctionsSections and DataSections.
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol)
static SmallString< 128 > getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, unsigned EntrySize, bool UniqueSectionName)
static std::string scalarConstantToHexString(const Constant *C)
static StringRef getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
static const Comdat * getELFComdat(const GlobalValue *GV)
static std::tuple< StringRef, bool, unsigned > getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM)
static unsigned getELFSectionFlags(SectionKind K)
Class for arbitrary precision integers.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
This is an important base class in LLVM.
Wrapper for a function that represents a value that functionally represents the original function.
GlobalValue * getGlobalValue() const
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
StringRef getPrivateGlobalPrefix() const
This is the base abstract class for diagnostic reporting in the backend.
Interface for custom diagnostic printing.
Lightweight error class with error context and mandatory checking.
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool hasExternalLinkage() const
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
LinkageTypes getLinkage() const
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
const Comdat * getComdat() const
ThreadLocalMode getThreadLocalMode() const
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
const GlobalObject * getAliaseeObject() const
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
bool hasCommonLinkage() const
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
AttributeSet getAttributes() const
Return the attribute set for this global.
bool hasImplicitSection() const
Check if section name is present.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static bool isSectionAtomizableBySymbols(const MCSection &Section)
True if the section is atomized using the symbols in it.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
bool binutilsIsAtLeast(int Major, int Minor) const
ExceptionHandling getExceptionHandlingType() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID)
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, uint32_t Subsection=0)
bool isELFGenericMergeableSection(StringRef Name)
std::optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Return the unique ID of the section with the given name, flags and entry size, if it exists.
const MCAsmInfo * getAsmInfo() const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Base class for the full range of assembler expressions which are needed for parsing.
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * MergeableConst16Section
MCSection * MergeableConst4Section
MCSection * TextSection
Section directive for standard text.
MCSection * ConstDataCoalSection
MCSection * ConstTextCoalSection
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
MCSection * MergeableConst8Section
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCSection * ReadOnly16Section
MCSection * FourByteConstantSection
MCSection * ReadOnly8Section
MCSection * DataBSSSection
MCSection * getDrectveSection() const
MCSection * TextCoalSection
MCSection * DataRelROSection
MCSection * CStringSection
bool isPositionIndependent() const
MCSection * DataCoalSection
MCSection * UStringSection
MCSection * MergeableConst32Section
MCSection * SixteenByteConstantSection
MCSection * DataCommonSection
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
MCSection * BSSSection
Section that is default initialized to zero.
MCSection * EightByteConstantSection
MCSection * getTextSection() const
MCSection * ConstDataSection
MCContext & getContext() const
MCSection * DataSection
Section directive for standard data.
This represents a section on Windows.
This represents a section on linux, lots of unix variants and some bare metal systems.
This represents a section on a Mach-O system (used by Mac OS X).
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
unsigned getTypeAndAttributes() const
unsigned getStubSize() const
This represents a section on wasm.
MCSymbolXCOFF * getQualNameSymbol() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
static constexpr unsigned NonUniqueID
StringRef getName() const
Streaming machine code generation interface.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
void emitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void emitLinkerOptions(ArrayRef< std::string > Kind)
Emit the given list Options of strings as linker options into the output.
void emitInt64(uint64_t Value)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
void emitInt8(uint64_t Value)
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
StringRef getSymbolTableName() const
bool hasPerSymbolCodeModel() const
CodeModel getPerSymbolCodeModel() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
This represents an "assembler immediate".
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
const MDOperand & getOperand(unsigned I) const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isBeginSection() const
Returns true if this block begins any section.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
MCSection * getSection() const
Returns the Section this function belongs to.
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
This class contains meta information specific to a module.
const Module * getModule() const
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
A Module instance is used to store all the information related to an LLVM module.
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
const std::string & getSourceFileName() const
Get the module's original source file name.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
PointerIntPair - This class implements a pair of a pointer and small integer.
PointerTy getPointer() const
SectionKind - This is a simple POD value that classifies the properties of a section.
static SectionKind getThreadData()
static SectionKind getMetadata()
bool isThreadBSSLocal() const
static SectionKind getText()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getReadOnly()
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
TargetLoweringObjectFileELF()
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const override
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const override
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
virtual void emitPersonalityValueImpl(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
void InitializeELF(bool UseInitArray_)
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
TargetLoweringObjectFileGOFF()
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit the module flags that specify the garbage collection information.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
TargetLoweringObjectFileMachO()
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF)
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getSectionForTOCEntry(const MCSymbol *Sym, const TargetMachine &TM) const override
On targets that support TOC entries, return a section for the entry given the symbol it refers to.
MCSection * getSectionForExternalReference(const GlobalObject *GO, const TargetMachine &TM) const override
For external functions, this will always return a function descriptor csect.
MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const override
If supported, return the function entry point symbol.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
MCSection * getSectionForFunctionDescriptor(const Function *F, const TargetMachine &TM) const override
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
static bool ShouldEmitEHBlock(const MachineFunction *MF)
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
For functions, this will return the LSDA section.
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const
Emit Call Graph Profile metadata.
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
Mangler & getMangler() const
bool SupportIndirectSymViaGOTPCRel
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
bool SupportDebugThreadLocalLocation
bool supportDSOLocalEquivalentLowering() const
Target supports a native lowering of a dso_local_equivalent constant without needing to replace it wi...
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
unsigned getPersonalityEncoding() const
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
bool SupportDSOLocalEquivalentLowering
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
unsigned CallSiteEncoding
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
Primary interface to the complete machine description for the target machine.
const Triple & getTargetTriple() const
bool getUniqueBasicBlockSectionNames() const
Return true if unique basic block section names must be generated.
bool getUniqueSectionNames() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
MCSymbol * getSymbol(const GlobalValue *GV) const
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections.
CodeModel::Model getCodeModel() const
Returns the code model.
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
unsigned XCOFFReadOnlyPointers
When set to true, const objects with relocatable address values are put into the RO data section.
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
uint64_t getArrayNumElements() const
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVMContext & getContext() const
All values hold a context through their type.
StringRef getName() const
Return a constant reference to the value's name.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_ANY
@ C
The default llvm calling convention, compatible with C.
@ SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_LINKER_OPTIONS
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
StorageMappingClass
Storage Mapping Class definitions.
@ XMC_TE
Symbol mapped at the end of TOC.
@ XMC_DS
Descriptor csect.
@ XMC_TL
Initialized thread-local variable.
@ XMC_RO
Read Only Constant.
@ XMC_UA
Unclassified - Treated as Read Write.
@ XMC_TD
Scalar data item in the TOC.
@ XMC_UL
Uninitialized thread-local variable.
@ XMC_BS
BSS class (uninitialized static internal)
@ XMC_TC
General TOC item.
@ XTY_CM
Common csect definition. For uninitialized storage.
@ XTY_SD
Csect definition for initialized storage.
@ XTY_ER
External reference.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
std::string encodeBase64(InputBytes const &Bytes)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
const char * toString(DWARFSectionKind Kind)
cl::opt< std::string > BBSectionsColdTextPrefix
@ Default
The result values are uniform if and only if all operands are uniform.
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_Hidden
.hidden (ELF)
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
constexpr const char * PseudoProbeDescMetadataName
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
static const MBBSectionID ExceptionSectionID
static const MBBSectionID ColdSectionID