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

310

311 if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {

314

316

317 for (const auto *Operand : DependentLibraries->operands()) {

319 cast(cast(Operand)->getOperand(0))->getString());

321 }

322 }

323

325

326

327

328

329

330

331 for (const auto *Operand : FuncInfo->operands()) {

332 const auto *MD = cast(Operand);

333 auto *GUID = mdconst::dyn_extract(MD->getOperand(0));

334 auto *Hash = mdconst::dyn_extract(MD->getOperand(1));

335 auto *Name = cast(MD->getOperand(2));

336 auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(

338

340 Streamer.emitInt64(GUID->getZExtValue());

341 Streamer.emitInt64(Hash->getZExtValue());

344 }

345 }

346

347 if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {

348

349

350 auto *S = C.getObjectFileInfo()->getLLVMStatsSection();

352 for (const auto *Operand : LLVMStats->operands()) {

353 const auto *MD = cast(Operand);

354 assert(MD->getNumOperands() % 2 == 0 &&

355 ("Operand num should be even for a list of key/value pair"));

356 for (size_t I = 0; I < MD->getNumOperands(); I += 2) {

357

358 auto *Key = cast(MD->getOperand(I));

360 Streamer.emitBytes(Key->getString());

361

363 Twine(mdconst::dyn_extract(MD->getOperand(I + 1))

364 ->getZExtValue())

368 }

369 }

370 }

371

373 unsigned Flags = 0;

375

377 if (!Section.empty()) {

384 }

385

387}

388

392 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {

395

397

398 for (const auto *Operand : LinkerOptions->operands()) {

399 if (cast(Operand)->getNumOperands() != 2)

401 for (const auto &Option : cast(Operand)->operands()) {

402 Streamer.emitBytes(cast(Option)->getString());

404 }

405 }

406 }

407}

408

419}

420

425 NameData += Sym->getName();

427 cast(getContext().getOrCreateSymbol(NameData));

433 unsigned Size = DL.getPointerSize();

440

442}

443

448}

449

455

457

458

459

464 }

465

469 }

470

472 MMI, Streamer);

473}

474

476

477

478

479

480

481

482

484 false) ||

486 false) ||

488 false) ||

490 false) ||

491 Name == ".llvmbc" || Name == ".llvmcmd")

493

494 if (Name.starts_with(".")) return K;

495

496

497 if (Name == ".bss" || Name.starts_with(".bss.") ||

498 Name.starts_with(".gnu.linkonce.b.") ||

499 Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||

500 Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||

501 Name.starts_with(".llvm.linkonce.sb."))

503

504 if (Name == ".tdata" || Name.starts_with(".tdata.") ||

505 Name.starts_with(".gnu.linkonce.td.") ||

506 Name.starts_with(".llvm.linkonce.td."))

508

509 if (Name == ".tbss" || Name.starts_with(".tbss.") ||

510 Name.starts_with(".gnu.linkonce.tb.") ||

511 Name.starts_with(".llvm.linkonce.tb."))

513

514 return K;

515}

516

518 return SectionName.consume_front(Prefix) &&

520}

521

523

524

525

526 if (Name.starts_with(".note"))

528

531

534

537

540 if (Name == ".llvm.lto")

542

543 if (K.isBSS() || K.isThreadBSS())

545

547}

548

550 unsigned Flags = 0;

551

552 if (!K.isMetadata() && !K.isExclude())

554

555 if (K.isExclude())

557

558 if (K.isText())

560

561 if (K.isExecuteOnly())

563

564 if (K.isWriteable())

566

567 if (K.isThreadLocal())

569

570 if (K.isMergeableCString() || K.isMergeableConst())

572

573 if (K.isMergeableCString())

575

576 return Flags;

577}

578

581 if (C)

582 return nullptr;

583

586 report_fatal_error("ELF COMDATs only support SelectionKind::Any and "

587 "SelectionKind::NoDeduplicate, '" +

588 C->getName() + "' cannot be lowered.");

589

590 return C;

591}

592

596 if (!MD)

597 return nullptr;

598

599 auto *VM = cast(MD->getOperand(0).get());

600 auto *OtherGV = dyn_cast(VM->getValue());

601 return OtherGV ? dyn_cast(TM.getSymbol(OtherGV)) : nullptr;

602}

603

