LLVM 23.0.0git
TargetLoweringObjectFileImpl.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/TargetLoweringObjectFileImpl.cpp - Object File Info ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements classes used to handle lowerings specific to common
10// object file formats.
11//
12//===----------------------------------------------------------------------===//
13
18#include "llvm/ADT/StringRef.h"
31#include "llvm/IR/Comdat.h"
32#include "llvm/IR/Constants.h"
33#include "llvm/IR/DataLayout.h"
37#include "llvm/IR/Function.h"
38#include "llvm/IR/GlobalAlias.h"
40#include "llvm/IR/GlobalValue.h"
42#include "llvm/IR/Mangler.h"
43#include "llvm/IR/Metadata.h"
44#include "llvm/IR/Module.h"
45#include "llvm/IR/Type.h"
46#include "llvm/MC/MCAsmInfo.h"
48#include "llvm/MC/MCContext.h"
49#include "llvm/MC/MCExpr.h"
57#include "llvm/MC/MCStreamer.h"
58#include "llvm/MC/MCSymbol.h"
59#include "llvm/MC/MCSymbolELF.h"
61#include "llvm/MC/MCValue.h"
62#include "llvm/MC/SectionKind.h"
64#include "llvm/Support/Base64.h"
68#include "llvm/Support/Format.h"
69#include "llvm/Support/Path.h"
73#include <cassert>
74#include <string>
75
76using namespace llvm;
77using namespace dwarf;
78
80 "jumptable-in-function-section", cl::Hidden, cl::init(false),
81 cl::desc("Putting Jump Table in function section"));
82
83static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
84 StringRef &Section) {
86 M.getModuleFlagsMetadata(ModuleFlags);
87
88 for (const auto &MFE: ModuleFlags) {
89 // Ignore flags with 'Require' behaviour.
90 if (MFE.Behavior == Module::Require)
91 continue;
92
93 StringRef Key = MFE.Key->getString();
94 if (Key == "Objective-C Image Info Version") {
95 Version = mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
96 } else if (Key == "Objective-C Garbage Collection" ||
97 Key == "Objective-C GC Only" ||
98 Key == "Objective-C Is Simulated" ||
99 Key == "Objective-C Class Properties" ||
100 Key == "Objective-C Image Swift Version") {
101 Flags |= mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
102 } else if (Key == "Objective-C Image Info Section") {
103 Section = cast<MDString>(MFE.Val)->getString();
104 }
105 // Backend generates L_OBJC_IMAGE_INFO from Swift ABI version + major + minor +
106 // "Objective-C Garbage Collection".
107 else if (Key == "Swift ABI Version") {
108 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 8;
109 } else if (Key == "Swift Major Version") {
110 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 24;
111 } else if (Key == "Swift Minor Version") {
112 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 16;
113 }
114 }
115}
116
117//===----------------------------------------------------------------------===//
118// ELF
119//===----------------------------------------------------------------------===//
120
122 const TargetMachine &TgtM) {
124
125 CodeModel::Model CM = TgtM.getCodeModel();
127
128 switch (TgtM.getTargetTriple().getArch()) {
129 case Triple::arm:
130 case Triple::armeb:
131 case Triple::thumb:
132 case Triple::thumbeb:
133 if (Ctx.getAsmInfo().getExceptionHandlingType() == ExceptionHandling::ARM)
134 break;
135 // Fallthrough if not using EHABI
136 [[fallthrough]];
137 case Triple::ppc:
138 case Triple::ppcle:
139 case Triple::x86:
152 break;
153 case Triple::x86_64:
154 if (isPositionIndependent()) {
156 ((CM == CodeModel::Small || CM == CodeModel::Medium)
159 (CM == CodeModel::Small
162 ((CM == CodeModel::Small || CM == CodeModel::Medium)
164 } else {
166 (CM == CodeModel::Small || CM == CodeModel::Medium)
172 }
173 break;
174 case Triple::hexagon:
178 if (isPositionIndependent()) {
182 }
183 break;
184 case Triple::aarch64:
187 // The small model guarantees static code/data size < 4GB, but not where it
188 // will be in memory. Most of these could end up >2GB away so even a signed
189 // pc-relative 32-bit address is insufficient, theoretically.
190 //
191 // Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
193 (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32
198 break;
199 case Triple::lanai:
203 break;
204 case Triple::mips:
205 case Triple::mipsel:
206 case Triple::mips64:
207 case Triple::mips64el:
208 // MIPS uses indirect pointer to refer personality functions and types, so
209 // that the eh_frame section can be read-only. DW.ref.personality will be
210 // generated for relocation.
212 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
213 // identify N64 from just a triple.
216
217 // FreeBSD must be explicit about the data size and using pcrel since it's
218 // assembler/linker won't do the automatic conversion that the Linux tools
219 // do.
223 }
224 break;
225 case Triple::ppc64:
226 case Triple::ppc64le:
232 break;
233 case Triple::sparcel:
234 case Triple::sparc:
235 if (isPositionIndependent()) {
241 } else {
245 }
247 break;
248 case Triple::riscv32:
249 case Triple::riscv64:
258 break;
259 case Triple::sparcv9:
261 if (isPositionIndependent()) {
266 } else {
269 }
270 break;
271 case Triple::systemz:
272 // All currently-defined code models guarantee that 4-byte PC-relative
273 // values will be in range.
274 if (isPositionIndependent()) {
280 } else {
284 }
285 break;
293 break;
294 default:
295 break;
296 }
297}
298
301 collectUsedGlobalVariables(M, Vec, false);
302 for (GlobalValue *GV : Vec)
303 if (auto *GO = dyn_cast<GlobalObject>(GV))
304 Used.insert(GO);
305}
306
308 Module &M) const {
309 auto &C = getContext();
310
311 emitLinkerDirectives(Streamer, M);
312
313 if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
314 auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
316
317 Streamer.switchSection(S);
318
319 for (const auto *Operand : DependentLibraries->operands()) {
320 Streamer.emitBytes(
321 cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
322 Streamer.emitInt8(0);
323 }
324 }
325
326 emitPseudoProbeDescMetadata(Streamer, M);
327
328 if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
329 // Emit the metadata for llvm statistics into .llvm_stats section, which is
330 // formatted as a list of key/value pair, the value is base64 encoded.
331 auto *S = C.getObjectFileInfo()->getLLVMStatsSection();
332 Streamer.switchSection(S);
333 for (const auto *Operand : LLVMStats->operands()) {
334 const auto *MD = cast<MDNode>(Operand);
335 assert(MD->getNumOperands() % 2 == 0 &&
336 ("Operand num should be even for a list of key/value pair"));
337 for (size_t I = 0; I < MD->getNumOperands(); I += 2) {
338 // Encode the key string size.
339 auto *Key = cast<MDString>(MD->getOperand(I));
340 Streamer.emitULEB128IntValue(Key->getString().size());
341 Streamer.emitBytes(Key->getString());
342 // Encode the value into a Base64 string.
343 std::string Value = encodeBase64(
344 Twine(mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1))
345 ->getZExtValue())
346 .str());
347 Streamer.emitULEB128IntValue(Value.size());
348 Streamer.emitBytes(Value);
349 }
350 }
351 }
352
353 unsigned Version = 0;
354 unsigned Flags = 0;
355 StringRef Section;
356
357 GetObjCImageInfo(M, Version, Flags, Section);
358 if (!Section.empty()) {
359 auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
360 Streamer.switchSection(S);
361 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
362 Streamer.emitInt32(Version);
363 Streamer.emitInt32(Flags);
364 Streamer.addBlankLine();
365 }
366
367 emitCGProfileMetadata(Streamer, M);
368}
369
371 Module &M) const {
372 auto &C = getContext();
373 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
374 auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS,
376
377 Streamer.switchSection(S);
378
379 for (const auto *Operand : LinkerOptions->operands()) {
380 if (cast<MDNode>(Operand)->getNumOperands() != 2)
381 report_fatal_error("invalid llvm.linker.options");
382 for (const auto &Option : cast<MDNode>(Operand)->operands()) {
383 Streamer.emitBytes(cast<MDString>(Option)->getString());
384 Streamer.emitInt8(0);
385 }
386 }
387 }
388}
389
391 const GlobalValue *GV, const TargetMachine &TM,
392 MachineModuleInfo *MMI) const {
393 unsigned Encoding = getPersonalityEncoding();
394 if ((Encoding & 0x80) == DW_EH_PE_indirect)
395 return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
396 TM.getSymbol(GV)->getName());
397 if ((Encoding & 0x70) == DW_EH_PE_absptr)
398 return TM.getSymbol(GV);
399 report_fatal_error("We do not support this DWARF encoding yet!");
400}
401
403 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
404 const MachineModuleInfo *MMI) const {
405 SmallString<64> NameData("DW.ref.");
406 NameData += Sym->getName();
407 auto *Label =
408 static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(NameData));
409 Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
410 Streamer.emitSymbolAttribute(Label, MCSA_Weak);
411 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
412 MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
413 ELF::SHT_PROGBITS, Flags, 0);
414 unsigned Size = DL.getPointerSize();
415 Streamer.switchSection(Sec);
416 Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0));
419 Streamer.emitELFSize(Label, E);
420 Streamer.emitLabel(Label);
421
422 emitPersonalityValueImpl(Streamer, DL, Sym, MMI);
423}
424
426 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
427 const MachineModuleInfo *MMI) const {
428 Streamer.emitSymbolValue(Sym, DL.getPointerSize());
429}
430
432 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
433 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
434 if (Encoding & DW_EH_PE_indirect) {
436
437 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
438
439 // Add information about the stub reference to ELFMMI so that the stub
440 // gets emitted by the asmprinter.
442 if (!StubSym.getPointer()) {
443 MCSymbol *Sym = TM.getSymbol(GV);
445 }
446
449 Encoding & ~DW_EH_PE_indirect, Streamer);
450 }
451
453 MMI, Streamer);
454}
455
457 // N.B.: The defaults used in here are not the same ones used in MC.
458 // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
459 // both gas and MC will produce a section with no flags. Given
460 // section(".eh_frame") gcc will produce:
461 //
462 // .section .eh_frame,"a",@progbits
463
464 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
465 /*AddSegmentInfo=*/false) ||
466 Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
467 /*AddSegmentInfo=*/false) ||
468 Name == getInstrProfSectionName(IPSK_covdata, Triple::ELF,
469 /*AddSegmentInfo=*/false) ||
470 Name == getInstrProfSectionName(IPSK_covname, Triple::ELF,
471 /*AddSegmentInfo=*/false) ||
472 Name == ".llvmbc" || Name == ".llvmcmd")
474
475 if (!Name.starts_with(".")) return K;
476
477 // Default implementation based on some magic section names.
478 if (Name == ".bss" || Name.starts_with(".bss.") ||
479 Name.starts_with(".gnu.linkonce.b.") ||
480 Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
481 Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||
482 Name.starts_with(".llvm.linkonce.sb."))
483 return SectionKind::getBSS();
484
485 if (Name == ".tdata" || Name.starts_with(".tdata.") ||
486 Name.starts_with(".gnu.linkonce.td.") ||
487 Name.starts_with(".llvm.linkonce.td."))
489
490 if (Name == ".tbss" || Name.starts_with(".tbss.") ||
491 Name.starts_with(".gnu.linkonce.tb.") ||
492 Name.starts_with(".llvm.linkonce.tb."))
494
495 return K;
496}
497
499 return SectionName.consume_front(Prefix) &&
500 (SectionName.empty() || SectionName[0] == '.');
501}
502
503static unsigned getELFSectionType(StringRef Name, SectionKind K) {
504 // Use SHT_NOTE for section whose name starts with ".note" to allow
505 // emitting ELF notes from C variable declaration.
506 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
507 if (Name.starts_with(".note"))
508 return ELF::SHT_NOTE;
509
510 if (hasPrefix(Name, ".init_array"))
511 return ELF::SHT_INIT_ARRAY;
512
513 if (hasPrefix(Name, ".fini_array"))
514 return ELF::SHT_FINI_ARRAY;
515
516 if (hasPrefix(Name, ".preinit_array"))
518
519 if (hasPrefix(Name, ".llvm.offloading"))
521 if (Name == ".llvm.lto")
522 return ELF::SHT_LLVM_LTO;
523
524 if (K.isBSS() || K.isThreadBSS())
525 return ELF::SHT_NOBITS;
526
527 return ELF::SHT_PROGBITS;
528}
529
530static unsigned getELFSectionFlags(SectionKind K, const Triple &T) {
531 unsigned Flags = 0;
532
533 if (!K.isMetadata() && !K.isExclude())
534 Flags |= ELF::SHF_ALLOC;
535
536 if (K.isExclude())
537 Flags |= ELF::SHF_EXCLUDE;
538
539 if (K.isText())
540 Flags |= ELF::SHF_EXECINSTR;
541
542 if (K.isExecuteOnly()) {
543 if (T.isAArch64())
545 else if (T.isARM() || T.isThumb())
546 Flags |= ELF::SHF_ARM_PURECODE;
547 }
548
549 if (K.isWriteable())
550 Flags |= ELF::SHF_WRITE;
551
552 if (K.isThreadLocal())
553 Flags |= ELF::SHF_TLS;
554
555 if (K.isMergeableCString() || K.isMergeableConst())
556 Flags |= ELF::SHF_MERGE;
557
558 if (K.isMergeableCString())
559 Flags |= ELF::SHF_STRINGS;
560
561 return Flags;
562}
563
564static const Comdat *getELFComdat(const GlobalValue *GV) {
565 const Comdat *C = GV->getComdat();
566 if (!C)
567 return nullptr;
568
569 if (C->getSelectionKind() != Comdat::Any &&
570 C->getSelectionKind() != Comdat::NoDeduplicate)
571 report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
572 "SelectionKind::NoDeduplicate, '" +
573 C->getName() + "' cannot be lowered.");
574
575 return C;
576}
577
579 const TargetMachine &TM) {
580 MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
581 if (!MD)
582 return nullptr;
583
584 auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
585 auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
586 return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV))
587 : nullptr;
588}
589
590static unsigned getEntrySizeForKind(SectionKind Kind) {
591 if (Kind.isMergeable1ByteCString())
592 return 1;
593 else if (Kind.isMergeable2ByteCString())
594 return 2;
595 else if (Kind.isMergeable4ByteCString())
596 return 4;
597 else if (Kind.isMergeableConst4())
598 return 4;
599 else if (Kind.isMergeableConst8())
600 return 8;
601 else if (Kind.isMergeableConst16())
602 return 16;
603 else if (Kind.isMergeableConst32())
604 return 32;
605 else {
606 // We shouldn't have mergeable C strings or mergeable constants that we
607 // didn't handle above.
608 assert(!Kind.isMergeableCString() && "unknown string width");
609 assert(!Kind.isMergeableConst() && "unknown data width");
610 return 0;
611 }
612}
613
614/// Return the section prefix name used by options FunctionsSections and
615/// DataSections.
617 if (Kind.isText())
618 return IsLarge ? ".ltext" : ".text";
619 if (Kind.isReadOnly())
620 return IsLarge ? ".lrodata" : ".rodata";
621 if (Kind.isBSS())
622 return IsLarge ? ".lbss" : ".bss";
623 if (Kind.isThreadData())
624 return ".tdata";
625 if (Kind.isThreadBSS())
626 return ".tbss";
627 if (Kind.isData())
628 return IsLarge ? ".ldata" : ".data";
629 if (Kind.isReadOnlyWithRel())
630 return IsLarge ? ".ldata.rel.ro" : ".data.rel.ro";
631 llvm_unreachable("Unknown section kind");
632}
633
634static SmallString<128>
636 Mangler &Mang, const TargetMachine &TM,
637 bool UniqueSectionName,
638 const MachineJumpTableEntry *JTE) {
639 SmallString<128> Name =
641 unsigned EntrySize = getEntrySizeForKind(Kind);
642 if (Kind.isMergeableCString()) {
643 // We also need alignment here.
644 // FIXME: this is getting the alignment of the character, not the
645 // alignment of the global!
646 Align Alignment = GO->getDataLayout().getPreferredAlign(
648
649 Name += ".str";
650 Name += utostr(EntrySize);
651 Name += ".";
652 Name += utostr(Alignment.value());
653 } else if (Kind.isMergeableConst()) {
654 Name += ".cst";
655 Name += utostr(EntrySize);
656 }
657
658 bool HasPrefix = false;
659 if (const auto *F = dyn_cast<Function>(GO)) {
660 // Jump table hotness takes precedence over its enclosing function's hotness
661 // if it's known. The function's section prefix is used if jump table entry
662 // hotness is unknown.
663 if (JTE && JTE->Hotness != MachineFunctionDataHotness::Unknown) {
665 raw_svector_ostream(Name) << ".hot";
666 } else {
668 "Hotness must be cold");
669 raw_svector_ostream(Name) << ".unlikely";
670 }
671 HasPrefix = true;
672 } else if (std::optional<StringRef> Prefix = F->getSectionPrefix()) {
673 raw_svector_ostream(Name) << '.' << *Prefix;
674 HasPrefix = true;
675 }
676 } else if (const auto *GV = dyn_cast<GlobalVariable>(GO)) {
677 if (std::optional<StringRef> Prefix = GV->getSectionPrefix()) {
678 raw_svector_ostream(Name) << '.' << *Prefix;
679 HasPrefix = true;
680 }
681 }
682
683 if (UniqueSectionName) {
684 Name.push_back('.');
685 TM.getNameWithPrefix(Name, GO, Mang, /*MayAlwaysUsePrivate*/true);
686 } else if (HasPrefix)
687 // For distinguishing between .text.${text-section-prefix}. (with trailing
688 // dot) and .text.${function-name}
689 Name.push_back('.');
690 return Name;
691}
692
693namespace {
694class LoweringDiagnosticInfo : public DiagnosticInfo {
695 const Twine &Msg;
696
697public:
698 LoweringDiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND,
699 DiagnosticSeverity Severity = DS_Error)
700 : DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
701 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
702};
703}
704
705/// Calculate an appropriate unique ID for a section, and update Flags,
706/// EntrySize and NextUniqueID where appropriate.
707static unsigned
709 SectionKind Kind, const TargetMachine &TM,
710 MCContext &Ctx, Mangler &Mang, unsigned &Flags,
711 unsigned &EntrySize, unsigned &NextUniqueID,
712 const bool Retain, const bool ForceUnique) {
713 // Increment uniqueID if we are forced to emit a unique section.
714 // This works perfectly fine with section attribute or pragma section as the
715 // sections with the same name are grouped together by the assembler.
716 if (ForceUnique)
717 return NextUniqueID++;
718
719 // A section can have at most one associated section. Put each global with
720 // MD_associated in a unique section.
721 const bool Associated = GO->getMetadata(LLVMContext::MD_associated);
722 if (Associated) {
723 Flags |= ELF::SHF_LINK_ORDER;
724 return NextUniqueID++;
725 }
726
727 if (Retain) {
728 if (TM.getTargetTriple().isOSSolaris())
730 else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
731 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36))
732 Flags |= ELF::SHF_GNU_RETAIN;
733 return NextUniqueID++;
734 }
735
736 // If two symbols with differing sizes end up in the same mergeable section
737 // that section can be assigned an incorrect entry size. To avoid this we
738 // usually put symbols of the same size into distinct mergeable sections with
739 // the same name. Doing so relies on the ",unique ," assembly feature. This
740 // feature is not available until binutils version 2.35
741 // (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
742 const bool SupportsUnique = Ctx.getAsmInfo().useIntegratedAssembler() ||
743 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35);
744 if (!SupportsUnique) {
745 Flags &= ~ELF::SHF_MERGE;
746 EntrySize = 0;
748 }
749
750 const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
751 const bool SeenSectionNameBefore =
752 Ctx.isELFGenericMergeableSection(SectionName);
753 // If this is the first occurrence of this section name, treat it as the
754 // generic section
755 if (!SymbolMergeable && !SeenSectionNameBefore) {
757 return NextUniqueID++;
758 else
760 }
761
762 // Symbols must be placed into sections with compatible entry sizes. Generate
763 // unique sections for symbols that have not been assigned to compatible
764 // sections.
765 const auto PreviousID =
766 Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
767 if (PreviousID &&
768 (!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
769 return *PreviousID;
770
771 // If the user has specified the same section name as would be created
772 // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
773 // to unique the section as the entry size for this symbol will be
774 // compatible with implicitly created sections.
775 SmallString<128> ImplicitSectionNameStem =
776 getELFSectionNameForGlobal(GO, Kind, Mang, TM, false, /*MJTE=*/nullptr);
777 if (SymbolMergeable &&
778 Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
779 SectionName.starts_with(ImplicitSectionNameStem))
781
782 // We have seen this section name before, but with different flags or entity
783 // size. Create a new unique ID.
784 return NextUniqueID++;
785}
786
787static std::tuple<StringRef, bool, unsigned, unsigned, unsigned>
790 StringRef Group = "";
791 bool IsComdat = false;
792 unsigned Flags = 0;
793 if (const Comdat *C = getELFComdat(GO)) {
794 Flags |= ELF::SHF_GROUP;
795 Group = C->getName();
796 IsComdat = C->getSelectionKind() == Comdat::Any;
797 }
798 if (TM.isLargeGlobalValue(GO))
799 Flags |= ELF::SHF_X86_64_LARGE;
800
801 unsigned Type, EntrySize;
802 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_elf_section_properties)) {
803 Type = cast<ConstantAsMetadata>(MD->getOperand(0))
804 ->getValue()
805 ->getUniqueInteger()
806 .getZExtValue();
807 EntrySize = cast<ConstantAsMetadata>(MD->getOperand(1))
808 ->getValue()
809 ->getUniqueInteger()
810 .getZExtValue();
811 } else {
813 EntrySize = getEntrySizeForKind(Kind);
814 }
815
816 return {Group, IsComdat, Flags, Type, EntrySize};
817}
818
820 SectionKind Kind) {
821 // Check if '#pragma clang section' name is applicable.
822 // Note that pragma directive overrides -ffunction-section, -fdata-section
823 // and so section name is exactly as user specified and not uniqued.
825 if (GV && GV->hasImplicitSection()) {
826 auto Attrs = GV->getAttributes();
827 if (Attrs.hasAttribute("bss-section") && Kind.isBSS())
828 return Attrs.getAttribute("bss-section").getValueAsString();
829 else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())
830 return Attrs.getAttribute("rodata-section").getValueAsString();
831 else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel())
832 return Attrs.getAttribute("relro-section").getValueAsString();
833 else if (Attrs.hasAttribute("data-section") && Kind.isData())
834 return Attrs.getAttribute("data-section").getValueAsString();
835 }
836
837 return GO->getSection();
838}
839
841 SectionKind Kind,
842 const TargetMachine &TM,
843 MCContext &Ctx, Mangler &Mang,
844 unsigned &NextUniqueID,
845 bool Retain, bool ForceUnique) {
847
848 // Infer section flags from the section name if we can.
850
851 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
852 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
853 getGlobalObjectInfo(GO, TM, SectionName, Kind);
854 Flags |= ExtraFlags;
855
857 GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
858 Retain, ForceUnique);
859
860 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
861 MCSectionELF *Section =
862 Ctx.getELFSection(SectionName, Type, Flags, EntrySize, Group, IsComdat,
863 UniqueID, LinkedToSym);
864 // Make sure that we did not get some other section with incompatible sh_link.
865 // This should not be possible due to UniqueID code above.
866 assert(Section->getLinkedToSymbol() == LinkedToSym &&
867 "Associated symbol mismatch between sections");
868
869 if (!(Ctx.getAsmInfo().useIntegratedAssembler() ||
870 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35))) {
871 // If we are using GNU as before 2.35, then this symbol might have
872 // been placed in an incompatible mergeable section. Emit an error if this
873 // is the case to avoid creating broken output.
874 if ((Section->getFlags() & ELF::SHF_MERGE) &&
875 (Section->getEntrySize() != getEntrySizeForKind(Kind)))
876 GO->getContext().diagnose(LoweringDiagnosticInfo(
877 "Symbol '" + GO->getName() + "' from module '" +
878 (GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
879 "' required a section with entry-size=" +
880 Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
881 SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
882 ": Explicit assignment by pragma or attribute of an incompatible "
883 "symbol to this section?"));
884 }
885
886 return Section;
887}
888
890 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
892 NextUniqueID, Used.count(GO),
893 /* ForceUnique = */false);
894}
895
897 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
898 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
899 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol,
900 const MachineJumpTableEntry *MJTE = nullptr) {
901 bool UniqueSectionName = false;
903 if (EmitUniqueSection) {
904 if (TM.getUniqueSectionNames()) {
905 UniqueSectionName = true;
906 } else {
907 UniqueID = *NextUniqueID;
908 (*NextUniqueID)++;
909 }
910 }
911 SmallString<128> Name =
912 getELFSectionNameForGlobal(GO, Kind, Mang, TM, UniqueSectionName, MJTE);
913
914 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
915 getGlobalObjectInfo(GO, TM, Name, Kind);
916 Flags |= ExtraFlags;
917
918 // Use 0 as the unique ID for execute-only text.
919 if (Kind.isExecuteOnly())
920 UniqueID = 0;
921 return Ctx.getELFSection(Name, Type, Flags, EntrySize, Group, IsComdat,
922 UniqueID, AssociatedSymbol);
923}
924
926 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
927 const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
928 unsigned Flags, unsigned *NextUniqueID) {
929 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
930 if (LinkedToSym) {
931 EmitUniqueSection = true;
932 Flags |= ELF::SHF_LINK_ORDER;
933 }
934 if (Retain) {
935 if (TM.getTargetTriple().isOSSolaris()) {
936 EmitUniqueSection = true;
938 } else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
939 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36)) {
940 EmitUniqueSection = true;
941 Flags |= ELF::SHF_GNU_RETAIN;
942 }
943 }
944 if (GO->hasMetadata(LLVMContext::MD_elf_section_properties))
945 EmitUniqueSection = true;
946
948 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
949 NextUniqueID, LinkedToSym);
950 assert(Section->getLinkedToSymbol() == LinkedToSym);
951 return Section;
952}
953
955 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
956 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
957
958 // If we have -ffunction-section or -fdata-section then we should emit the
959 // global value to a uniqued section specifically for it.
960 bool EmitUniqueSection = false;
961 if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
962 if (Kind.isText())
963 EmitUniqueSection = TM.getFunctionSections();
964 else
965 EmitUniqueSection = TM.getDataSections();
966 }
967 EmitUniqueSection |= GO->hasComdat();
968 return selectELFSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
969 Used.count(GO), EmitUniqueSection, Flags,
970 &NextUniqueID);
971}
972
974 const Function &F, const TargetMachine &TM) const {
976 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
977 // If the function's section names is pre-determined via pragma or a
978 // section attribute, call selectExplicitSectionGlobal.
979 if (F.hasSection())
981 &F, Kind, TM, getContext(), getMangler(), NextUniqueID,
982 Used.count(&F), /* ForceUnique = */true);
983
985 getContext(), &F, Kind, getMangler(), TM, Used.count(&F),
986 /*EmitUniqueSection=*/true, Flags, &NextUniqueID);
987}
988
993
995 const Function &F, const TargetMachine &TM,
996 const MachineJumpTableEntry *JTE) const {
997 // If the function can be removed, produce a unique section so that
998 // the table doesn't prevent the removal.
999 const Comdat *C = F.getComdat();
1000 bool EmitUniqueSection = TM.getFunctionSections() || C;
1001 if (!EmitUniqueSection && !TM.getEnableStaticDataPartitioning())
1002 return ReadOnlySection;
1003
1005 getMangler(), TM, EmitUniqueSection,
1006 ELF::SHF_ALLOC, &NextUniqueID,
1007 /* AssociatedSymbol */ nullptr, JTE);
1008}
1009
1011 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
1012 // If neither COMDAT nor function sections, use the monolithic LSDA section.
1013 // Re-use this path if LSDASection is null as in the Arm EHABI.
1014 if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
1015 return LSDASection;
1016
1017 const auto *LSDA = static_cast<const MCSectionELF *>(LSDASection);
1018 unsigned Flags = LSDA->getFlags();
1019 const MCSymbolELF *LinkedToSym = nullptr;
1020 StringRef Group;
1021 bool IsComdat = false;
1022 if (const Comdat *C = getELFComdat(&F)) {
1023 Flags |= ELF::SHF_GROUP;
1024 Group = C->getName();
1025 IsComdat = C->getSelectionKind() == Comdat::Any;
1026 }
1027 // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
1028 // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
1029 if (TM.getFunctionSections() &&
1030 (getContext().getAsmInfo().useIntegratedAssembler() &&
1031 getContext().getAsmInfo().binutilsIsAtLeast(2, 36))) {
1032 Flags |= ELF::SHF_LINK_ORDER;
1033 LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym);
1034 }
1035
1036 // Append the function name as the suffix like GCC, assuming
1037 // -funique-section-names applies to .gcc_except_table sections.
1038 return getContext().getELFSection(
1039 (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
1040 : LSDA->getName()),
1041 LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
1042 LinkedToSym);
1043}
1044
1046 bool UsesLabelDifference, const Function &F) const {
1047 // We can always create relative relocations, so use another section
1048 // that can be marked non-executable.
1049 return false;
1050}
1051
1052/// Given a mergeable constant with the specified size and relocation
1053/// information, return a section that it should be placed in.
1055 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1056 const Function *F) const {
1057 if (Kind.isMergeableConst4() && MergeableConst4Section)
1059 if (Kind.isMergeableConst8() && MergeableConst8Section)
1061 if (Kind.isMergeableConst16() && MergeableConst16Section)
1063 if (Kind.isMergeableConst32() && MergeableConst32Section)
1065 if (Kind.isReadOnly())
1066 return ReadOnlySection;
1067
1068 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1069 return DataRelROSection;
1070}
1071
1073 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1074 const Function *F, StringRef SectionSuffix) const {
1075 // TODO: Share code between this function and
1076 // MCObjectInfo::initELFMCObjectFileInfo.
1077 if (SectionSuffix.empty())
1078 return getSectionForConstant(DL, Kind, C, Alignment, F);
1079
1080 auto &Context = getContext();
1081 if (Kind.isMergeableConst4() && MergeableConst4Section)
1082 return Context.getELFSection(".rodata.cst4." + SectionSuffix + ".",
1085 if (Kind.isMergeableConst8() && MergeableConst8Section)
1086 return Context.getELFSection(".rodata.cst8." + SectionSuffix + ".",
1089 if (Kind.isMergeableConst16() && MergeableConst16Section)
1090 return Context.getELFSection(".rodata.cst16." + SectionSuffix + ".",
1093 if (Kind.isMergeableConst32() && MergeableConst32Section)
1094 return Context.getELFSection(".rodata.cst32." + SectionSuffix + ".",
1097 if (Kind.isReadOnly())
1098 return Context.getELFSection(".rodata." + SectionSuffix + ".",
1100
1101 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1102 return Context.getELFSection(".data.rel.ro." + SectionSuffix + ".",
1105}
1106
1107/// Returns a unique section for the given machine basic block.
1109 const Function &F, const MachineBasicBlock &MBB,
1110 const TargetMachine &TM) const {
1111 assert(MBB.isBeginSection() && "Basic block does not start a section!");
1113
1114 // For cold sections use the .text.split. prefix along with the parent
1115 // function name. All cold blocks for the same function go to the same
1116 // section. Similarly all exception blocks are grouped by symbol name
1117 // under the .text.eh prefix. For regular sections, we either use a unique
1118 // name, or a unique ID for the section.
1119 SmallString<128> Name;
1120 StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
1121 if (FunctionSectionName == ".text" ||
1122 FunctionSectionName.starts_with(".text.")) {
1123 // Function is in a regular .text section.
1124 StringRef FunctionName = MBB.getParent()->getName();
1125 if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
1127 Name += FunctionName;
1128 } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
1129 Name += ".text.eh.";
1130 Name += FunctionName;
1131 } else {
1132 Name += FunctionSectionName;
1133 if (TM.getUniqueBasicBlockSectionNames()) {
1134 if (!Name.ends_with("."))
1135 Name += ".";
1136 Name += MBB.getSymbol()->getName();
1137 } else {
1138 UniqueID = NextUniqueID++;
1139 }
1140 }
1141 } else {
1142 // If the original function has a custom non-dot-text section, then emit
1143 // all basic block sections into that section too, each with a unique id.
1144 Name = FunctionSectionName;
1145 UniqueID = NextUniqueID++;
1146 }
1147
1148 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
1149 std::string GroupName;
1150 if (F.hasComdat()) {
1151 Flags |= ELF::SHF_GROUP;
1152 GroupName = F.getComdat()->getName().str();
1153 }
1154 return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
1155 0 /* Entry Size */, GroupName,
1156 F.hasComdat(), UniqueID, nullptr);
1157}
1158
1159static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
1160 bool IsCtor, unsigned Priority,
1161 const MCSymbol *KeySym) {
1162 std::string Name;
1163 unsigned Type;
1164 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
1165 StringRef Comdat = KeySym ? KeySym->getName() : "";
1166
1167 if (KeySym)
1168 Flags |= ELF::SHF_GROUP;
1169
1170 if (UseInitArray) {
1171 if (IsCtor) {
1173 Name = ".init_array";
1174 } else {
1176 Name = ".fini_array";
1177 }
1178 if (Priority != 65535) {
1179 Name += '.';
1180 Name += utostr(Priority);
1181 }
1182 } else {
1183 // The default scheme is .ctor / .dtor, so we have to invert the priority
1184 // numbering.
1185 if (IsCtor)
1186 Name = ".ctors";
1187 else
1188 Name = ".dtors";
1189 if (Priority != 65535)
1190 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1192 }
1193
1194 return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
1195}
1196
1198 unsigned Priority, const MCSymbol *KeySym) const {
1199 return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
1200 KeySym);
1201}
1202
1204 unsigned Priority, const MCSymbol *KeySym) const {
1205 return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
1206 KeySym);
1207}
1208
1210 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1211 std::optional<int64_t> PCRelativeOffset) const {
1212 auto &Ctx = getContext();
1213 const MCExpr *Res;
1214 // Return a relocatable expression with the PLT specifier, %plt(GV) or
1215 // %plt(GV-RHS).
1216 if (PCRelativeOffset && PLTPCRelativeSpecifier) {
1217 Res = MCSymbolRefExpr::create(LHS, Ctx);
1218 // The current location is RHS plus *PCRelativeOffset. Compensate for it.
1219 Addend += *PCRelativeOffset;
1220 if (Addend)
1221 Res = MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx),
1222 Ctx);
1224 }
1225
1227 return nullptr;
1230 MCSymbolRefExpr::create(RHS, Ctx), Ctx);
1231 if (Addend)
1232 Res =
1233 MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx), Ctx);
1234 return Res;
1235}
1236
1237// Reference the PLT entry of a function, optionally with a subtrahend (`RHS`).
1239 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1240 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
1241 if (RHS)
1242 return lowerSymbolDifference(LHS, RHS, Addend, PCRelativeOffset);
1243
1244 // Only the legacy MCSymbolRefExpr::VariantKind approach is implemented.
1245 // Reference LHS@plt or LHS@plt - RHS.
1248 return nullptr;
1249}
1250
1252 // Use ".GCC.command.line" since this feature is to support clang's
1253 // -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1254 // same name.
1255 return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
1257}
1258
1259void
1261 UseInitArray = UseInitArray_;
1262 MCContext &Ctx = getContext();
1263 if (!UseInitArray) {
1264 StaticCtorSection = Ctx.getELFSection(".ctors", ELF::SHT_PROGBITS,
1266
1267 StaticDtorSection = Ctx.getELFSection(".dtors", ELF::SHT_PROGBITS,
1269 return;
1270 }
1271
1272 StaticCtorSection = Ctx.getELFSection(".init_array", ELF::SHT_INIT_ARRAY,
1274 StaticDtorSection = Ctx.getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
1276}
1277
1278//===----------------------------------------------------------------------===//
1279// MachO
1280//===----------------------------------------------------------------------===//
1281
1285
1287 const TargetMachine &TM) {
1289 if (TM.getRelocationModel() == Reloc::Static) {
1290 StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0,
1292 StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0,
1294 } else {
1295 StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func",
1298 StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func",
1301 }
1302
1308}
1309
1311 unsigned Priority, const MCSymbol *KeySym) const {
1312 return StaticDtorSection;
1313 // In userspace, we lower global destructors via atexit(), but kernel/kext
1314 // environments do not provide this function so we still need to support the
1315 // legacy way here.
1316 // See the -disable-atexit-based-global-dtor-lowering CodeGen flag for more
1317 // context.
1318}
1319
1321 Module &M) const {
1322 // Emit the linker options if present.
1323 emitLinkerDirectives(Streamer, M);
1324
1325 emitPseudoProbeDescMetadata(Streamer, M);
1326
1327 unsigned VersionVal = 0;
1328 unsigned ImageInfoFlags = 0;
1329 StringRef SectionVal;
1330
1331 GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1332 emitCGProfileMetadata(Streamer, M);
1333
1334 // The section is mandatory. If we don't have it, then we don't have GC info.
1335 if (SectionVal.empty())
1336 return;
1337
1338 StringRef Segment, Section;
1339 unsigned TAA = 0, StubSize = 0;
1340 bool TAAParsed;
1342 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1343 // If invalid, report the error with report_fatal_error.
1344 report_fatal_error("Invalid section specifier '" + Section +
1345 "': " + toString(std::move(E)) + ".");
1346 }
1347
1348 // Get the section.
1350 Segment, Section, TAA, StubSize, SectionKind::getData());
1351 Streamer.switchSection(S);
1352 Streamer.emitLabel(getContext().
1353 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1354 Streamer.emitInt32(VersionVal);
1355 Streamer.emitInt32(ImageInfoFlags);
1356 Streamer.addBlankLine();
1357}
1358
1360 Module &M) const {
1361 if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1362 for (const auto *Option : LinkerOptions->operands()) {
1363 SmallVector<std::string, 4> StrOptions;
1364 for (const auto &Piece : cast<MDNode>(Option)->operands())
1365 StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1366 Streamer.emitLinkerOptions(StrOptions);
1367 }
1368 }
1369}
1370
1371static void checkMachOComdat(const GlobalValue *GV) {
1372 const Comdat *C = GV->getComdat();
1373 if (!C)
1374 return;
1375
1376 report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
1377 "' cannot be lowered.");
1378}
1379
1381 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1382
1384
1385 // Parse the section specifier and create it if valid.
1386 StringRef Segment, Section;
1387 unsigned TAA = 0, StubSize = 0;
1388 bool TAAParsed;
1389
1390 checkMachOComdat(GO);
1391
1393 SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1394 // If invalid, report the error with report_fatal_error.
1395 report_fatal_error("Global variable '" + GO->getName() +
1396 "' has an invalid section specifier '" +
1397 GO->getSection() + "': " + toString(std::move(E)) + ".");
1398 }
1399
1400 // Get the section.
1401 MCSectionMachO *S =
1402 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1403
1404 // If TAA wasn't set by ParseSectionSpecifier() above,
1405 // use the value returned by getMachOSection() as a default.
1406 if (!TAAParsed)
1407 TAA = S->getTypeAndAttributes();
1408
1409 // Okay, now that we got the section, verify that the TAA & StubSize agree.
1410 // If the user declared multiple globals with different section flags, we need
1411 // to reject it here.
1412 if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1413 // If invalid, report the error with report_fatal_error.
1414 report_fatal_error("Global variable '" + GO->getName() +
1415 "' section type or attributes does not match previous"
1416 " section specifier");
1417 }
1418
1419 return S;
1420}
1421
1423 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1424 checkMachOComdat(GO);
1425
1426 // Handle thread local data.
1427 if (Kind.isThreadBSS()) return TLSBSSSection;
1428 if (Kind.isThreadData()) return TLSDataSection;
1429
1430 if (Kind.isText())
1432
1433 // If this is weak/linkonce, put this in a coalescable section, either in text
1434 // or data depending on if it is writable.
1435 if (GO->isWeakForLinker()) {
1436 if (Kind.isReadOnly())
1437 return ConstTextCoalSection;
1438 if (Kind.isReadOnlyWithRel())
1439 return ConstDataCoalSection;
1440 return DataCoalSection;
1441 }
1442
1443 // FIXME: Alignment check should be handled by section classifier.
1444 if (Kind.isMergeable1ByteCString() &&
1446 cast<GlobalVariable>(GO)) < Align(32))
1447 return CStringSection;
1448
1449 // Do not put 16-bit arrays in the UString section if they have an
1450 // externally visible label, this runs into issues with certain linker
1451 // versions.
1452 if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1454 cast<GlobalVariable>(GO)) < Align(32))
1455 return UStringSection;
1456
1457 // With MachO only variables whose corresponding symbol starts with 'l' or
1458 // 'L' can be merged, so we only try merging GVs with private linkage.
1459 if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1460 if (Kind.isMergeableConst4())
1462 if (Kind.isMergeableConst8())
1464 if (Kind.isMergeableConst16())
1466 }
1467
1468 // Otherwise, if it is readonly, but not something we can specially optimize,
1469 // just drop it in .const.
1470 if (Kind.isReadOnly())
1471 return ReadOnlySection;
1472
1473 // If this is marked const, put it into a const section. But if the dynamic
1474 // linker needs to write to it, put it in the data segment.
1475 if (Kind.isReadOnlyWithRel())
1476 return ConstDataSection;
1477
1478 // Put zero initialized globals with strong external linkage in the
1479 // DATA, __common section with the .zerofill directive.
1480 if (Kind.isBSSExtern())
1481 return DataCommonSection;
1482
1483 // Put zero initialized globals with local linkage in __DATA,__bss directive
1484 // with the .zerofill directive (aka .lcomm).
1485 if (Kind.isBSSLocal())
1486 return DataBSSSection;
1487
1488 // Otherwise, just drop the variable in the normal data section.
1489 return DataSection;
1490}
1491
1493 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1494 const Function *F) const {
1495 // If this constant requires a relocation, we have to put it in the data
1496 // segment, not in the text segment.
1497 if (Kind.isData() || Kind.isReadOnlyWithRel())
1498 return ConstDataSection;
1499
1500 if (Kind.isMergeableConst4())
1502 if (Kind.isMergeableConst8())
1504 if (Kind.isMergeableConst16())
1506 return ReadOnlySection; // .const
1507}
1508
1513
1515 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
1516 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1517 // The mach-o version of this method defaults to returning a stub reference.
1518
1519 if (Encoding & DW_EH_PE_indirect) {
1520 MachineModuleInfoMachO &MachOMMI =
1522
1523 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1524
1525 // Add information about the stub reference to MachOMMI so that the stub
1526 // gets emitted by the asmprinter.
1527 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1528 if (!StubSym.getPointer()) {
1529 MCSymbol *Sym = TM.getSymbol(GV);
1531 }
1532
1535 Encoding & ~DW_EH_PE_indirect, Streamer);
1536 }
1537
1539 MMI, Streamer);
1540}
1541
1543 const GlobalValue *GV, const TargetMachine &TM,
1544 MachineModuleInfo *MMI) const {
1545 // The mach-o version of this method defaults to returning a stub reference.
1546 MachineModuleInfoMachO &MachOMMI =
1548
1549 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1550
1551 // Add information about the stub reference to MachOMMI so that the stub
1552 // gets emitted by the asmprinter.
1553 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1554 if (!StubSym.getPointer()) {
1555 MCSymbol *Sym = TM.getSymbol(GV);
1557 }
1558
1559 return SSym;
1560}
1561
1563 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
1564 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1565 // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1566 // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1567 // through a non_lazy_ptr stub instead. One advantage is that it allows the
1568 // computation of deltas to final external symbols. Example:
1569 //
1570 // _extgotequiv:
1571 // .long _extfoo
1572 //
1573 // _delta:
1574 // .long _extgotequiv-_delta
1575 //
1576 // is transformed to:
1577 //
1578 // _delta:
1579 // .long L_extfoo$non_lazy_ptr-(_delta+0)
1580 //
1581 // .section __IMPORT,__pointers,non_lazy_symbol_pointers
1582 // L_extfoo$non_lazy_ptr:
1583 // .indirect_symbol _extfoo
1584 // .long 0
1585 //
1586 // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1587 // may point to both local (same translation unit) and global (other
1588 // translation units) symbols. Example:
1589 //
1590 // .section __DATA,__pointers,non_lazy_symbol_pointers
1591 // L1:
1592 // .indirect_symbol _myGlobal
1593 // .long 0
1594 // L2:
1595 // .indirect_symbol _myLocal
1596 // .long _myLocal
1597 //
1598 // If the symbol is local, instead of the symbol's index, the assembler
1599 // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1600 // Then the linker will notice the constant in the table and will look at the
1601 // content of the symbol.
1602 MachineModuleInfoMachO &MachOMMI =
1604 MCContext &Ctx = getContext();
1605
1606 // The offset must consider the original displacement from the base symbol
1607 // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1608 Offset = -MV.getConstant();
1609 const MCSymbol *BaseSym = MV.getSubSym();
1610
1611 // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1612 // non_lazy_ptr stubs.
1613 SmallString<128> Name;
1614 StringRef Suffix = "$non_lazy_ptr";
1616 Name += Sym->getName();
1617 Name += Suffix;
1618 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1619
1620 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1621
1622 if (!StubSym.getPointer())
1623 StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1624 !GV->hasLocalLinkage());
1625
1626 const MCExpr *BSymExpr = MCSymbolRefExpr::create(BaseSym, Ctx);
1627 const MCExpr *LHS = MCSymbolRefExpr::create(Stub, Ctx);
1628
1629 if (!Offset)
1630 return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1631
1632 const MCExpr *RHS =
1634 return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1635}
1636
1637static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
1638 const MCSection &Section) {
1640 return true;
1641
1642 // FIXME: we should be able to use private labels for sections that can't be
1643 // dead-stripped (there's no issue with blocking atomization there), but `ld
1644 // -r` sometimes drops the no_dead_strip attribute from sections so for safety
1645 // we don't allow it.
1646 return false;
1647}
1648
1650 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1651 const TargetMachine &TM) const {
1652 bool CannotUsePrivateLabel = true;
1653 if (auto *GO = GV->getAliaseeObject()) {
1655 const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
1656 CannotUsePrivateLabel = !canUsePrivateLabel(TM.getMCAsmInfo(), *TheSection);
1657 }
1658 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1659}
1660
1661//===----------------------------------------------------------------------===//
1662// COFF
1663//===----------------------------------------------------------------------===//
1664
1665static unsigned
1667 unsigned Flags = 0;
1669
1670 if (K.isMetadata())
1671 Flags |=
1673 else if (K.isExclude())
1674 Flags |=
1676 else if (K.isText())
1677 Flags |=
1682 else if (K.isBSS())
1683 Flags |=
1687 else if (K.isThreadLocal())
1688 Flags |=
1692 else if (K.isReadOnly() || K.isReadOnlyWithRel())
1693 Flags |=
1696 else if (K.isWriteable())
1697 Flags |=
1701
1702 return Flags;
1703}
1704
1706 const Comdat *C = GV->getComdat();
1707 assert(C && "expected GV to have a Comdat!");
1708
1709 StringRef ComdatGVName = C->getName();
1710 const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1711 if (!ComdatGV)
1712 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1713 "' does not exist.");
1714
1715 if (ComdatGV->getComdat() != C)
1716 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1717 "' is not a key for its COMDAT.");
1718
1719 return ComdatGV;
1720}
1721
1722static int getSelectionForCOFF(const GlobalValue *GV) {
1723 if (const Comdat *C = GV->getComdat()) {
1724 const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
1725 if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1726 ComdatKey = GA->getAliaseeObject();
1727 if (ComdatKey == GV) {
1728 switch (C->getSelectionKind()) {
1729 case Comdat::Any:
1731 case Comdat::ExactMatch:
1733 case Comdat::Largest:
1737 case Comdat::SameSize:
1739 }
1740 } else {
1742 }
1743 }
1744 return 0;
1745}
1746
1748 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1749 StringRef Name = handlePragmaClangSection(GO, Kind);
1750 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::COFF,
1751 /*AddSegmentInfo=*/false) ||
1752 Name == getInstrProfSectionName(IPSK_covfun, Triple::COFF,
1753 /*AddSegmentInfo=*/false) ||
1754 Name == getInstrProfSectionName(IPSK_covdata, Triple::COFF,
1755 /*AddSegmentInfo=*/false) ||
1756 Name == getInstrProfSectionName(IPSK_covname, Triple::COFF,
1757 /*AddSegmentInfo=*/false) ||
1758 Name == ".llvmbc" || Name == ".llvmcmd")
1759 Kind = SectionKind::getMetadata();
1760 int Selection = 0;
1761 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1762 StringRef COMDATSymName = "";
1763 if (GO->hasComdat()) {
1765 const GlobalValue *ComdatGV;
1767 ComdatGV = getComdatGVForCOFF(GO);
1768 else
1769 ComdatGV = GO;
1770
1771 if (!ComdatGV->hasPrivateLinkage()) {
1772 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1773 COMDATSymName = Sym->getName();
1774 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1775 } else {
1776 Selection = 0;
1777 }
1778 }
1779
1780 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1781 Selection);
1782}
1783
1785 if (Kind.isText())
1786 return ".text";
1787 if (Kind.isBSS())
1788 return ".bss";
1789 if (Kind.isThreadLocal())
1790 return ".tls$";
1791 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1792 return ".rdata";
1793 return ".data";
1794}
1795
1797 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1798 // If we have -ffunction-sections then we should emit the global value to a
1799 // uniqued section specifically for it.
1800 bool EmitUniquedSection;
1801 if (Kind.isText())
1802 EmitUniquedSection = TM.getFunctionSections();
1803 else
1804 EmitUniquedSection = TM.getDataSections();
1805
1806 if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1808
1809 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1810
1811 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1813 if (!Selection)
1815 const GlobalValue *ComdatGV;
1816 if (GO->hasComdat())
1817 ComdatGV = getComdatGVForCOFF(GO);
1818 else
1819 ComdatGV = GO;
1820
1822 if (EmitUniquedSection)
1823 UniqueID = NextUniqueID++;
1824
1825 if (!ComdatGV->hasPrivateLinkage()) {
1826 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1827 StringRef COMDATSymName = Sym->getName();
1828
1829 if (const auto *F = dyn_cast<Function>(GO))
1830 if (std::optional<StringRef> Prefix = F->getSectionPrefix())
1831 raw_svector_ostream(Name) << '$' << *Prefix;
1832
1833 // Append "$symbol" to the section name *before* IR-level mangling is
1834 // applied when targetting mingw. This is what GCC does, and the ld.bfd
1835 // COFF linker will not properly handle comdats otherwise.
1836 if (getContext().getTargetTriple().isOSCygMing())
1837 raw_svector_ostream(Name) << '$' << ComdatGV->getName();
1838
1839 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1841 } else {
1842 SmallString<256> TmpData;
1843 getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
1844 return getContext().getCOFFSection(Name, Characteristics, TmpData,
1846 }
1847 }
1848
1849 if (Kind.isText())
1850 return TextSection;
1851
1852 if (Kind.isThreadLocal())
1853 return TLSDataSection;
1854
1855 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1856 return ReadOnlySection;
1857
1858 // Note: we claim that common symbols are put in BSSSection, but they are
1859 // really emitted with the magic .comm directive, which creates a symbol table
1860 // entry but not a section.
1861 if (Kind.isBSS() || Kind.isCommon())
1862 return BSSSection;
1863
1864 return DataSection;
1865}
1866
1868 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1869 const TargetMachine &TM) const {
1870 bool CannotUsePrivateLabel = false;
1871 if (GV->hasPrivateLinkage() &&
1872 ((isa<Function>(GV) && TM.getFunctionSections()) ||
1873 (isa<GlobalVariable>(GV) && TM.getDataSections())))
1874 CannotUsePrivateLabel = true;
1875
1876 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1877}
1878
1880 const Function &F, const TargetMachine &TM) const {
1881 // If the function can be removed, produce a unique section so that
1882 // the table doesn't prevent the removal.
1883 const Comdat *C = F.getComdat();
1884 bool EmitUniqueSection = TM.getFunctionSections() || C;
1885 if (!EmitUniqueSection)
1886 return ReadOnlySection;
1887
1888 // FIXME: we should produce a symbol for F instead.
1889 if (F.hasPrivateLinkage())
1890 return ReadOnlySection;
1891
1892 MCSymbol *Sym = TM.getSymbol(&F);
1893 StringRef COMDATSymName = Sym->getName();
1894
1897 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1898 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1899 unsigned UniqueID = NextUniqueID++;
1900
1901 return getContext().getCOFFSection(SecName, Characteristics, COMDATSymName,
1903 UniqueID);
1904}
1905
1907 bool UsesLabelDifference, const Function &F) const {
1908 if (TM->getTargetTriple().getArch() == Triple::x86_64) {
1910 // We can always create relative relocations, so use another section
1911 // that can be marked non-executable.
1912 return false;
1913 }
1914 }
1916 UsesLabelDifference, F);
1917}
1918
1920 Module &M) const {
1921 emitLinkerDirectives(Streamer, M);
1922
1923 unsigned Version = 0;
1924 unsigned Flags = 0;
1925 StringRef Section;
1926
1927 GetObjCImageInfo(M, Version, Flags, Section);
1928 if (!Section.empty()) {
1929 auto &C = getContext();
1930 auto *S = C.getCOFFSection(Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1932 Streamer.switchSection(S);
1933 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1934 Streamer.emitInt32(Version);
1935 Streamer.emitInt32(Flags);
1936 Streamer.addBlankLine();
1937 }
1938
1939 emitCGProfileMetadata(Streamer, M);
1940 emitPseudoProbeDescMetadata(Streamer, M, [](MCStreamer &Streamer) {
1941 if (MCSymbol *Sym =
1942 static_cast<MCSectionCOFF *>(Streamer.getCurrentSectionOnly())
1943 ->getCOMDATSymbol())
1944 if (Sym->isUndefined()) {
1945 // COMDAT symbol must be external to perform deduplication.
1946 Streamer.emitSymbolAttribute(Sym, MCSA_Global);
1947 Streamer.emitLabel(Sym);
1948 }
1949 });
1950}
1951
1953 MCStreamer &Streamer, Module &M) const {
1954 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1955 // Emit the linker options to the linker .drectve section. According to the
1956 // spec, this section is a space-separated string containing flags for
1957 // linker.
1959 Streamer.switchSection(Sec);
1960 for (const auto *Option : LinkerOptions->operands()) {
1961 for (const auto &Piece : cast<MDNode>(Option)->operands()) {
1962 // Lead with a space for consistency with our dllexport implementation.
1963 std::string Directive(" ");
1964 Directive.append(std::string(cast<MDString>(Piece)->getString()));
1965 Streamer.emitBytes(Directive);
1966 }
1967 }
1968 }
1969
1970 // Emit /EXPORT: flags for each exported global as necessary.
1971 std::string Flags;
1972 for (const GlobalValue &GV : M.global_values()) {
1973 raw_string_ostream OS(Flags);
1974 emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
1975 getMangler());
1976 if (!Flags.empty()) {
1977 Streamer.switchSection(getDrectveSection());
1978 Streamer.emitBytes(Flags);
1979 }
1980 Flags.clear();
1981 }
1982
1983 // Emit /INCLUDE: flags for each used global as necessary.
1984 if (const auto *LU = M.getNamedGlobal("llvm.used")) {
1985 assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
1986 assert(isa<ArrayType>(LU->getValueType()) &&
1987 "expected llvm.used to be an array type");
1988 if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
1989 for (const Value *Op : A->operands()) {
1990 const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
1991 // Global symbols with internal or private linkage are not visible to
1992 // the linker, and thus would cause an error when the linker tried to
1993 // preserve the symbol due to the `/include:` directive.
1994 if (GV->hasLocalLinkage())
1995 continue;
1996
1997 raw_string_ostream OS(Flags);
1998 emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
1999 getMangler());
2000
2001 if (!Flags.empty()) {
2002 Streamer.switchSection(getDrectveSection());
2003 Streamer.emitBytes(Flags);
2004 }
2005 Flags.clear();
2006 }
2007 }
2008 }
2009}
2010
2012 const TargetMachine &TM) {
2014 this->TM = &TM;
2015 const Triple &T = TM.getTargetTriple();
2016 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2018 Ctx.getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2021 Ctx.getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2023 } else {
2024 StaticCtorSection = Ctx.getCOFFSection(
2027 StaticDtorSection = Ctx.getCOFFSection(
2030 }
2031}
2032
2034 const Triple &T, bool IsCtor,
2035 unsigned Priority,
2036 const MCSymbol *KeySym,
2038 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2039 // If the priority is the default, use .CRT$XCU, possibly associative.
2040 if (Priority == 65535)
2041 return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
2042
2043 // Otherwise, we need to compute a new section name. Low priorities should
2044 // run earlier. The linker will sort sections ASCII-betically, and we need a
2045 // string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
2046 // make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
2047 // low priorities need to sort before 'L', since the CRT uses that
2048 // internally, so we use ".CRT$XCA00001" for them. We have a contract with
2049 // the frontend that "init_seg(compiler)" corresponds to priority 200 and
2050 // "init_seg(lib)" corresponds to priority 400, and those respectively use
2051 // 'C' and 'L' without the priority suffix. Priorities between 200 and 400
2052 // use 'C' with the priority as a suffix.
2053 SmallString<24> Name;
2054 char LastLetter = 'T';
2055 bool AddPrioritySuffix = Priority != 200 && Priority != 400;
2056 if (Priority < 200)
2057 LastLetter = 'A';
2058 else if (Priority < 400)
2059 LastLetter = 'C';
2060 else if (Priority == 400)
2061 LastLetter = 'L';
2062 raw_svector_ostream OS(Name);
2063 OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;
2064 if (AddPrioritySuffix)
2065 OS << format("%05u", Priority);
2066 MCSectionCOFF *Sec = Ctx.getCOFFSection(
2068 return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
2069 }
2070
2071 std::string Name = IsCtor ? ".ctors" : ".dtors";
2072 if (Priority != 65535)
2073 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
2074
2075 return Ctx.getAssociativeCOFFSection(
2076 Ctx.getCOFFSection(Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2079 KeySym, 0);
2080}
2081
2083 unsigned Priority, const MCSymbol *KeySym) const {
2085 getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
2086 static_cast<MCSectionCOFF *>(StaticCtorSection));
2087}
2088
2090 unsigned Priority, const MCSymbol *KeySym) const {
2092 getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
2093 static_cast<MCSectionCOFF *>(StaticDtorSection));
2094}
2095
2097 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
2098 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
2099 const Triple &T = TM.getTargetTriple();
2100 if (T.isOSCygMing())
2101 return nullptr;
2102
2103 // Our symbols should exist in address space zero, cowardly no-op if
2104 // otherwise.
2105 if (LHS->getType()->getPointerAddressSpace() != 0 ||
2106 RHS->getType()->getPointerAddressSpace() != 0)
2107 return nullptr;
2108
2109 // Both ptrtoint instructions must wrap global objects:
2110 // - Only global variables are eligible for image relative relocations.
2111 // - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
2112 // We expect __ImageBase to be a global variable without a section, externally
2113 // defined.
2114 //
2115 // It should look something like this: @__ImageBase = external constant i8
2116 if (!isa<GlobalObject>(LHS) || !isa<GlobalVariable>(RHS) ||
2117 LHS->isThreadLocal() || RHS->isThreadLocal() ||
2118 RHS->getName() != "__ImageBase" || !RHS->hasExternalLinkage() ||
2119 cast<GlobalVariable>(RHS)->hasInitializer() || RHS->hasSection())
2120 return nullptr;
2121
2122 const MCExpr *Res = MCSymbolRefExpr::create(
2123 TM.getSymbol(LHS), MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
2124 if (Addend != 0)
2126 Res, MCConstantExpr::create(Addend, getContext()), getContext());
2127 return Res;
2128}
2129
2130static std::string APIntToHexString(const APInt &AI) {
2131 unsigned Width = (AI.getBitWidth() / 8) * 2;
2132 std::string HexString = toString(AI, 16, /*Signed=*/false);
2133 llvm::transform(HexString, HexString.begin(), tolower);
2134 unsigned Size = HexString.size();
2135 assert(Width >= Size && "hex string is too large!");
2136 HexString.insert(HexString.begin(), Width - Size, '0');
2137
2138 return HexString;
2139}
2140
2141static std::string scalarConstantToHexString(const Constant *C) {
2142 Type *Ty = C->getType();
2143 if (isa<UndefValue>(C)) {
2144 return APIntToHexString(APInt::getZero(Ty->getPrimitiveSizeInBits()));
2145 } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
2146 if (CFP->getType()->isFloatingPointTy())
2147 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2148
2149 std::string HexString;
2150 unsigned NumElements =
2151 cast<FixedVectorType>(CFP->getType())->getNumElements();
2152 for (unsigned I = 0; I < NumElements; ++I)
2153 HexString += APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2154 return HexString;
2155 } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
2156 if (CI->getType()->isIntegerTy())
2157 return APIntToHexString(CI->getValue());
2158
2159 std::string HexString;
2160 unsigned NumElements =
2161 cast<FixedVectorType>(CI->getType())->getNumElements();
2162 for (unsigned I = 0; I < NumElements; ++I)
2163 HexString += APIntToHexString(CI->getValue());
2164 return HexString;
2165 } else {
2166 unsigned NumElements;
2167 if (auto *VTy = dyn_cast<VectorType>(Ty))
2168 NumElements = cast<FixedVectorType>(VTy)->getNumElements();
2169 else
2170 NumElements = Ty->getArrayNumElements();
2171 std::string HexString;
2172 for (int I = NumElements - 1, E = -1; I != E; --I)
2173 HexString += scalarConstantToHexString(C->getAggregateElement(I));
2174 return HexString;
2175 }
2176}
2177
2179 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2180 const Function *F) const {
2181 if (Kind.isMergeableConst() && C &&
2182 getContext().getAsmInfo().hasCOFFComdatConstants()) {
2183 // This creates comdat sections with the given symbol name, but unless
2184 // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
2185 // will be created with a null storage class, which makes GNU binutils
2186 // error out.
2187 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2190 std::string COMDATSymName;
2191 if (Kind.isMergeableConst4()) {
2192 if (Alignment <= 4) {
2193 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2194 Alignment = Align(4);
2195 }
2196 } else if (Kind.isMergeableConst8()) {
2197 if (Alignment <= 8) {
2198 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2199 Alignment = Align(8);
2200 }
2201 } else if (Kind.isMergeableConst16()) {
2202 // FIXME: These may not be appropriate for non-x86 architectures.
2203 if (Alignment <= 16) {
2204 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
2205 Alignment = Align(16);
2206 }
2207 } else if (Kind.isMergeableConst32()) {
2208 if (Alignment <= 32) {
2209 COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
2210 Alignment = Align(32);
2211 }
2212 }
2213
2214 if (!COMDATSymName.empty())
2215 return getContext().getCOFFSection(".rdata", Characteristics,
2216 COMDATSymName,
2218 }
2219
2220 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, Alignment,
2221 F);
2222}
2223
2224//===----------------------------------------------------------------------===//
2225// Wasm
2226//===----------------------------------------------------------------------===//
2227
2228static const Comdat *getWasmComdat(const GlobalValue *GV) {
2229 const Comdat *C = GV->getComdat();
2230 if (!C)
2231 return nullptr;
2232
2233 if (C->getSelectionKind() != Comdat::Any)
2234 report_fatal_error("WebAssembly COMDATs only support "
2235 "SelectionKind::Any, '" + C->getName() + "' cannot be "
2236 "lowered.");
2237
2238 return C;
2239}
2240
2241static unsigned getWasmSectionFlags(SectionKind K, bool Retain) {
2242 unsigned Flags = 0;
2243
2244 if (K.isThreadLocal())
2245 Flags |= wasm::WASM_SEG_FLAG_TLS;
2246
2247 if (K.isMergeableCString())
2249
2250 if (Retain)
2252
2253 // TODO(sbc): Add suport for K.isMergeableConst()
2254
2255 return Flags;
2256}
2257
2260 collectUsedGlobalVariables(M, Vec, false);
2261 for (GlobalValue *GV : Vec)
2262 if (auto *GO = dyn_cast<GlobalObject>(GV))
2263 Used.insert(GO);
2264}
2265
2267 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2268 // We don't support explict section names for functions in the wasm object
2269 // format. Each function has to be in its own unique section.
2270 if (isa<Function>(GO)) {
2271 return SelectSectionForGlobal(GO, Kind, TM);
2272 }
2273
2274 StringRef Name = GO->getSection();
2275
2276 // Certain data sections we treat as named custom sections rather than
2277 // segments within the data section.
2278 // This could be avoided if all data segements (the wasm sense) were
2279 // represented as their own sections (in the llvm sense).
2280 // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2281 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::Wasm,
2282 /*AddSegmentInfo=*/false) ||
2283 Name == getInstrProfSectionName(IPSK_covfun, Triple::Wasm,
2284 /*AddSegmentInfo=*/false) ||
2285 Name == ".llvmbc" || Name == ".llvmcmd")
2286 Kind = SectionKind::getMetadata();
2287
2288 StringRef Group = "";
2289 if (const Comdat *C = getWasmComdat(GO)) {
2290 Group = C->getName();
2291 }
2292
2293 unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
2294 MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
2296
2297 return Section;
2298}
2299
2300static MCSectionWasm *
2302 SectionKind Kind, Mangler &Mang,
2303 const TargetMachine &TM, bool EmitUniqueSection,
2304 unsigned *NextUniqueID, bool Retain) {
2305 StringRef Group = "";
2306 if (const Comdat *C = getWasmComdat(GO)) {
2307 Group = C->getName();
2308 }
2309
2310 bool UniqueSectionNames = TM.getUniqueSectionNames();
2311 SmallString<128> Name = getSectionPrefixForGlobal(Kind, /*IsLarge=*/false);
2312
2313 if (const auto *F = dyn_cast<Function>(GO)) {
2314 const auto &OptionalPrefix = F->getSectionPrefix();
2315 if (OptionalPrefix)
2316 raw_svector_ostream(Name) << '.' << *OptionalPrefix;
2317 }
2318
2319 if (EmitUniqueSection && UniqueSectionNames) {
2320 Name.push_back('.');
2321 TM.getNameWithPrefix(Name, GO, Mang, true);
2322 }
2324 if (EmitUniqueSection && !UniqueSectionNames) {
2325 UniqueID = *NextUniqueID;
2326 (*NextUniqueID)++;
2327 }
2328
2329 unsigned Flags = getWasmSectionFlags(Kind, Retain);
2330 return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2331}
2332
2334 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2335
2336 if (Kind.isCommon())
2337 report_fatal_error("mergable sections not supported yet on wasm");
2338
2339 // If we have -ffunction-section or -fdata-section then we should emit the
2340 // global value to a uniqued section specifically for it.
2341 bool EmitUniqueSection = false;
2342 if (Kind.isText())
2343 EmitUniqueSection = TM.getFunctionSections();
2344 else
2345 EmitUniqueSection = TM.getDataSections();
2346 EmitUniqueSection |= GO->hasComdat();
2347 bool Retain = Used.count(GO);
2348 EmitUniqueSection |= Retain;
2349
2350 return selectWasmSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
2351 EmitUniqueSection, &NextUniqueID, Retain);
2352}
2353
2355 bool UsesLabelDifference, const Function &F) const {
2356 // We can always create relative relocations, so use another section
2357 // that can be marked non-executable.
2358 return false;
2359}
2360
2364
2365 // We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2366 // .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2368}
2369
2371 unsigned Priority, const MCSymbol *KeySym) const {
2372 return Priority == UINT16_MAX ?
2374 getContext().getWasmSection(".init_array." + utostr(Priority),
2376}
2377
2379 unsigned Priority, const MCSymbol *KeySym) const {
2380 report_fatal_error("@llvm.global_dtors should have been lowered already");
2381}
2382
2383//===----------------------------------------------------------------------===//
2384// XCOFF
2385//===----------------------------------------------------------------------===//
2387 const MachineFunction *MF) {
2388 if (!MF->getLandingPads().empty())
2389 return true;
2390
2391 const Function &F = MF->getFunction();
2392 if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2393 return false;
2394
2395 const GlobalValue *Per =
2396 dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2397 assert(Per && "Personality routine is not a GlobalValue type.");
2399 return false;
2400
2401 return true;
2402}
2403
2405 const MachineFunction *MF) {
2406 const Function &F = MF->getFunction();
2407 if (!F.hasStackProtectorFnAttr())
2408 return false;
2409 // FIXME: check presence of canary word
2410 // There are cases that the stack protectors are not really inserted even if
2411 // the attributes are on.
2412 return true;
2413}
2414
2415MCSymbol *
2417 auto *EHInfoSym =
2418 static_cast<MCSymbolXCOFF *>(MF->getContext().getOrCreateSymbol(
2419 "__ehinfo." + Twine(MF->getFunctionNumber())));
2420 EHInfoSym->setEHInfo();
2421 return EHInfoSym;
2422}
2423
2424MCSymbol *
2426 const TargetMachine &TM) const {
2427 // We always use a qualname symbol for a GV that represents
2428 // a declaration, a function descriptor, or a common symbol. An IFunc is
2429 // lowered as a special trampoline function which has an entry point and a
2430 // descriptor.
2431 // If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2432 // also return a qualname so that a label symbol could be avoided.
2433 // It is inherently ambiguous when the GO represents the address of a
2434 // function, as the GO could either represent a function descriptor or a
2435 // function entry point. We choose to always return a function descriptor
2436 // here.
2437 if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2438 if (GO->isDeclarationForLinker())
2439 return static_cast<const MCSectionXCOFF *>(
2441 ->getQualNameSymbol();
2442
2443 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2444 if (GVar->hasAttribute("toc-data"))
2445 return static_cast<const MCSectionXCOFF *>(
2447 ->getQualNameSymbol();
2448
2449 if (isa<GlobalIFunc>(GO))
2450 return static_cast<const MCSectionXCOFF *>(
2452 ->getQualNameSymbol();
2453
2454 SectionKind GOKind = getKindForGlobal(GO, TM);
2455 if (GOKind.isText())
2456 return static_cast<const MCSectionXCOFF *>(
2458 ->getQualNameSymbol();
2459 if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2460 GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2461 return static_cast<const MCSectionXCOFF *>(
2462 SectionForGlobal(GO, GOKind, TM))
2463 ->getQualNameSymbol();
2464 }
2465
2466 // For all other cases, fall back to getSymbol to return the unqualified name.
2467 return nullptr;
2468}
2469
2471 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2472 if (!GO->hasSection())
2473 report_fatal_error("#pragma clang section is not yet supported");
2474
2476
2477 // Handle the XCOFF::TD case first, then deal with the rest.
2478 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2479 if (GVar->hasAttribute("toc-data"))
2480 return getContext().getXCOFFSection(
2481 SectionName, Kind,
2483 /* MultiSymbolsAllowed*/ true);
2484
2485 XCOFF::StorageMappingClass MappingClass;
2486 if (Kind.isText())
2487 MappingClass = XCOFF::XMC_PR;
2488 else if (Kind.isData() || Kind.isBSS())
2489 MappingClass = XCOFF::XMC_RW;
2490 else if (Kind.isReadOnlyWithRel())
2491 MappingClass =
2492 TM.Options.XCOFFReadOnlyPointers ? XCOFF::XMC_RO : XCOFF::XMC_RW;
2493 else if (Kind.isReadOnly())
2494 MappingClass = XCOFF::XMC_RO;
2495 else
2496 report_fatal_error("XCOFF other section types not yet implemented.");
2497
2498 return getContext().getXCOFFSection(
2499 SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
2500 /* MultiSymbolsAllowed*/ true);
2501}
2502
2504 const GlobalObject *GO, const TargetMachine &TM) const {
2506 "Tried to get ER section for a defined global.");
2507
2508 SmallString<128> Name;
2509 getNameWithPrefix(Name, GO, TM);
2510
2511 // AIX TLS local-dynamic does not need the external reference for the
2512 // "_$TLSML" symbol.
2514 GO->hasName() && GO->getName() == "_$TLSML") {
2515 return getContext().getXCOFFSection(
2516 Name, SectionKind::getData(),
2518 }
2519
2522 if (GO->isThreadLocal())
2523 SMC = XCOFF::XMC_UL;
2524
2525 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2526 if (GVar->hasAttribute("toc-data"))
2527 SMC = XCOFF::XMC_TD;
2528
2529 // Externals go into a csect of type ER.
2530 return getContext().getXCOFFSection(
2533}
2534
2536 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2537 // Handle the XCOFF::TD case first, then deal with the rest.
2538 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2539 if (GVar->hasAttribute("toc-data")) {
2540 SmallString<128> Name;
2541 getNameWithPrefix(Name, GO, TM);
2542 XCOFF::SymbolType symType =
2544 return getContext().getXCOFFSection(
2545 Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_TD, symType),
2546 /* MultiSymbolsAllowed*/ true);
2547 }
2548
2549 // Common symbols go into a csect with matching name which will get mapped
2550 // into the .bss section.
2551 // Zero-initialized local TLS symbols go into a csect with matching name which
2552 // will get mapped into the .tbss section.
2553 if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2554 SmallString<128> Name;
2555 getNameWithPrefix(Name, GO, TM);
2556 XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ? XCOFF::XMC_BS
2557 : Kind.isCommon() ? XCOFF::XMC_RW
2558 : XCOFF::XMC_UL;
2559 return getContext().getXCOFFSection(
2560 Name, Kind, XCOFF::CsectProperties(SMC, XCOFF::XTY_CM));
2561 }
2562
2563 if (Kind.isText()) {
2564 if (TM.getFunctionSections()) {
2565 return static_cast<const MCSymbolXCOFF *>(
2567 ->getRepresentedCsect();
2568 }
2569 return TextSection;
2570 }
2571
2572 if (TM.Options.XCOFFReadOnlyPointers && Kind.isReadOnlyWithRel()) {
2573 if (!TM.getDataSections())
2575 "ReadOnlyPointers is supported only if data sections is turned on");
2576
2577 SmallString<128> Name;
2578 getNameWithPrefix(Name, GO, TM);
2579 return getContext().getXCOFFSection(
2582 }
2583
2584 // For BSS kind, zero initialized data must be emitted to the .data section
2585 // because external linkage control sections that get mapped to the .bss
2586 // section will be linked as tentative definitions, which is only appropriate
2587 // for SectionKind::Common.
2588 if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2589 if (TM.getDataSections()) {
2590 SmallString<128> Name;
2591 getNameWithPrefix(Name, GO, TM);
2592 return getContext().getXCOFFSection(
2593 Name, SectionKind::getData(),
2595 }
2596 return DataSection;
2597 }
2598
2599 if (Kind.isReadOnly()) {
2600 if (TM.getDataSections()) {
2601 SmallString<128> Name;
2602 getNameWithPrefix(Name, GO, TM);
2603 return getContext().getXCOFFSection(
2606 }
2607 return ReadOnlySection;
2608 }
2609
2610 // External/weak TLS data and initialized local TLS data are not eligible
2611 // to be put into common csect. If data sections are enabled, thread
2612 // data are emitted into separate sections. Otherwise, thread data
2613 // are emitted into the .tdata section.
2614 if (Kind.isThreadLocal()) {
2615 if (TM.getDataSections()) {
2616 SmallString<128> Name;
2617 getNameWithPrefix(Name, GO, TM);
2618 return getContext().getXCOFFSection(
2620 }
2621 return TLSDataSection;
2622 }
2623
2624 report_fatal_error("XCOFF other section types not yet implemented.");
2625}
2626
2628 const Function &F, const TargetMachine &TM) const {
2629 assert (!F.getComdat() && "Comdat not supported on XCOFF.");
2630
2631 if (!TM.getFunctionSections())
2632 return ReadOnlySection;
2633
2634 // If the function can be removed, produce a unique section so that
2635 // the table doesn't prevent the removal.
2636 SmallString<128> NameStr(".rodata.jmp..");
2637 getNameWithPrefix(NameStr, &F, TM);
2638 return getContext().getXCOFFSection(
2639 NameStr, SectionKind::getReadOnly(),
2641}
2642
2644 bool UsesLabelDifference, const Function &F) const {
2645 return false;
2646}
2647
2648/// Given a mergeable constant with the specified size and relocation
2649/// information, return a section that it should be placed in.
2651 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2652 const Function *F) const {
2653 // TODO: Enable emiting constant pool to unique sections when we support it.
2654 if (Alignment > Align(16))
2655 report_fatal_error("Alignments greater than 16 not yet supported.");
2656
2657 if (Alignment == Align(8)) {
2658 assert(ReadOnly8Section && "Section should always be initialized.");
2659 return ReadOnly8Section;
2660 }
2661
2662 if (Alignment == Align(16)) {
2663 assert(ReadOnly16Section && "Section should always be initialized.");
2664 return ReadOnly16Section;
2665 }
2666
2667 return ReadOnlySection;
2668}
2669
2671 const TargetMachine &TgtM) {
2675 (TgtM.getTargetTriple().isArch32Bit() ? dwarf::DW_EH_PE_sdata4
2678 LSDAEncoding = 0;
2680
2681 // AIX debug for thread local location is not ready. And for integrated as
2682 // mode, the relocatable address for the thread local variable will cause
2683 // linker error. So disable the location attribute generation for thread local
2684 // variables for now.
2685 // FIXME: when TLS debug on AIX is ready, remove this setting.
2687}
2688
2690 unsigned Priority, const MCSymbol *KeySym) const {
2691 report_fatal_error("no static constructor section on AIX");
2692}
2693
2695 unsigned Priority, const MCSymbol *KeySym) const {
2696 report_fatal_error("no static destructor section on AIX");
2697}
2698
2701 assert(!isa<GlobalIFunc>(GV) && "GlobalIFunc is not supported on AIX.");
2702
2703 switch (GV->getLinkage()) {
2706 return XCOFF::C_HIDEXT;
2710 return XCOFF::C_EXT;
2716 return XCOFF::C_WEAKEXT;
2719 "There is no mapping that implements AppendingLinkage for XCOFF.");
2720 }
2721 llvm_unreachable("Unknown linkage type!");
2722}
2723
2725 const GlobalValue *Func, const TargetMachine &TM) const {
2726 assert((isa<Function>(Func) || isa<GlobalIFunc>(Func) ||
2727 (isa<GlobalAlias>(Func) &&
2729 cast<GlobalAlias>(Func)->getAliaseeObject()))) &&
2730 "Func must be a function or an alias which has a function as base "
2731 "object.");
2732
2733 SmallString<128> NameStr;
2734 NameStr.push_back('.');
2735 getNameWithPrefix(NameStr, Func, TM);
2736
2737 // When -function-sections is enabled and explicit section is not specified,
2738 // it's not necessary to emit function entry point label any more. We will use
2739 // function entry point csect instead. And for function delcarations, the
2740 // undefined symbols gets treated as csect with XTY_ER property.
2741 if (((TM.getFunctionSections() && !Func->hasSection()) ||
2742 Func->isDeclarationForLinker()) &&
2743 (isa<Function>(Func) || isa<GlobalIFunc>(Func))) {
2744 return getContext()
2746 NameStr, SectionKind::getText(),
2747 XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclarationForLinker()
2749 : XCOFF::XTY_SD))
2751 }
2752
2753 return getContext().getOrCreateSymbol(NameStr);
2754}
2755
2757 const GlobalObject *F, const TargetMachine &TM) const {
2759 "F must be a function or ifunc object.");
2760 SmallString<128> NameStr;
2761 getNameWithPrefix(NameStr, F, TM);
2762 return getContext().getXCOFFSection(
2763 NameStr, SectionKind::getData(),
2765}
2766
2768 const MCSymbol *Sym, const TargetMachine &TM) const {
2769 const XCOFF::StorageMappingClass SMC = [](const MCSymbol *Sym,
2770 const TargetMachine &TM) {
2771 auto *XSym = static_cast<const MCSymbolXCOFF *>(Sym);
2772
2773 // The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC,
2774 // otherwise the AIX assembler will complain.
2775 if (XSym->getSymbolTableName() == "_$TLSML")
2776 return XCOFF::XMC_TC;
2777
2778 // Use large code model toc entries for ehinfo symbols as they are
2779 // never referenced directly. The runtime loads their TOC entry
2780 // addresses from the trace-back table.
2781 if (XSym->isEHInfo())
2782 return XCOFF::XMC_TE;
2783
2784 // If the symbol does not have a code model specified use the module value.
2785 if (!XSym->hasPerSymbolCodeModel())
2786 return TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE
2787 : XCOFF::XMC_TC;
2788
2789 return XSym->getPerSymbolCodeModel() == MCSymbolXCOFF::CM_Large
2791 : XCOFF::XMC_TC;
2792 }(Sym, TM);
2793
2794 return getContext().getXCOFFSection(
2795 static_cast<const MCSymbolXCOFF *>(Sym)->getSymbolTableName(),
2797}
2798
2800 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2801 auto *LSDA = static_cast<MCSectionXCOFF *>(LSDASection);
2802 if (TM.getFunctionSections()) {
2803 // If option -ffunction-sections is on, append the function name to the
2804 // name of the LSDA csect so that each function has its own LSDA csect.
2805 // This helps the linker to garbage-collect EH info of unused functions.
2806 SmallString<128> NameStr = LSDA->getName();
2807 raw_svector_ostream(NameStr) << '.' << F.getName();
2808 LSDA = getContext().getXCOFFSection(NameStr, LSDA->getKind(),
2809 LSDA->getCsectProp());
2810 }
2811 return LSDA;
2812}
2813//===----------------------------------------------------------------------===//
2814// GOFF
2815//===----------------------------------------------------------------------===//
2817
2819 // Construct the default names for the root SD and the ADA PR symbol.
2820 StringRef FileName = sys::path::stem(M.getSourceFileName());
2821 if (FileName.size() > 1 && FileName.starts_with('<') &&
2822 FileName.ends_with('>'))
2823 FileName = FileName.substr(1, FileName.size() - 2);
2824 DefaultRootSDName = Twine(FileName).concat("#C").str();
2825 DefaultADAPRName = Twine(FileName).concat("#S").str();
2826 MCSectionGOFF *RootSD =
2827 static_cast<MCSectionGOFF *>(TextSection)->getParent();
2828 MCSectionGOFF *ADAPR = static_cast<MCSectionGOFF *>(ADASection);
2829 RootSD->setName(DefaultRootSDName);
2830 ADAPR->setName(DefaultADAPRName);
2831 // Initialize the label for the text section.
2832 MCSymbolGOFF *TextLD = static_cast<MCSymbolGOFF *>(
2833 getContext().getOrCreateSymbol(RootSD->getName()));
2836 TextLD->setExternal(false);
2837 TextLD->setWeak(false);
2838 TextLD->setADA(ADAPR);
2839 TextSection->setBeginSymbol(TextLD);
2840 // Initialize the label for the ADA section.
2841 MCSymbolGOFF *ADASym = static_cast<MCSymbolGOFF *>(
2843 ADAPR->setBeginSymbol(ADASym);
2844}
2845
2847 bool UsesLabelDifference, const Function &F) const {
2848 return true;
2849}
2850
2855
2857 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2858 std::string Name = ".gcc_exception_table." + F.getName().str();
2859
2860 MCSectionGOFF *WSA = getContext().getGOFFSection(
2866 static_cast<MCSectionGOFF *>(TextSection)->getParent());
2867 return getContext().getGOFFSection(SectionKind::getData(), Name,
2871 WSA);
2872}
2873
2875 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2876 auto *Symbol = TM.getSymbol(GO);
2877
2878 if (Kind.isBSS() || Kind.isData()) {
2879 GOFF::ESDBindingScope PRBindingScope =
2880 GO->hasExternalLinkage()
2884 GOFF::ESDBindingScope SDBindingScope =
2887 MaybeAlign Alignment;
2888 if (auto *F = dyn_cast<Function>(GO))
2889 Alignment = F->getAlign();
2890 else if (auto *V = dyn_cast<GlobalVariable>(GO))
2891 Alignment = V->getAlign();
2893 Alignment ? static_cast<GOFF::ESDAlignment>(Log2(*Alignment))
2895 MCSectionGOFF *SD = getContext().getGOFFSection(
2896 SectionKind::getMetadata(), Symbol->getName(),
2897 GOFF::SDAttr{GOFF::ESD_TA_Unspecified, SDBindingScope});
2898 MCSectionGOFF *ED = getContext().getGOFFSection(
2903 SD);
2904 return getContext().getGOFFSection(Kind, Symbol->getName(),
2905 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
2906 GOFF::ESD_LT_XPLink,
2907 PRBindingScope, 0},
2908 ED);
2909 }
2910 return TextSection;
2911}
2912
2913MCSection *
2915 // XL C/C++ compilers on z/OS support priorities from min-int to max-int, with
2916 // sinit as source priority 0. For clang, sinit has source priority 65535.
2917 // For GOFF, the priority sortkey field is an unsigned value. So, we
2918 // add min-int to get sorting to work properly but also subtract the
2919 // clang sinit (65535) value so internally xl sinit and clang sinit have
2920 // the same unsigned GOFF priority sortkey field value (i.e. 0x80000000).
2921 static constexpr const uint32_t ClangDefaultSinitPriority = 65535;
2922 uint32_t Prio = Priority + (0x80000000 - ClangDefaultSinitPriority);
2923
2924 std::string Name(".xtor");
2925 if (Priority != ClangDefaultSinitPriority)
2926 Name = llvm::Twine(Name).concat(".").concat(llvm::utostr(Priority)).str();
2927
2928 MCContext &Ctx = getContext();
2929 MCSectionGOFF *SInit = Ctx.getGOFFSection(
2935 static_cast<const MCSectionGOFF *>(TextSection)->getParent());
2936
2937 MCSectionGOFF *Xtor = Ctx.getGOFFSection(
2938 SectionKind::getData(), Name,
2940 GOFF::ESD_BSC_Section, Prio},
2941 SInit);
2942 return Xtor;
2943}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static bool isThumb(const MCSubtargetInfo &STI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_LIFETIME_BOUND
Definition Compiler.h:435
This file contains the declarations for the subclasses of Constant, which represent the different fla...
@ Default
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...
This file contains the MCSymbolGOFF class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define T
This file defines the SmallString class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
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 std::tuple< StringRef, bool, unsigned, unsigned, unsigned > getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM, StringRef SectionName, SectionKind Kind)
static unsigned getWasmSectionFlags(SectionKind K, bool Retain)
static void checkMachOComdat(const GlobalValue *GV)
static std::string APIntToHexString(const APInt &AI)
static unsigned getELFSectionFlags(SectionKind K, const Triple &T)
static SmallString< 128 > getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool UniqueSectionName, const MachineJumpTableEntry *JTE)
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 std::string scalarConstantToHexString(const Constant *C)
static StringRef getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
static const Comdat * getELFComdat(const GlobalValue *GV)
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol, const MachineJumpTableEntry *MJTE=nullptr)
Class for arbitrary precision integers.
Definition APInt.h:78
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1511
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:201
@ Largest
The linker will choose the largest COMDAT.
Definition Comdat.h:39
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition Comdat.h:41
@ Any
The linker may choose any COMDAT.
Definition Comdat.h:37
@ NoDeduplicate
No deduplication is performed.
Definition Comdat.h:40
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition Comdat.h:38
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
StringRef getInternalSymbolPrefix() const
Definition DataLayout.h:308
LLVM_ABI Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
This is the base abstract class for diagnostic reporting in the backend.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasMetadata() const
Return true if this GlobalObject has any metadata attached to it.
bool hasComdat() const
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
bool hasSection() const
Check if this global has a custom object file section.
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 hasDefaultVisibility() const
bool hasPrivateLinkage() const
LLVM_ABI const Comdat * getComdat() const
Definition Globals.cpp:210
ThreadLocalMode getThreadLocalMode() const
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:450
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:141
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.
Definition GlobalValue.h:61
@ CommonLinkage
Tentative definitions.
Definition GlobalValue.h:63
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition GlobalValue.h:55
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:58
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition GlobalValue.h:57
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition GlobalValue.h:59
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition GlobalValue.h:62
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:56
AttributeSet getAttributes() const
Return the attribute set for this global.
bool hasImplicitSection() const
Check if section name is present.
LLVM_ABI 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...
Definition MCAsmInfo.h:64
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:343
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI 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.
LLVM_ABI MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=MCSection::NonUniqueID)
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition MCContext.h:638
LLVM_ABI 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)
Definition MCContext.h:550
LLVM_ABI MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * MergeableConst16Section
MCSection * TextSection
Section directive for standard text.
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCSection * FourByteConstantSection
MCSection * getDrectveSection() const
bool isPositionIndependent() const
MCSection * MergeableConst32Section
MCSection * SixteenByteConstantSection
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
MCSection * BSSSection
Section that is default initialized to zero.
MCSection * EightByteConstantSection
MCContext & getContext() const
MCSection * DataSection
Section directive for standard data.
This represents a section on Windows.
MCSymbol * getCOMDATSymbol() const
This represents a section on linux, lots of unix variants and some bare metal systems.
unsigned getFlags() const
void setName(StringRef SectionName)
MCSectionGOFF * getParent() const
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.
Definition MCSection.h:573
static constexpr unsigned NonUniqueID
Definition MCSection.h:578
void setBeginSymbol(MCSymbol *Sym)
Definition MCSection.h:650
StringRef getName() const
Definition MCSection.h:643
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
Definition MCStreamer.h:415
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 Fill=0, uint8_t FillLen=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.
Definition MCStreamer.h:499
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)
Definition MCStreamer.h:757
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:428
void emitInt8(uint64_t Value)
Definition MCStreamer.h:755
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
void setWeak(bool Value=true)
void setExternal(bool Value) const
void setCodeData(GOFF::ESDExecutable Value)
void setADA(MCSectionGOFF *AssociatedDataArea)
void setLinkage(GOFF::ESDLinkageType Value)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
void setEHInfo() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
int64_t getConstant() const
Definition MCValue.h:44
const MCSymbol * getSubSym() const
Definition MCValue.h:51
Metadata node.
Definition Metadata.h:1080
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1444
Metadata * get() const
Definition Metadata.h:931
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current 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.
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.
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition Mangler.cpp:121
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition Module.h:133
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition Module.h:263
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition Module.cpp:177
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:278
A tuple of MDNodes.
Definition Metadata.h:1760
PointerTy getPointer() const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
static SectionKind getThreadData()
static SectionKind getMetadata()
bool isThreadBSSLocal() const
static SectionKind getText()
bool isBSSLocal() const
static SectionKind getData()
bool isText() const
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...
Definition SmallString.h:26
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.
Definition StringRef.h:55
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:591
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:140
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition StringRef.h:270
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...
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.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, const TargetMachine &TM) 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 * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
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 * 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
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
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.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * lowerSymbolDifference(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset) const
const MCExpr * lowerDSOLocalEquivalent(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, 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
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
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 * getStaticXtorSection(unsigned Priority) const
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
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) 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 * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
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
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.
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
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
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)
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
MCSection * getSectionForFunctionDescriptor(const GlobalObject *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.
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
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) 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...
void emitPseudoProbeDescMetadata(MCStreamer &Streamer, Module &M, std::function< void(MCStreamer &Streamer)> COMDATSymEmitter=nullptr) const
Emit pseudo_probe_desc metadata.
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 getSeparateNamedSections() const
bool getUniqueSectionNames() const
TargetOptions Options
MCSymbol * getSymbol(const GlobalValue *GV) const
CodeModel::Model getCodeModel() const
Returns the code model.
bool isLargeGlobalValue(const GlobalValue *GV) const
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ loongarch32
Definition Triple.h:64
@ loongarch64
Definition Triple.h:65
bool isOSSolaris() const
Definition Triple.h:675
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:435
bool isOSFreeBSD() const
Definition Triple.h:669
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
Twine concat(const Twine &Suffix) const
Definition Twine.h:497
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
bool hasName() const
Definition Value.h:261
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:318
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
CallInst * Retain
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.
SectionCharacteristics
Definition COFF.h:298
@ IMAGE_SCN_LNK_REMOVE
Definition COFF.h:308
@ IMAGE_SCN_CNT_CODE
Definition COFF.h:303
@ IMAGE_SCN_MEM_READ
Definition COFF.h:336
@ IMAGE_SCN_MEM_EXECUTE
Definition COFF.h:335
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition COFF.h:305
@ IMAGE_SCN_MEM_DISCARDABLE
Definition COFF.h:331
@ IMAGE_SCN_MEM_16BIT
Definition COFF.h:312
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition COFF.h:304
@ IMAGE_SCN_LNK_COMDAT
Definition COFF.h:309
@ IMAGE_SCN_MEM_WRITE
Definition COFF.h:337
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition COFF.h:455
@ IMAGE_COMDAT_SELECT_LARGEST
Definition COFF.h:460
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition COFF.h:457
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition COFF.h:459
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition COFF.h:458
@ IMAGE_COMDAT_SELECT_ANY
Definition COFF.h:456
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ SHF_MERGE
Definition ELF.h:1255
@ SHF_STRINGS
Definition ELF.h:1258
@ SHF_AARCH64_PURECODE
Definition ELF.h:1347
@ SHF_EXCLUDE
Definition ELF.h:1283
@ SHF_ALLOC
Definition ELF.h:1249
@ SHF_LINK_ORDER
Definition ELF.h:1264
@ SHF_GROUP
Definition ELF.h:1271
@ SHF_SUNW_NODISCARD
Definition ELF.h:1290
@ SHF_X86_64_LARGE
Definition ELF.h:1312
@ SHF_GNU_RETAIN
Definition ELF.h:1280
@ SHF_WRITE
Definition ELF.h:1246
@ SHF_TLS
Definition ELF.h:1274
@ SHF_ARM_PURECODE
Definition ELF.h:1344
@ SHF_EXECINSTR
Definition ELF.h:1252
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition ELF.h:1179
@ SHT_PROGBITS
Definition ELF.h:1148
@ SHT_LLVM_LINKER_OPTIONS
Definition ELF.h:1176
@ SHT_NOBITS
Definition ELF.h:1155
@ SHT_LLVM_OFFLOADING
Definition ELF.h:1187
@ SHT_LLVM_LTO
Definition ELF.h:1188
@ SHT_PREINIT_ARRAY
Definition ELF.h:1161
@ SHT_INIT_ARRAY
Definition ELF.h:1159
@ SHT_NOTE
Definition ELF.h:1154
@ SHT_FINI_ARRAY
Definition ELF.h:1160
@ ESD_LB_Deferred
Definition GOFF.h:129
@ ESD_LB_Initial
Definition GOFF.h:128
constexpr StringLiteral CLASS_WSA
@ ESD_BA_Merge
Definition GOFF.h:99
@ ESD_TS_ByteOriented
Definition GOFF.h:92
@ ESD_EXE_CODE
Definition GOFF.h:112
@ ESD_EXE_DATA
Definition GOFF.h:111
@ ESD_RQ_0
Definition GOFF.h:69
ESDAlignment
Definition GOFF.h:144
@ ESD_ALIGN_Doubleword
Definition GOFF.h:148
@ ESD_ALIGN_Fullword
Definition GOFF.h:147
ESDBindingScope
Definition GOFF.h:134
@ ESD_BSC_Library
Definition GOFF.h:138
@ ESD_BSC_Unspecified
Definition GOFF.h:135
@ ESD_BSC_ImportExport
Definition GOFF.h:139
@ ESD_BSC_Section
Definition GOFF.h:136
constexpr StringLiteral CLASS_SINIT
@ ESD_LT_XPLink
Definition GOFF.h:142
@ ESD_NS_Parts
Definition GOFF.h:65
@ ESD_RMODE_64
Definition GOFF.h:88
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition MachO.h:150
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition MachO.h:147
@ C_WEAKEXT
Definition XCOFF.h:200
StorageMappingClass
Storage Mapping Class definitions.
Definition XCOFF.h:104
@ XMC_TE
Symbol mapped at the end of TOC.
Definition XCOFF.h:129
@ XMC_DS
Descriptor csect.
Definition XCOFF.h:122
@ XMC_RW
Read Write Data.
Definition XCOFF.h:118
@ XMC_TL
Initialized thread-local variable.
Definition XCOFF.h:127
@ XMC_RO
Read Only Constant.
Definition XCOFF.h:107
@ XMC_UA
Unclassified - Treated as Read Write.
Definition XCOFF.h:123
@ XMC_TD
Scalar data item in the TOC.
Definition XCOFF.h:121
@ XMC_UL
Uninitialized thread-local variable.
Definition XCOFF.h:128
@ XMC_PR
Program Code.
Definition XCOFF.h:106
@ XMC_BS
BSS class (uninitialized static internal)
Definition XCOFF.h:124
@ XMC_TC
General TOC item.
Definition XCOFF.h:120
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition XCOFF.h:246
@ XTY_SD
Csect definition for initialized storage.
Definition XCOFF.h:243
@ XTY_ER
External reference.
Definition XCOFF.h:242
initializer< Ty > init(const Ty &Val)
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
@ DW_EH_PE_datarel
Definition Dwarf.h:881
@ DW_EH_PE_pcrel
Definition Dwarf.h:879
@ DW_EH_PE_sdata4
Definition Dwarf.h:876
@ DW_EH_PE_sdata8
Definition Dwarf.h:877
@ DW_EH_PE_absptr
Definition Dwarf.h:868
@ DW_EH_PE_udata4
Definition Dwarf.h:872
@ DW_EH_PE_udata8
Definition Dwarf.h:873
@ DW_EH_PE_indirect
Definition Dwarf.h:884
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition Metadata.h:696
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:668
LLVM_ABI StringRef stem(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get stem.
Definition Path.cpp:586
@ WASM_SEG_FLAG_RETAIN
Definition Wasm.h:240
@ WASM_SEG_FLAG_TLS
Definition Wasm.h:239
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:238
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
std::string utostr(uint64_t X, bool isNeg=false)
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
LLVM_ABI std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
@ DK_Lowering
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.
Definition STLExtras.h:2025
std::string encodeBase64(InputBytes const &Bytes)
Definition Base64.h:24
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
LLVM_ABI void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
Definition Mangler.cpp:278
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
DWARFExpression::Operation Op
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
LLVM_ABI void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
Definition Mangler.cpp:214
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197
cl::opt< std::string > BBSectionsColdTextPrefix
@ MCSA_Weak
.weak
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_Hidden
.hidden (ELF)
LLVM_ABI 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 ...
Definition Module.cpp:875
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
LLVM_ABI static const MBBSectionID ExceptionSectionID
LLVM_ABI static const MBBSectionID ColdSectionID
MachineJumpTableEntry - One jump table in the jump table info.
MachineFunctionDataHotness Hotness
The hotness of MJTE is inferred from the hotness of the source basic block(s) that reference it.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106