605 if (Kind.isMergeable1ByteCString())

606 return 1;

607 else if (Kind.isMergeable2ByteCString())

608 return 2;

609 else if (Kind.isMergeable4ByteCString())

610 return 4;

611 else if (Kind.isMergeableConst4())

612 return 4;

613 else if (Kind.isMergeableConst8())

614 return 8;

615 else if (Kind.isMergeableConst16())

616 return 16;

617 else if (Kind.isMergeableConst32())

618 return 32;

619 else {

620

621

622 assert(!Kind.isMergeableCString() && "unknown string width");

623 assert(!Kind.isMergeableConst() && "unknown data width");

624 return 0;

625 }

626}

627

628

629

631 if (Kind.isText())

632 return IsLarge ? ".ltext" : ".text";

633 if (Kind.isReadOnly())

634 return IsLarge ? ".lrodata" : ".rodata";

635 if (Kind.isBSS())

636 return IsLarge ? ".lbss" : ".bss";

637 if (Kind.isThreadData())

638 return ".tdata";

639 if (Kind.isThreadBSS())

640 return ".tbss";

641 if (Kind.isData())

642 return IsLarge ? ".ldata" : ".data";

643 if (Kind.isReadOnlyWithRel())

644 return IsLarge ? ".ldata.rel.ro" : ".data.rel.ro";

646}

647

651 unsigned EntrySize, bool UniqueSectionName) {

654 if (Kind.isMergeableCString()) {

655

656

657

659 cast(GO));

660

661 Name += ".str";

662 Name += utostr(EntrySize);

664 Name += utostr(Alignment.value());

665 } else if (Kind.isMergeableConst()) {

666 Name += ".cst";

667 Name += utostr(EntrySize);

668 }

669

670 bool HasPrefix = false;

671 if (const auto *F = dyn_cast(GO)) {

672 if (std::optional Prefix = F->getSectionPrefix()) {

674 HasPrefix = true;

675 }

676 }

677

678 if (UniqueSectionName) {

679 Name.push_back('.');

680 TM.getNameWithPrefix(Name, GO, Mang, true);

681 } else if (HasPrefix)

682

683

684 Name.push_back('.');

686}

687

688namespace {

689class LoweringDiagnosticInfo : public DiagnosticInfo {

690 const Twine &Msg;

691

692public:

693 LoweringDiagnosticInfo(const Twine &DiagMsg,

697};

698}

699

700

701

702static unsigned

706 unsigned &EntrySize, unsigned &NextUniqueID,

707 const bool Retain, const bool ForceUnique) {

708

709

710

711 if (ForceUnique)

712 return NextUniqueID++;

713

714

715

716 const bool Associated = GO->getMetadata(LLVMContext::MD_associated);

717 if (Associated) {

719 return NextUniqueID++;

720 }

721

722 if (Retain) {

723 if (TM.getTargetTriple().isOSSolaris())

728 return NextUniqueID++;

729 }

730

731

732

733

734

735

736

739 if (!SupportsUnique) {

740 Flags &= ~ELF::SHF_MERGE;

741 EntrySize = 0;

743 }

744

746 const bool SeenSectionNameBefore =

748

749

750 if (!SymbolMergeable && !SeenSectionNameBefore) {

751 if (TM.getSeparateNamedSections())

752 return NextUniqueID++;

753 else

755 }

756

757

758

759

760 const auto PreviousID =

762 if (PreviousID && (!TM.getSeparateNamedSections() ||

764 return *PreviousID;

765

766

767

768

769

772 if (SymbolMergeable &&

774 SectionName.starts_with(ImplicitSectionNameStem))

776

777

778

779 return NextUniqueID++;

780}

781

782static std::tuple<StringRef, bool, unsigned>

785 bool IsComdat = false;

786 unsigned Flags = 0;

789 Group = C->getName();

790 IsComdat = C->getSelectionKind() == Comdat::Any;

791 }

792 if (TM.isLargeGlobalValue(GO))

794 return {Group, IsComdat, Flags};

795}

796

799

800

801

802 const GlobalVariable *GV = dyn_cast(GO);

805 if (Attrs.hasAttribute("bss-section") && Kind.isBSS())

806 return Attrs.getAttribute("bss-section").getValueAsString();

807 else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())

808 return Attrs.getAttribute("rodata-section").getValueAsString();

809 else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel())

810 return Attrs.getAttribute("relro-section").getValueAsString();

811 else if (Attrs.hasAttribute("data-section") && Kind.isData())

812 return Attrs.getAttribute("data-section").getValueAsString();

813 }

814

816}

817

822 unsigned &NextUniqueID,

823 bool Retain, bool ForceUnique) {

825

826

828

831 Flags |= ExtraFlags;

832

835 GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,

836 Retain, ForceUnique);

837

841 Group, IsComdat, UniqueID, LinkedToSym);

842

843

844 assert(Section->getLinkedToSymbol() == LinkedToSym &&

845 "Associated symbol mismatch between sections");

846

849

850

851

855 "Symbol '" + GO->getName() + "' from module '" +

857 "' required a section with entry-size=" +

859 SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +

860 ": Explicit assignment by pragma or attribute of an incompatible "

861 "symbol to this section?"));

862 }

863

864 return Section;

865}

866

870 NextUniqueID, Used.count(GO),

871 false);

872}

873

876 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,

877 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {

878

880 Flags |= ExtraFlags;

881

882

884

885 bool UniqueSectionName = false;

887 if (EmitUniqueSection) {

888 if (TM.getUniqueSectionNames()) {

889 UniqueSectionName = true;

890 } else {

891 UniqueID = *NextUniqueID;

892 (*NextUniqueID)++;

893 }

894 }

896 GO, Kind, Mang, TM, EntrySize, UniqueSectionName);

897

898

899 if (Kind.isExecuteOnly())

900 UniqueID = 0;

902 EntrySize, Group, IsComdat, UniqueID,

903 AssociatedSymbol);

904}

905

908 const TargetMachine &TM, bool Retain, bool EmitUniqueSection,

909 unsigned Flags, unsigned *NextUniqueID) {

911 if (LinkedToSym) {

912 EmitUniqueSection = true;

914 }

915 if (Retain) {

916 if (TM.getTargetTriple().isOSSolaris()) {

917 EmitUniqueSection = true;

921 EmitUniqueSection = true;

923 }

924 }

925

927 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,

928 NextUniqueID, LinkedToSym);

929 assert(Section->getLinkedToSymbol() == LinkedToSym);

930 return Section;

931}

932

936

937

938

939 bool EmitUniqueSection = false;

941 if (Kind.isText())

943 else

945 }

946 EmitUniqueSection |= GO->hasComdat();

948 Used.count(GO), EmitUniqueSection, Flags,

949 &NextUniqueID);

950}

951

956

957

958 if (F.hasSection())

961 Used.count(&F), true);

962 else

965 true, Flags, &NextUniqueID);

966}

967

970

971

972 const Comdat *C = F.getComdat();

974 if (!EmitUniqueSection)

976

980 nullptr);

981}

982

985

986

989

990 const auto *LSDA = cast(LSDASection);

991 unsigned Flags = LSDA->getFlags();

992 const MCSymbolELF *LinkedToSym = nullptr;

994 bool IsComdat = false;

997 Group = C->getName();

998 IsComdat = C->getSelectionKind() == Comdat::Any;

999 }

1000

1001

1003 (getContext().getAsmInfo()->useIntegratedAssembler() &&

1004 getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {

1006 LinkedToSym = cast(&FnSym);

1007 }

1008

1009

1010

1013 : LSDA->getName()),

1015 LinkedToSym);

1016}

1017

1019 bool UsesLabelDifference, const Function &F) const {

1020

1021

1022 return false;

1023}

1024

1025

1026

1029 Align &Alignment) const {

1038 if (Kind.isReadOnly())

1040

1041 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");

1043}

1044

1045

1051

1052

1053

1054

1055

1056

1059 if (FunctionSectionName == ".text" ||

1060 FunctionSectionName.starts_with(".text.")) {

1061

1065 Name += FunctionName;

1067 Name += ".text.eh.";

1068 Name += FunctionName;

1069 } else {

1070 Name += FunctionSectionName;

1072 if (Name.ends_with("."))

1073 Name += ".";

1075 } else {

1076 UniqueID = NextUniqueID++;

1077 }

1078 }

1079 } else {

1080

1081

1082 Name = FunctionSectionName;

1083 UniqueID = NextUniqueID++;

1084 }

1085

1087 std::string GroupName;

1088 if (F.hasComdat()) {

1090 GroupName = F.getComdat()->getName().str();

1091 }

1093 0 , GroupName,

1094 F.hasComdat(), UniqueID, nullptr);

1095}

1096

1098 bool IsCtor, unsigned Priority,

1100 std::string Name;

1101 unsigned Type;

1104

1105 if (KeySym)

1107

1108 if (UseInitArray) {

1109 if (IsCtor) {

1111 Name = ".init_array";

1112 } else {

1114 Name = ".fini_array";

1115 }

1116 if (Priority != 65535) {

1117 Name += '.';

1118 Name += utostr(Priority);

1119 }

1120 } else {

1121

1122

1123 if (IsCtor)

1124 Name = ".ctors";

1125 else

1126 Name = ".dtors";

1127 if (Priority != 65535)

1130 }

1131

1133}

1134

1136 unsigned Priority, const MCSymbol *KeySym) const {

1138 KeySym);

1139}

1140

1142 unsigned Priority, const MCSymbol *KeySym) const {

1144 KeySym);

1145}

1146

1150

1151

1152 if (LHS->hasGlobalUnnamedAddr() || LHS->getValueType()->isFunctionTy())

1153 return nullptr;

1154

1155

1158 RHS->isThreadLocal())

1159 return nullptr;

1160

1165}

1166

1170

1172

1173

1174 if (GV->isDSOLocal() || GV->isImplicitDSOLocal())

1176

1179}

1180

1182

1183

1184

1187}

1188

1189void

1191 UseInitArray = UseInitArray_;

1193 if (!UseInitArray) {

1196

1199 return;

1200 }

1201

1206}

1207

1208

1209

1210

1211

1214}

1215

1224 } else {

1231 }

1232

1238}

1239

1241 unsigned Priority, const MCSymbol *KeySym) const {

1243

1244

1245

1246

1247

1248}

1249

1252

1254

1255 unsigned VersionVal = 0;

1256 unsigned ImageInfoFlags = 0;

1258

1259 GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);

1261

1262

1263 if (SectionVal.empty())

1264 return;

1265

1267 unsigned TAA = 0, StubSize = 0;

1268 bool TAAParsed;

1270 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {

1271

1273 "': " + toString(std::move(E)) + ".");

1274 }

1275

1276

1281 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));

1283 Streamer.emitInt32(ImageInfoFlags);

1285}

1286

1289 if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {

1290 for (const auto *Option : LinkerOptions->operands()) {

1292 for (const auto &Piece : cast(Option)->operands())

1293 StrOptions.push_back(std::string(cast(Piece)->getString()));

1295 }

1296 }

1297}

1298

1301 if (C)

1302 return;

1303

1305 "' cannot be lowered.");

1306}

1307

1310

1312

1313

1315 unsigned TAA = 0, StubSize = 0;

1316 bool TAAParsed;

1317

1319

1321 SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {

1322

1324 "' has an invalid section specifier '" +

1326 }

1327

1328

1331

1332

1333

1334 if (!TAAParsed)

1336

1337

1338

1339

1341

1343 "' section type or attributes does not match previous"

1344 " section specifier");

1345 }

1346

1347 return S;

1348}

1349

1353

1354

1357

1358 if (Kind.isText())

1360

1361

1362

1364 if (Kind.isReadOnly())

1366 if (Kind.isReadOnlyWithRel())

1369 }

1370

1371

1372 if (Kind.isMergeable1ByteCString() &&

1374 cast(GO)) < Align(32))

1376

1377

1378

1379

1382 cast(GO)) < Align(32))

1384

1385

1386

1388 if (Kind.isMergeableConst4())

1390 if (Kind.isMergeableConst8())

1392 if (Kind.isMergeableConst16())

1394 }

1395

1396

1397

1398 if (Kind.isReadOnly())

1400

1401

1402

1403 if (Kind.isReadOnlyWithRel())

1405

1406

1407

1408 if (Kind.isBSSExtern())

1410

1411

1412

1413 if (Kind.isBSSLocal())

1415

1416

1418}

1419

1422 Align &Alignment) const {

1423

1424

1425 if (Kind.isData() || Kind.isReadOnlyWithRel())

1427

1428 if (Kind.isMergeableConst4())

1430 if (Kind.isMergeableConst8())

1432 if (Kind.isMergeableConst16())

1435}

1436

1440}

1441

1445

1446

1450

1452

1453

1454

1459 }

1460

1464 }

1465

1467 MMI, Streamer);

1468}

1469

1473

1476

1478

1479

1480

1485 }

1486

1487 return SSym;

1488}

1489

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

1527

1528

1529

1533

1534

1535

1538

1539

1540

1542 StringRef Suffix = "$non_lazy_ptr";

1545 Name += Suffix;

1546 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);

1547

1549

1553

1554 const MCExpr *BSymExpr =

1558

1561

1565}

1566

1570 return true;

1571

1572

1573

1574

1575

1576 return false;

1577}

1578

1582 bool CannotUsePrivateLabel = true;

1586 CannotUsePrivateLabel =

1588 }

1590}

1591

1592

1593

1594

1595

1596static unsigned

1598 unsigned Flags = 0;

1600

1601 if (K.isMetadata())

1602 Flags |=

1604 else if (K.isExclude())

1605 Flags |=

1607 else if (K.isText())

1608 Flags |=

1613 else if (K.isBSS())

1614 Flags |=

1618 else if (K.isThreadLocal())

1619 Flags |=

1623 else if (K.isReadOnly() || K.isReadOnlyWithRel())

1624 Flags |=

1627 else if (K.isWriteable())

1628 Flags |=

1632

1633 return Flags;

1634}

1635

1638 assert(C && "expected GV to have a Comdat!");

1639

1640 StringRef ComdatGVName = C->getName();

1642 if (!ComdatGV)

1644 "' does not exist.");

1645

1648 "' is not a key for its COMDAT.");

1649

1650 return ComdatGV;

1651}

1652

1656 if (const auto *GA = dyn_cast(ComdatKey))

1658 if (ComdatKey == GV) {

1659 switch (C->getSelectionKind()) {

1670 }

1671 } else {

1673 }

1674 }

1675 return 0;

1676}

1677

1682 false) ||

1684 false) ||

1686 false) ||

1688 false))

1698 else

1699 ComdatGV = GO;

1700

1703 COMDATSymName = Sym->getName();

1705 } else {

1707 }

1708 }

1709

1712}

1713

1715 if (Kind.isText())

1716 return ".text";

1717 if (Kind.isBSS())

1718 return ".bss";

1719 if (Kind.isThreadLocal())

1720 return ".tls$";

1721 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())

1722 return ".rdata";

1723 return ".data";

1724}

1725

1728

1729

1730 bool EmitUniquedSection;

1731 if (Kind.isText())

1732 EmitUniquedSection = TM.getFunctionSections();

1733 else

1734 EmitUniquedSection = TM.getDataSections();

1735

1736 if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {

1738

1740

1748 else

1749 ComdatGV = GO;

1750

1752 if (EmitUniquedSection)

1753 UniqueID = NextUniqueID++;

1754

1758

1759 if (const auto *F = dyn_cast(GO))

1760 if (std::optional Prefix = F->getSectionPrefix())

1762

1763

1764

1765

1766 if (getContext().getTargetTriple().isWindowsGNUEnvironment())

1768

1771 } else {

1776 }

1777 }

1778

1779 if (Kind.isText())

1781

1782 if (Kind.isThreadLocal())

1784

1785 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())

1787

1788

1789

1790

1791 if (Kind.isBSS() || Kind.isCommon())

1793

1795}

1796

1800 bool CannotUsePrivateLabel = false;

1802 ((isa(GV) && TM.getFunctionSections()) ||

1803 (isa(GV) && TM.getDataSections())))

1804 CannotUsePrivateLabel = true;

1805

1807}

1808

1811

1812

1813 const Comdat *C = F.getComdat();

1814 bool EmitUniqueSection = TM.getFunctionSections() || C;

1815 if (!EmitUniqueSection)

1817

1818

1819 if (F.hasPrivateLinkage())

1821

1824

1829 unsigned UniqueID = NextUniqueID++;

1830

1833 UniqueID);

1834}

1835

1837 bool UsesLabelDifference, const Function &F) const {

1840

1841

1842 return false;

1843 }

1844 }

1846 UsesLabelDifference, F);

1847}

1848

1852

1854 unsigned Flags = 0;

1856

1858 if (!Section.empty()) {

1867 }

1868

1870}

1871

1874 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {

1875

1876

1877

1880 for (const auto *Option : LinkerOptions->operands()) {

1881 for (const auto &Piece : cast(Option)->operands()) {

1882

1884 Directive.append(std::string(cast(Piece)->getString()));

1886 }

1887 }

1888 }

1889

1890

1891 std::string Flags;

1892 for (const GlobalValue &GV : M.global_values()) {

1897 if (!Flags.empty()) {

1900 }

1901 Flags.clear();

1902 }

1903

1904

1905 if (const auto *LU = M.getNamedGlobal("llvm.used")) {

1906 assert(LU->hasInitializer() && "expected llvm.used to have an initializer");

1907 assert(isa(LU->getValueType()) &&

1908 "expected llvm.used to be an array type");

1909 if (const auto *A = cast(LU->getInitializer())) {

1910 for (const Value *Op : A->operands()) {

1911 const auto *GV = cast(Op->stripPointerCasts());

1912

1913

1914

1915 if (GV->hasLocalLinkage())

1916 continue;

1917

1922

1923 if (!Flags.empty()) {

1926 }

1927 Flags.clear();

1928 }

1929 }

1930 }

1931}

1932

1936 this->TM = &TM;

1937 const Triple &T = TM.getTargetTriple();

1938 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {

1945 } else {

1952 }

1953}

1954

1956 const Triple &T, bool IsCtor,

1957 unsigned Priority,

1960 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {

1961

1962 if (Priority == 65535)

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1976 char LastLetter = 'T';

1977 bool AddPrioritySuffix = Priority != 200 && Priority != 400;

1978 if (Priority < 200)

1979 LastLetter = 'A';

1980 else if (Priority < 400)

1981 LastLetter = 'C';

1982 else if (Priority == 400)

1983 LastLetter = 'L';

1985 OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;

1986 if (AddPrioritySuffix)

1987 OS << format("%05u", Priority);

1991 }

1992

1993 std::string Name = IsCtor ? ".ctors" : ".dtors";

1994 if (Priority != 65535)

1996

2001 KeySym, 0);

2002}

2003

2005 unsigned Priority, const MCSymbol *KeySym) const {

2009}

2010

2012 unsigned Priority, const MCSymbol *KeySym) const {

2016}

2017

2021 const Triple &T = TM.getTargetTriple();

2022 if (T.isOSCygMing())

2023 return nullptr;

2024

2025

2026

2029 return nullptr;

2030

2031

2032

2033

2034

2035

2036

2037

2038 if (!isa(LHS) || !isa(RHS) ||

2039 LHS->isThreadLocal() || RHS->isThreadLocal() ||

2040 RHS->getName() != "__ImageBase" || RHS->hasExternalLinkage() ||

2041 cast(RHS)->hasInitializer() || RHS->hasSection())

2042 return nullptr;

2043

2047}

2048

2050 unsigned Width = (AI.getBitWidth() / 8) * 2;

2051 std::string HexString = toString(AI, 16, false);

2053 unsigned Size = HexString.size();

2054 assert(Width >= Size && "hex string is too large!");

2055 HexString.insert(HexString.begin(), Width - Size, '0');

2056

2057 return HexString;

2058}

2059

2061 Type *Ty = C->getType();

2062 if (isa(C)) {

2064 } else if (const auto *CFP = dyn_cast(C)) {

2065 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());

2066 } else if (const auto *CI = dyn_cast(C)) {

2068 } else {

2069 unsigned NumElements;

2070 if (auto *VTy = dyn_cast(Ty))

2071 NumElements = cast(VTy)->getNumElements();

2072 else

2074 std::string HexString;

2075 for (int I = NumElements - 1, E = -1; I != E; --I)

2077 return HexString;

2078 }

2079}

2080

2083 Align &Alignment) const {

2084 if (Kind.isMergeableConst() && C &&

2085 getContext().getAsmInfo()->hasCOFFComdatConstants()) {

2086

2087

2088

2089

2093 std::string COMDATSymName;

2094 if (Kind.isMergeableConst4()) {

2095 if (Alignment <= 4) {

2097 Alignment = Align(4);

2098 }

2099 } else if (Kind.isMergeableConst8()) {

2100 if (Alignment <= 8) {

2102 Alignment = Align(8);

2103 }

2104 } else if (Kind.isMergeableConst16()) {

2105

2106 if (Alignment <= 16) {

2108 Alignment = Align(16);

2109 }

2110 } else if (Kind.isMergeableConst32()) {

2111 if (Alignment <= 32) {

2113 Alignment = Align(32);

2114 }

2115 }

2116

2117 if (!COMDATSymName.empty())

2119 COMDATSymName,

2121 }

2122

2124 Alignment);

2125}

2126

2127

2128

2129

2130

2133 if (C)

2134 return nullptr;

2135

2138 "SelectionKind::Any, '" + C->getName() + "' cannot be "

2139 "lowered.");

2140

2141 return C;

2142}

2143

2145 unsigned Flags = 0;

2146

2147 if (K.isThreadLocal())

2149

2150 if (K.isMergeableCString())

2152

2153 if (Retain)

2155

2156

2157

2158 return Flags;

2159}

2160

2165 if (auto *GO = dyn_cast(GV))

2166 Used.insert(GO);

2167}

2168

2171

2172

2173 if (isa(GO)) {

2175 }

2176

2178

2179

2180

2181

2182

2183

2185 false) ||

2187 false) ||

2188 Name == ".llvmbc" || Name == ".llvmcmd")

2190

2193 Group = C->getName();

2194 }

2195

2199

2200 return Section;

2201}

2202

2206 const TargetMachine &TM, bool EmitUniqueSection,

2207 unsigned *NextUniqueID, bool Retain) {

2210 Group = C->getName();

2211 }

2212

2213 bool UniqueSectionNames = TM.getUniqueSectionNames();

2215

2216 if (const auto *F = dyn_cast(GO)) {

2217 const auto &OptionalPrefix = F->getSectionPrefix();

2218 if (OptionalPrefix)

2220 }

2221

2222 if (EmitUniqueSection && UniqueSectionNames) {

2223 Name.push_back('.');

2224 TM.getNameWithPrefix(Name, GO, Mang, true);

2225 }

2227 if (EmitUniqueSection && !UniqueSectionNames) {

2228 UniqueID = *NextUniqueID;

2229 (*NextUniqueID)++;

2230 }

2231

2234}

2235

2238

2239 if (Kind.isCommon())

2241

2242

2243

2244 bool EmitUniqueSection = false;

2245 if (Kind.isText())

2247 else

2249 EmitUniqueSection |= GO->hasComdat();

2250 bool Retain = Used.count(GO);

2251 EmitUniqueSection |= Retain;

2252

2254 EmitUniqueSection, &NextUniqueID, Retain);

2255}

2256

2258 bool UsesLabelDifference, const Function &F) const {

2259

2260

2261 return false;

2262}

2263

2267

2268

2269 if (LHS->hasGlobalUnnamedAddr() || LHS->getValueType()->isFunctionTy())

2270 return nullptr;

2271

2272

2275 RHS->isThreadLocal())

2276 return nullptr;

2277

2282}

2283

2287

2288

2289

2291}

2292

2294 unsigned Priority, const MCSymbol *KeySym) const {

2295 return Priority == UINT16_MAX ?

2299}

2300

2302 unsigned Priority, const MCSymbol *KeySym) const {

2303 report_fatal_error("@llvm.global_dtors should have been lowered already");

2304}

2305

2306

2307

2308

2312 return true;

2313

2315 if (F.hasPersonalityFn() || F.needsUnwindTableEntry())

2316 return false;

2317

2319 dyn_cast(F.getPersonalityFn()->stripPointerCasts());

2320 assert(Per && "Personality routine is not a GlobalValue type.");

2322 return false;

2323

2324 return true;

2325}

2326

2330 if (F.hasStackProtectorFnAttr())

2331 return false;

2332

2333

2334

2335 return true;

2336}

2337

2342 cast(EHInfoSym)->setEHInfo();

2343 return EHInfoSym;

2344}

2345

2349

2350

2351

2352

2353

2354

2355

2356

2357 if (const GlobalObject *GO = dyn_cast(GV)) {

2358 if (GO->isDeclarationForLinker())

2360 ->getQualNameSymbol();

2361

2362 if (const GlobalVariable *GVar = dyn_cast(GV))

2363 if (GVar->hasAttribute("toc-data"))

2364 return cast(

2366 ->getQualNameSymbol();

2367

2369 if (GOKind.isText())

2370 return cast(

2372 ->getQualNameSymbol();

2373 if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||

2376 ->getQualNameSymbol();

2377 }

2378

2379

2380 return nullptr;

2381}

2382

2387

2389

2390

2391 if (const GlobalVariable *GVar = dyn_cast(GO))

2392 if (GVar->hasAttribute("toc-data"))

2396 true);

2397

2399 if (Kind.isText())

2401 else if (Kind.isData() || Kind.isBSS())

2403 else if (Kind.isReadOnlyWithRel())

2404 MappingClass =

2406 else if (Kind.isReadOnly())

2408 else

2409 report_fatal_error("XCOFF other section types not yet implemented.");

2410

2413 true);

2414}

2415

2419 "Tried to get ER section for a defined global.");

2420

2423

2424

2425

2431 }

2432

2437

2438 if (const GlobalVariable *GVar = dyn_cast(GO))

2439 if (GVar->hasAttribute("toc-data"))

2441

2442

2446}

2447

2450

2451 if (const GlobalVariable *GVar = dyn_cast(GO))

2452 if (GVar->hasAttribute("toc-data")) {

2459 true);

2460 }

2461

2462

2463

2464

2465

2466 if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {

2474 }

2475

2476 if (Kind.isText()) {

2479 ->getRepresentedCsect();

2480 }

2482 }

2483

2487 "ReadOnlyPointers is supported only if data sections is turned on");

2488

2494 }

2495

2496

2497

2498

2499

2500 if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {

2507 }

2509 }

2510

2511 if (Kind.isReadOnly()) {

2518 }

2520 }

2521

2522

2523

2524

2525

2526 if (Kind.isThreadLocal()) {

2532 }

2534 }

2535

2536 report_fatal_error("XCOFF other section types not yet implemented.");

2537}

2538

2541 assert (F.getComdat() && "Comdat not supported on XCOFF.");

2542

2545

2546

2547

2553}

2554

2556 bool UsesLabelDifference, const Function &F) const {

2557 return false;

2558}

2559

2560

2561

2564 Align &Alignment) const {

2565

2566 if (Alignment > Align(16))

2567 report_fatal_error("Alignments greater than 16 not yet supported.");

2568

2569 if (Alignment == Align(8)) {

2572 }

2573

2574 if (Alignment == Align(16)) {

2577 }

2578

2580}

2581

2592

2593

2594

2595

2596

2597

2599}

2600

2602 unsigned Priority, const MCSymbol *KeySym) const {

2604}

2605

2607 unsigned Priority, const MCSymbol *KeySym) const {

2609}

2610

2614

2615 return nullptr;

2616}

2617

2620 assert(!isa(GV) && "GlobalIFunc is not supported on AIX.");

2621

2638 "There is no mapping that implements AppendingLinkage for XCOFF.");

2639 }

2641}

2642

2645 assert((isa(Func) ||

2646 (isa(Func) &&

2647 isa_and_nonnull(

2648 cast(Func)->getAliaseeObject()))) &&

2649 "Func must be a function or an alias which has a function as base "

2650 "object.");

2651

2655

2656

2657

2658

2659

2661 Func->isDeclarationForLinker()) &&

2662 isa(Func)) {

2670 }

2671

2673}

2674

2682}

2683

2689

2690

2691

2694

2695

2696

2697

2700

2701

2705

2710

2714}

2715

2718 auto *LSDA = cast(LSDASection);

2720

2721

2722

2726 LSDA->getCsectProp());

2727 }

2728 return LSDA;

2729}

2730

2731

2732

2734

2738}

2739

2742 std::string Name = ".gcc_exception_table." + F.getName().str();

2744}

2745

2749 if (Kind.isBSS())

2751 nullptr, 0);

2752

2754}

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 StringRef handlePragmaClangSection(const GlobalObject *GO, SectionKind Kind)

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

void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override

Process linker options metadata and emit platform-specific bits.

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.

void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override

Process linker options metadata and emit platform-specific bits.

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

void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override

Process linker options metadata and emit platform-specific bits.

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