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:
155 CM = CodeModel::Large;
156 if (isPositionIndependent()) {
158 ((CM == CodeModel::Small || CM == CodeModel::Medium)
161 (CM == CodeModel::Small
164 ((CM == CodeModel::Small || CM == CodeModel::Medium)
166 } else {
168 (CM == CodeModel::Small || CM == CodeModel::Medium)
174 }
175 break;
176 case Triple::hexagon:
180 if (isPositionIndependent()) {
184 }
185 break;
186 case Triple::aarch64:
189 // The small model guarantees static code/data size < 4GB, but not where it
190 // will be in memory. Most of these could end up >2GB away so even a signed
191 // pc-relative 32-bit address is insufficient, theoretically.
192 //
193 // Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
195 (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32
200 break;
201 case Triple::lanai:
205 break;
206 case Triple::mips:
207 case Triple::mipsel:
208 case Triple::mips64:
209 case Triple::mips64el:
210 // MIPS uses indirect pointer to refer personality functions and types, so
211 // that the eh_frame section can be read-only. DW.ref.personality will be
212 // generated for relocation.
214 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
215 // identify N64 from just a triple.
218
219 // FreeBSD must be explicit about the data size and using pcrel since it's
220 // assembler/linker won't do the automatic conversion that the Linux tools
221 // do.
225 }
226 break;
227 case Triple::ppc64:
228 case Triple::ppc64le:
234 break;
235 case Triple::sparcel:
236 case Triple::sparc:
237 if (isPositionIndependent()) {
243 } else {
247 }
249 break;
250 case Triple::riscv32:
251 case Triple::riscv64:
260 break;
261 case Triple::sparcv9:
263 if (isPositionIndependent()) {
268 } else {
271 }
272 break;
273 case Triple::systemz:
274 // All currently-defined code models guarantee that 4-byte PC-relative
275 // values will be in range.
276 if (isPositionIndependent()) {
282 } else {
286 }
287 break;
295 break;
296 default:
297 break;
298 }
299}
300
303 collectUsedGlobalVariables(M, Vec, false);
304 for (GlobalValue *GV : Vec)
305 if (auto *GO = dyn_cast<GlobalObject>(GV))
306 Used.insert(GO);
307}
308
310 Module &M) const {
311 auto &C = getContext();
312
313 emitLinkerDirectives(Streamer, M);
314
315 if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
316 auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
318
319 Streamer.switchSection(S);
320
321 for (const auto *Operand : DependentLibraries->operands()) {
322 Streamer.emitBytes(
323 cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
324 Streamer.emitInt8(0);
325 }
326 }
327
328 emitPseudoProbeDescMetadata(Streamer, M);
329
330 if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
331 // Emit the metadata for llvm statistics into .llvm_stats section, which is
332 // formatted as a list of key/value pair, the value is base64 encoded.
333 auto *S = C.getObjectFileInfo()->getLLVMStatsSection();
334 Streamer.switchSection(S);
335 for (const auto *Operand : LLVMStats->operands()) {
336 const auto *MD = cast<MDNode>(Operand);
337 assert(MD->getNumOperands() % 2 == 0 &&
338 ("Operand num should be even for a list of key/value pair"));
339 for (size_t I = 0; I < MD->getNumOperands(); I += 2) {
340 // Encode the key string size.
341 auto *Key = cast<MDString>(MD->getOperand(I));
342 Streamer.emitULEB128IntValue(Key->getString().size());
343 Streamer.emitBytes(Key->getString());
344 // Encode the value into a Base64 string.
345 std::string Value = encodeBase64(
346 Twine(mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1))
347 ->getZExtValue())
348 .str());
349 Streamer.emitULEB128IntValue(Value.size());
350 Streamer.emitBytes(Value);
351 }
352 }
353 }
354
355 unsigned Version = 0;
356 unsigned Flags = 0;
357 StringRef Section;
358
359 GetObjCImageInfo(M, Version, Flags, Section);
360 if (!Section.empty()) {
361 auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
362 Streamer.switchSection(S);
363 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
364 Streamer.emitInt32(Version);
365 Streamer.emitInt32(Flags);
366 Streamer.addBlankLine();
367 }
368
369 emitCGProfileMetadata(Streamer, M);
370}
371
373 Module &M) const {
374 auto &C = getContext();
375 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
376 auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS,
378
379 Streamer.switchSection(S);
380
381 for (const auto *Operand : LinkerOptions->operands()) {
382 if (cast<MDNode>(Operand)->getNumOperands() != 2)
383 report_fatal_error("invalid llvm.linker.options");
384 for (const auto &Option : cast<MDNode>(Operand)->operands()) {
385 Streamer.emitBytes(cast<MDString>(Option)->getString());
386 Streamer.emitInt8(0);
387 }
388 }
389 }
390}
391
393 const GlobalValue *GV, const TargetMachine &TM,
394 MachineModuleInfo *MMI) const {
395 unsigned Encoding = getPersonalityEncoding();
396 if ((Encoding & 0x80) == DW_EH_PE_indirect)
397 return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
398 TM.getSymbol(GV)->getName());
399 if ((Encoding & 0x70) == DW_EH_PE_absptr)
400 return TM.getSymbol(GV);
401 report_fatal_error("We do not support this DWARF encoding yet!");
402}
403
405 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
406 const MachineModuleInfo *MMI) const {
407 SmallString<64> NameData("DW.ref.");
408 NameData += Sym->getName();
409 auto *Label =
410 static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(NameData));
411 Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
412 Streamer.emitSymbolAttribute(Label, MCSA_Weak);
413 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
414 MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
415 ELF::SHT_PROGBITS, Flags, 0);
416 unsigned Size = DL.getPointerSize();
417 Streamer.switchSection(Sec);
418 Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0));
421 Streamer.emitELFSize(Label, E);
422 Streamer.emitLabel(Label);
423
424 emitPersonalityValueImpl(Streamer, DL, Sym, MMI);
425}
426
428 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
429 const MachineModuleInfo *MMI) const {
430 Streamer.emitSymbolValue(Sym, DL.getPointerSize());
431}
432
434 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
435 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
436 if (Encoding & DW_EH_PE_indirect) {
438
439 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
440
441 // Add information about the stub reference to ELFMMI so that the stub
442 // gets emitted by the asmprinter.
444 if (!StubSym.getPointer()) {
445 MCSymbol *Sym = TM.getSymbol(GV);
447 }
448
451 Encoding & ~DW_EH_PE_indirect, Streamer);
452 }
453
455 MMI, Streamer);
456}
457
459 // N.B.: The defaults used in here are not the same ones used in MC.
460 // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
461 // both gas and MC will produce a section with no flags. Given
462 // section(".eh_frame") gcc will produce:
463 //
464 // .section .eh_frame,"a",@progbits
465
466 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
467 /*AddSegmentInfo=*/false) ||
468 Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
469 /*AddSegmentInfo=*/false) ||
470 Name == getInstrProfSectionName(IPSK_covdata, Triple::ELF,
471 /*AddSegmentInfo=*/false) ||
472 Name == getInstrProfSectionName(IPSK_covname, Triple::ELF,
473 /*AddSegmentInfo=*/false) ||
474 Name == ".llvmbc" || Name == ".llvmcmd")
476
477 if (!Name.starts_with(".")) return K;
478
479 // Default implementation based on some magic section names.
480 if (Name == ".bss" || Name.starts_with(".bss.") ||
481 Name.starts_with(".gnu.linkonce.b.") ||
482 Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
483 Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||
484 Name.starts_with(".llvm.linkonce.sb."))
485 return SectionKind::getBSS();
486
487 if (Name == ".tdata" || Name.starts_with(".tdata.") ||
488 Name.starts_with(".gnu.linkonce.td.") ||
489 Name.starts_with(".llvm.linkonce.td."))
491
492 if (Name == ".tbss" || Name.starts_with(".tbss.") ||
493 Name.starts_with(".gnu.linkonce.tb.") ||
494 Name.starts_with(".llvm.linkonce.tb."))
496
497 return K;
498}
499
501 return SectionName.consume_front(Prefix) &&
502 (SectionName.empty() || SectionName[0] == '.');
503}
504
505static unsigned getELFSectionType(StringRef Name, SectionKind K) {
506 // Use SHT_NOTE for section whose name starts with ".note" to allow
507 // emitting ELF notes from C variable declaration.
508 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
509 if (Name.starts_with(".note"))
510 return ELF::SHT_NOTE;
511
512 if (hasPrefix(Name, ".init_array"))
513 return ELF::SHT_INIT_ARRAY;
514
515 if (hasPrefix(Name, ".fini_array"))
516 return ELF::SHT_FINI_ARRAY;
517
518 if (hasPrefix(Name, ".preinit_array"))
520
521 if (hasPrefix(Name, ".llvm.offloading"))
523 if (Name == ".llvm.lto")
524 return ELF::SHT_LLVM_LTO;
525
526 if (K.isBSS() || K.isThreadBSS())
527 return ELF::SHT_NOBITS;
528
529 return ELF::SHT_PROGBITS;
530}
531
532static unsigned getELFSectionFlags(SectionKind K, const Triple &T) {
533 unsigned Flags = 0;
534
535 if (!K.isMetadata() && !K.isExclude())
536 Flags |= ELF::SHF_ALLOC;
537
538 if (K.isExclude())
539 Flags |= ELF::SHF_EXCLUDE;
540
541 if (K.isText())
542 Flags |= ELF::SHF_EXECINSTR;
543
544 if (K.isExecuteOnly()) {
545 if (T.isAArch64())
547 else if (T.isARM() || T.isThumb())
548 Flags |= ELF::SHF_ARM_PURECODE;
549 }
550
551 if (K.isWriteable())
552 Flags |= ELF::SHF_WRITE;
553
554 if (K.isThreadLocal())
555 Flags |= ELF::SHF_TLS;
556
557 if (K.isMergeableCString() || K.isMergeableConst())
558 Flags |= ELF::SHF_MERGE;
559
560 if (K.isMergeableCString())
561 Flags |= ELF::SHF_STRINGS;
562
563 return Flags;
564}
565
566static const Comdat *getELFComdat(const GlobalValue *GV) {
567 const Comdat *C = GV->getComdat();
568 if (!C)
569 return nullptr;
570
571 if (C->getSelectionKind() != Comdat::Any &&
572 C->getSelectionKind() != Comdat::NoDeduplicate)
573 report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
574 "SelectionKind::NoDeduplicate, '" +
575 C->getName() + "' cannot be lowered.");
576
577 return C;
578}
579
581 const TargetMachine &TM) {
582 MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
583 if (!MD)
584 return nullptr;
585
586 auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
587 auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
588 return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV))
589 : nullptr;
590}
591
592static unsigned getEntrySizeForKind(SectionKind Kind) {
593 if (Kind.isMergeable1ByteCString())
594 return 1;
595 else if (Kind.isMergeable2ByteCString())
596 return 2;
597 else if (Kind.isMergeable4ByteCString())
598 return 4;
599 else if (Kind.isMergeableConst4())
600 return 4;
601 else if (Kind.isMergeableConst8())
602 return 8;
603 else if (Kind.isMergeableConst16())
604 return 16;
605 else if (Kind.isMergeableConst32())
606 return 32;
607 else {
608 // We shouldn't have mergeable C strings or mergeable constants that we
609 // didn't handle above.
610 assert(!Kind.isMergeableCString() && "unknown string width");
611 assert(!Kind.isMergeableConst() && "unknown data width");
612 return 0;
613 }
614}
615
616/// Return the section prefix name used by options FunctionsSections and
617/// DataSections.
619 if (Kind.isText())
620 return IsLarge ? ".ltext" : ".text";
621 if (Kind.isReadOnly())
622 return IsLarge ? ".lrodata" : ".rodata";
623 if (Kind.isBSS())
624 return IsLarge ? ".lbss" : ".bss";
625 if (Kind.isThreadData())
626 return ".tdata";
627 if (Kind.isThreadBSS())
628 return ".tbss";
629 if (Kind.isData())
630 return IsLarge ? ".ldata" : ".data";
631 if (Kind.isReadOnlyWithRel())
632 return IsLarge ? ".ldata.rel.ro" : ".data.rel.ro";
633 llvm_unreachable("Unknown section kind");
634}
635
636static SmallString<128>
638 Mangler &Mang, const TargetMachine &TM,
639 bool UniqueSectionName,
640 const MachineJumpTableEntry *JTE) {
641 SmallString<128> Name =
643 unsigned EntrySize = getEntrySizeForKind(Kind);
644 if (Kind.isMergeableCString()) {
645 // We also need alignment here.
646 // FIXME: this is getting the alignment of the character, not the
647 // alignment of the global!
648 Align Alignment = GO->getDataLayout().getPreferredAlign(
650
651 Name += ".str";
652 Name += utostr(EntrySize);
653 Name += ".";
654 Name += utostr(Alignment.value());
655 } else if (Kind.isMergeableConst()) {
656 Name += ".cst";
657 Name += utostr(EntrySize);
658 }
659
660 bool HasPrefix = false;
661 if (const auto *F = dyn_cast<Function>(GO)) {
662 // Jump table hotness takes precedence over its enclosing function's hotness
663 // if it's known. The function's section prefix is used if jump table entry
664 // hotness is unknown.
665 if (JTE && JTE->Hotness != MachineFunctionDataHotness::Unknown) {
667 raw_svector_ostream(Name) << ".hot";
668 } else {
670 "Hotness must be cold");
671 raw_svector_ostream(Name) << ".unlikely";
672 }
673 HasPrefix = true;
674 } else if (std::optional<StringRef> Prefix = F->getSectionPrefix()) {
675 raw_svector_ostream(Name) << '.' << *Prefix;
676 HasPrefix = true;
677 }
678 } else if (const auto *GV = dyn_cast<GlobalVariable>(GO)) {
679 if (std::optional<StringRef> Prefix = GV->getSectionPrefix()) {
680 raw_svector_ostream(Name) << '.' << *Prefix;
681 HasPrefix = true;
682 }
683 }
684
685 if (UniqueSectionName) {
686 Name.push_back('.');
687 TM.getNameWithPrefix(Name, GO, Mang, /*MayAlwaysUsePrivate*/true);
688 } else if (HasPrefix)
689 // For distinguishing between .text.${text-section-prefix}. (with trailing
690 // dot) and .text.${function-name}
691 Name.push_back('.');
692 return Name;
693}
694
695namespace {
696class LoweringDiagnosticInfo : public DiagnosticInfo {
697 const Twine &Msg;
698
699public:
700 LoweringDiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND,
701 DiagnosticSeverity Severity = DS_Error)
702 : DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
703 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
704};
705}
706
707/// Calculate an appropriate unique ID for a section, and update Flags,
708/// EntrySize and NextUniqueID where appropriate.
709static unsigned
711 SectionKind Kind, const TargetMachine &TM,
712 MCContext &Ctx, Mangler &Mang, unsigned &Flags,
713 unsigned &EntrySize, unsigned &NextUniqueID,
714 const bool Retain, const bool ForceUnique) {
715 // Increment uniqueID if we are forced to emit a unique section.
716 // This works perfectly fine with section attribute or pragma section as the
717 // sections with the same name are grouped together by the assembler.
718 if (ForceUnique)
719 return NextUniqueID++;
720
721 // A section can have at most one associated section. Put each global with
722 // MD_associated in a unique section.
723 const bool Associated = GO->getMetadata(LLVMContext::MD_associated);
724 if (Associated) {
725 Flags |= ELF::SHF_LINK_ORDER;
726 return NextUniqueID++;
727 }
728
729 if (Retain) {
730 if (TM.getTargetTriple().isOSSolaris())
732 else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
733 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36))
734 Flags |= ELF::SHF_GNU_RETAIN;
735 return NextUniqueID++;
736 }
737
738 // If two symbols with differing sizes end up in the same mergeable section
739 // that section can be assigned an incorrect entry size. To avoid this we
740 // usually put symbols of the same size into distinct mergeable sections with
741 // the same name. Doing so relies on the ",unique ," assembly feature. This
742 // feature is not available until binutils version 2.35
743 // (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
744 const bool SupportsUnique = Ctx.getAsmInfo().useIntegratedAssembler() ||
745 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35);
746 if (!SupportsUnique) {
747 Flags &= ~ELF::SHF_MERGE;
748 EntrySize = 0;
750 }
751
752 const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
753 const bool SeenSectionNameBefore =
754 Ctx.isELFGenericMergeableSection(SectionName);
755 // If this is the first occurrence of this section name, treat it as the
756 // generic section
757 if (!SymbolMergeable && !SeenSectionNameBefore) {
759 return NextUniqueID++;
760 else
762 }
763
764 // Symbols must be placed into sections with compatible entry sizes. Generate
765 // unique sections for symbols that have not been assigned to compatible
766 // sections.
767 const auto PreviousID =
768 Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
769 if (PreviousID &&
770 (!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
771 return *PreviousID;
772
773 // If the user has specified the same section name as would be created
774 // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
775 // to unique the section as the entry size for this symbol will be
776 // compatible with implicitly created sections.
777 SmallString<128> ImplicitSectionNameStem =
778 getELFSectionNameForGlobal(GO, Kind, Mang, TM, false, /*MJTE=*/nullptr);
779 if (SymbolMergeable &&
780 Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
781 SectionName.starts_with(ImplicitSectionNameStem))
783
784 // We have seen this section name before, but with different flags or entity
785 // size. Create a new unique ID.
786 return NextUniqueID++;
787}
788
789static std::tuple<StringRef, bool, unsigned, unsigned, unsigned>
792 StringRef Group = "";
793 bool IsComdat = false;
794 unsigned Flags = 0;
795 if (const Comdat *C = getELFComdat(GO)) {
796 Flags |= ELF::SHF_GROUP;
797 Group = C->getName();
798 IsComdat = C->getSelectionKind() == Comdat::Any;
799 }
800 if (TM.isLargeGlobalValue(GO))
801 Flags |= ELF::SHF_X86_64_LARGE;
802
803 unsigned Type, EntrySize;
804 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_elf_section_properties)) {
805 Type = cast<ConstantAsMetadata>(MD->getOperand(0))
806 ->getValue()
807 ->getUniqueInteger()
808 .getZExtValue();
809 EntrySize = cast<ConstantAsMetadata>(MD->getOperand(1))
810 ->getValue()
811 ->getUniqueInteger()
812 .getZExtValue();
813 } else {
815 EntrySize = getEntrySizeForKind(Kind);
816 }
817
818 return {Group, IsComdat, Flags, Type, EntrySize};
819}
820
822 SectionKind Kind) {
823 // Check if '#pragma clang section' name is applicable.
824 // Note that pragma directive overrides -ffunction-section, -fdata-section
825 // and so section name is exactly as user specified and not uniqued.
827 if (GV && GV->hasImplicitSection()) {
828 auto Attrs = GV->getAttributes();
829 if (Attrs.hasAttribute("bss-section") && Kind.isBSS())
830 return Attrs.getAttribute("bss-section").getValueAsString();
831 else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())
832 return Attrs.getAttribute("rodata-section").getValueAsString();
833 else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel())
834 return Attrs.getAttribute("relro-section").getValueAsString();
835 else if (Attrs.hasAttribute("data-section") && Kind.isData())
836 return Attrs.getAttribute("data-section").getValueAsString();
837 }
838
839 return GO->getSection();
840}
841
843 SectionKind Kind,
844 const TargetMachine &TM,
845 MCContext &Ctx, Mangler &Mang,
846 unsigned &NextUniqueID,
847 bool Retain, bool ForceUnique) {
849
850 // Infer section flags from the section name if we can.
852
853 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
854 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
855 getGlobalObjectInfo(GO, TM, SectionName, Kind);
856 Flags |= ExtraFlags;
857
859 GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
860 Retain, ForceUnique);
861
862 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
863 MCSectionELF *Section =
864 Ctx.getELFSection(SectionName, Type, Flags, EntrySize, Group, IsComdat,
865 UniqueID, LinkedToSym);
866 // Make sure that we did not get some other section with incompatible sh_link.
867 // This should not be possible due to UniqueID code above.
868 assert(Section->getLinkedToSymbol() == LinkedToSym &&
869 "Associated symbol mismatch between sections");
870
871 if (!(Ctx.getAsmInfo().useIntegratedAssembler() ||
872 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35))) {
873 // If we are using GNU as before 2.35, then this symbol might have
874 // been placed in an incompatible mergeable section. Emit an error if this
875 // is the case to avoid creating broken output.
876 if ((Section->getFlags() & ELF::SHF_MERGE) &&
877 (Section->getEntrySize() != getEntrySizeForKind(Kind)))
878 GO->getContext().diagnose(LoweringDiagnosticInfo(
879 "Symbol '" + GO->getName() + "' from module '" +
880 (GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
881 "' required a section with entry-size=" +
882 Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
883 SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
884 ": Explicit assignment by pragma or attribute of an incompatible "
885 "symbol to this section?"));
886 }
887
888 return Section;
889}
890
892 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
894 NextUniqueID, Used.count(GO),
895 /* ForceUnique = */false);
896}
897
899 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
900 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
901 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol,
902 const MachineJumpTableEntry *MJTE = nullptr) {
903 bool UniqueSectionName = false;
905 if (EmitUniqueSection) {
906 if (TM.getUniqueSectionNames()) {
907 UniqueSectionName = true;
908 } else {
909 UniqueID = *NextUniqueID;
910 (*NextUniqueID)++;
911 }
912 }
913 SmallString<128> Name =
914 getELFSectionNameForGlobal(GO, Kind, Mang, TM, UniqueSectionName, MJTE);
915
916 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
917 getGlobalObjectInfo(GO, TM, Name, Kind);
918 Flags |= ExtraFlags;
919
920 // Use 0 as the unique ID for execute-only text.
921 if (Kind.isExecuteOnly())
922 UniqueID = 0;
923 return Ctx.getELFSection(Name, Type, Flags, EntrySize, Group, IsComdat,
924 UniqueID, AssociatedSymbol);
925}
926
928 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
929 const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
930 unsigned Flags, unsigned *NextUniqueID) {
931 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
932 if (LinkedToSym) {
933 EmitUniqueSection = true;
934 Flags |= ELF::SHF_LINK_ORDER;
935 }
936 if (Retain) {
937 if (TM.getTargetTriple().isOSSolaris()) {
938 EmitUniqueSection = true;
940 } else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
941 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36)) {
942 EmitUniqueSection = true;
943 Flags |= ELF::SHF_GNU_RETAIN;
944 }
945 }
946 if (GO->hasMetadata(LLVMContext::MD_elf_section_properties))
947 EmitUniqueSection = true;
948
950 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
951 NextUniqueID, LinkedToSym);
952 assert(Section->getLinkedToSymbol() == LinkedToSym);
953 return Section;
954}
955
957 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
958 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
959
960 // If we have -ffunction-section or -fdata-section then we should emit the
961 // global value to a uniqued section specifically for it.
962 bool EmitUniqueSection = false;
963 if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
964 if (Kind.isText())
965 EmitUniqueSection = TM.getFunctionSections();
966 else
967 EmitUniqueSection = TM.getDataSections();
968 }
969 EmitUniqueSection |= GO->hasComdat();
970 return selectELFSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
971 Used.count(GO), EmitUniqueSection, Flags,
972 &NextUniqueID);
973}
974
976 const Function &F, const TargetMachine &TM) const {
978 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
979 // If the function's section names is pre-determined via pragma or a
980 // section attribute, call selectExplicitSectionGlobal.
981 if (F.hasSection())
983 &F, Kind, TM, getContext(), getMangler(), NextUniqueID,
984 Used.count(&F), /* ForceUnique = */true);
985
987 getContext(), &F, Kind, getMangler(), TM, Used.count(&F),
988 /*EmitUniqueSection=*/true, Flags, &NextUniqueID);
989}
990
995
997 const Function &F, const TargetMachine &TM,
998 const MachineJumpTableEntry *JTE) const {
999 // If the function can be removed, produce a unique section so that
1000 // the table doesn't prevent the removal.
1001 const Comdat *C = F.getComdat();
1002 bool EmitUniqueSection = TM.getFunctionSections() || C;
1003 if (!EmitUniqueSection && !TM.getEnableStaticDataPartitioning())
1004 return ReadOnlySection;
1005
1007 getMangler(), TM, EmitUniqueSection,
1008 ELF::SHF_ALLOC, &NextUniqueID,
1009 /* AssociatedSymbol */ nullptr, JTE);
1010}
1011
1013 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
1014 // If neither COMDAT nor function sections, use the monolithic LSDA section.
1015 // Re-use this path if LSDASection is null as in the Arm EHABI.
1016 if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
1017 return LSDASection;
1018
1019 const auto *LSDA = static_cast<const MCSectionELF *>(LSDASection);
1020 unsigned Flags = LSDA->getFlags();
1021 const MCSymbolELF *LinkedToSym = nullptr;
1022 StringRef Group;
1023 bool IsComdat = false;
1024 if (const Comdat *C = getELFComdat(&F)) {
1025 Flags |= ELF::SHF_GROUP;
1026 Group = C->getName();
1027 IsComdat = C->getSelectionKind() == Comdat::Any;
1028 }
1029 // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
1030 // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
1031 if (TM.getFunctionSections() &&
1032 (getContext().getAsmInfo().useIntegratedAssembler() &&
1033 getContext().getAsmInfo().binutilsIsAtLeast(2, 36))) {
1034 Flags |= ELF::SHF_LINK_ORDER;
1035 LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym);
1036 }
1037
1038 // Append the function name as the suffix like GCC, assuming
1039 // -funique-section-names applies to .gcc_except_table sections.
1040 return getContext().getELFSection(
1041 (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
1042 : LSDA->getName()),
1043 LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
1044 LinkedToSym);
1045}
1046
1048 bool UsesLabelDifference, const Function &F) const {
1049 // We can always create relative relocations, so use another section
1050 // that can be marked non-executable.
1051 return false;
1052}
1053
1054/// Given a mergeable constant with the specified size and relocation
1055/// information, return a section that it should be placed in.
1057 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1058 const Function *F) const {
1059 if (Kind.isMergeableConst4() && MergeableConst4Section)
1061 if (Kind.isMergeableConst8() && MergeableConst8Section)
1063 if (Kind.isMergeableConst16() && MergeableConst16Section)
1065 if (Kind.isMergeableConst32() && MergeableConst32Section)
1067 if (Kind.isReadOnly())
1068 return ReadOnlySection;
1069
1070 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1071 return DataRelROSection;
1072}
1073
1075 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1076 const Function *F, StringRef SectionSuffix) const {
1077 // TODO: Share code between this function and
1078 // MCObjectInfo::initELFMCObjectFileInfo.
1079 if (SectionSuffix.empty())
1080 return getSectionForConstant(DL, Kind, C, Alignment, F);
1081
1082 auto &Context = getContext();
1083 StringRef CstPrefix = ".rodata";
1084 unsigned MergeableCstFlags = ELF::SHF_ALLOC | ELF::SHF_MERGE;
1085 if (TM->getCodeModel() == CodeModel::Large &&
1086 TM->getTargetTriple().getArch() == Triple::x86_64) {
1087 MergeableCstFlags |= ELF::SHF_X86_64_LARGE;
1088 CstPrefix = ".lrodata";
1089 }
1090
1091 if (Kind.isMergeableConst4() && MergeableConst4Section)
1092 return Context.getELFSection(CstPrefix + ".cst4." + SectionSuffix + ".",
1093 ELF::SHT_PROGBITS, MergeableCstFlags, 4);
1094 if (Kind.isMergeableConst8() && MergeableConst8Section)
1095 return Context.getELFSection(CstPrefix + ".cst8." + SectionSuffix + ".",
1096 ELF::SHT_PROGBITS, MergeableCstFlags, 8);
1097 if (Kind.isMergeableConst16() && MergeableConst16Section)
1098 return Context.getELFSection(CstPrefix + ".cst16." + SectionSuffix + ".",
1099 ELF::SHT_PROGBITS, MergeableCstFlags, 16);
1100 if (Kind.isMergeableConst32() && MergeableConst32Section)
1101 return Context.getELFSection(CstPrefix + ".cst32." + SectionSuffix + ".",
1102 ELF::SHT_PROGBITS, MergeableCstFlags, 32);
1103 if (Kind.isReadOnly())
1104 return Context.getELFSection(".rodata." + SectionSuffix + ".",
1106
1107 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1108 return Context.getELFSection(".data.rel.ro." + SectionSuffix + ".",
1111}
1112
1113/// Returns a unique section for the given machine basic block.
1115 const Function &F, const MachineBasicBlock &MBB,
1116 const TargetMachine &TM) const {
1117 assert(MBB.isBeginSection() && "Basic block does not start a section!");
1119
1120 // For cold sections use the .text.split. prefix along with the parent
1121 // function name. All cold blocks for the same function go to the same
1122 // section. Similarly all exception blocks are grouped by symbol name
1123 // under the .text.eh prefix. For regular sections, we either use a unique
1124 // name, or a unique ID for the section.
1125 SmallString<128> Name;
1126 StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
1127 if (FunctionSectionName == ".text" ||
1128 FunctionSectionName.starts_with(".text.")) {
1129 // Function is in a regular .text section.
1130 StringRef FunctionName = MBB.getParent()->getName();
1131 if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
1133 Name += FunctionName;
1134 } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
1135 Name += ".text.eh.";
1136 Name += FunctionName;
1137 } else {
1138 Name += FunctionSectionName;
1139 if (TM.getUniqueBasicBlockSectionNames()) {
1140 if (!Name.ends_with("."))
1141 Name += ".";
1142 Name += MBB.getSymbol()->getName();
1143 } else {
1144 UniqueID = NextUniqueID++;
1145 }
1146 }
1147 } else {
1148 // If the original function has a custom non-dot-text section, then emit
1149 // all basic block sections into that section too, each with a unique id.
1150 Name = FunctionSectionName;
1151 UniqueID = NextUniqueID++;
1152 }
1153
1154 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
1155 std::string GroupName;
1156 if (F.hasComdat()) {
1157 Flags |= ELF::SHF_GROUP;
1158 GroupName = F.getComdat()->getName().str();
1159 }
1160 return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
1161 0 /* Entry Size */, GroupName,
1162 F.hasComdat(), UniqueID, nullptr);
1163}
1164
1165static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
1166 bool IsCtor, unsigned Priority,
1167 const MCSymbol *KeySym) {
1168 std::string Name;
1169 unsigned Type;
1170 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
1171 StringRef Comdat = KeySym ? KeySym->getName() : "";
1172
1173 if (KeySym)
1174 Flags |= ELF::SHF_GROUP;
1175
1176 if (UseInitArray) {
1177 if (IsCtor) {
1179 Name = ".init_array";
1180 } else {
1182 Name = ".fini_array";
1183 }
1184 if (Priority != 65535) {
1185 Name += '.';
1186 Name += utostr(Priority);
1187 }
1188 } else {
1189 // The default scheme is .ctor / .dtor, so we have to invert the priority
1190 // numbering.
1191 if (IsCtor)
1192 Name = ".ctors";
1193 else
1194 Name = ".dtors";
1195 if (Priority != 65535)
1196 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1198 }
1199
1200 return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
1201}
1202
1204 unsigned Priority, const MCSymbol *KeySym) const {
1205 return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
1206 KeySym);
1207}
1208
1210 unsigned Priority, const MCSymbol *KeySym) const {
1211 return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
1212 KeySym);
1213}
1214
1216 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1217 std::optional<int64_t> PCRelativeOffset) const {
1218 auto &Ctx = getContext();
1219 const MCExpr *Res;
1220 // Return a relocatable expression with the PLT specifier, %plt(GV) or
1221 // %plt(GV-RHS).
1222 if (PCRelativeOffset && PLTPCRelativeSpecifier) {
1223 Res = MCSymbolRefExpr::create(LHS, Ctx);
1224 // The current location is RHS plus *PCRelativeOffset. Compensate for it.
1225 Addend += *PCRelativeOffset;
1226 if (Addend)
1227 Res = MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx),
1228 Ctx);
1230 }
1231
1233 return nullptr;
1236 MCSymbolRefExpr::create(RHS, Ctx), Ctx);
1237 if (Addend)
1238 Res =
1239 MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx), Ctx);
1240 return Res;
1241}
1242
1243// Reference the PLT entry of a function, optionally with a subtrahend (`RHS`).
1245 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1246 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
1247 if (RHS)
1248 return lowerSymbolDifference(LHS, RHS, Addend, PCRelativeOffset);
1249
1250 // Only the legacy MCSymbolRefExpr::VariantKind approach is implemented.
1251 // Reference LHS@plt or LHS@plt - RHS.
1254 return nullptr;
1255}
1256
1258 // Use ".GCC.command.line" since this feature is to support clang's
1259 // -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1260 // same name.
1261 return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
1263}
1264
1265void
1267 UseInitArray = UseInitArray_;
1268 MCContext &Ctx = getContext();
1269 if (!UseInitArray) {
1270 StaticCtorSection = Ctx.getELFSection(".ctors", ELF::SHT_PROGBITS,
1272
1273 StaticDtorSection = Ctx.getELFSection(".dtors", ELF::SHT_PROGBITS,
1275 return;
1276 }
1277
1278 StaticCtorSection = Ctx.getELFSection(".init_array", ELF::SHT_INIT_ARRAY,
1280 StaticDtorSection = Ctx.getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
1282}
1283
1284//===----------------------------------------------------------------------===//
1285// MachO
1286//===----------------------------------------------------------------------===//
1287
1291
1293 const TargetMachine &TM) {
1295 if (TM.getRelocationModel() == Reloc::Static) {
1296 StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0,
1298 StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0,
1300 } else {
1301 StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func",
1304 StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func",
1307 }
1308
1314}
1315
1317 unsigned Priority, const MCSymbol *KeySym) const {
1318 return StaticDtorSection;
1319 // In userspace, we lower global destructors via atexit(), but kernel/kext
1320 // environments do not provide this function so we still need to support the
1321 // legacy way here.
1322 // See the -disable-atexit-based-global-dtor-lowering CodeGen flag for more
1323 // context.
1324}
1325
1327 Module &M) const {
1328 // Emit the linker options if present.
1329 emitLinkerDirectives(Streamer, M);
1330
1331 emitPseudoProbeDescMetadata(Streamer, M);
1332
1333 unsigned VersionVal = 0;
1334 unsigned ImageInfoFlags = 0;
1335 StringRef SectionVal;
1336
1337 GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1338 emitCGProfileMetadata(Streamer, M);
1339
1340 // The section is mandatory. If we don't have it, then we don't have GC info.
1341 if (SectionVal.empty())
1342 return;
1343
1344 StringRef Segment, Section;
1345 unsigned TAA = 0, StubSize = 0;
1346 bool TAAParsed;
1348 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1349 // If invalid, report the error with report_fatal_error.
1350 report_fatal_error("Invalid section specifier '" + Section +
1351 "': " + toString(std::move(E)) + ".");
1352 }
1353
1354 // Get the section.
1356 Segment, Section, TAA, StubSize, SectionKind::getData());
1357 Streamer.switchSection(S);
1358 Streamer.emitLabel(getContext().
1359 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1360 Streamer.emitInt32(VersionVal);
1361 Streamer.emitInt32(ImageInfoFlags);
1362 Streamer.addBlankLine();
1363}
1364
1366 Module &M) const {
1367 if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1368 for (const auto *Option : LinkerOptions->operands()) {
1369 SmallVector<std::string, 4> StrOptions;
1370 for (const auto &Piece : cast<MDNode>(Option)->operands())
1371 StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1372 Streamer.emitLinkerOptions(StrOptions);
1373 }
1374 }
1375}
1376
1377static void checkMachOComdat(const GlobalValue *GV) {
1378 const Comdat *C = GV->getComdat();
1379 if (!C)
1380 return;
1381
1382 report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
1383 "' cannot be lowered.");
1384}
1385
1387 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1388
1390
1391 // Parse the section specifier and create it if valid.
1392 StringRef Segment, Section;
1393 unsigned TAA = 0, StubSize = 0;
1394 bool TAAParsed;
1395
1396 checkMachOComdat(GO);
1397
1399 SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1400 // If invalid, report the error with report_fatal_error.
1401 report_fatal_error("Global variable '" + GO->getName() +
1402 "' has an invalid section specifier '" +
1403 GO->getSection() + "': " + toString(std::move(E)) + ".");
1404 }
1405
1406 // Get the section.
1407 MCSectionMachO *S =
1408 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1409
1410 // If TAA wasn't set by ParseSectionSpecifier() above,
1411 // use the value returned by getMachOSection() as a default.
1412 if (!TAAParsed)
1413 TAA = S->getTypeAndAttributes();
1414
1415 // Okay, now that we got the section, verify that the TAA & StubSize agree.
1416 // If the user declared multiple globals with different section flags, we need
1417 // to reject it here.
1418 if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1419 // If invalid, report the error with report_fatal_error.
1420 report_fatal_error("Global variable '" + GO->getName() +
1421 "' section type or attributes does not match previous"
1422 " section specifier");
1423 }
1424
1425 return S;
1426}
1427
1429 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1430 checkMachOComdat(GO);
1431
1432 // Handle thread local data.
1433 if (Kind.isThreadBSS()) return TLSBSSSection;
1434 if (Kind.isThreadData()) return TLSDataSection;
1435
1436 if (Kind.isText())
1438
1439 // If this is weak/linkonce, put this in a coalescable section, either in text
1440 // or data depending on if it is writable.
1441 if (GO->isWeakForLinker()) {
1442 if (Kind.isReadOnly())
1443 return ConstTextCoalSection;
1444 if (Kind.isReadOnlyWithRel())
1445 return ConstDataCoalSection;
1446 return DataCoalSection;
1447 }
1448
1449 // FIXME: Alignment check should be handled by section classifier.
1450 if (Kind.isMergeable1ByteCString() &&
1452 cast<GlobalVariable>(GO)) < Align(32))
1453 return CStringSection;
1454
1455 // Do not put 16-bit arrays in the UString section if they have an
1456 // externally visible label, this runs into issues with certain linker
1457 // versions.
1458 if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1460 cast<GlobalVariable>(GO)) < Align(32))
1461 return UStringSection;
1462
1463 // With MachO only variables whose corresponding symbol starts with 'l' or
1464 // 'L' can be merged, so we only try merging GVs with private linkage.
1465 if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1466 if (Kind.isMergeableConst4())
1468 if (Kind.isMergeableConst8())
1470 if (Kind.isMergeableConst16())
1472 }
1473
1474 // Otherwise, if it is readonly, but not something we can specially optimize,
1475 // just drop it in .const.
1476 if (Kind.isReadOnly())
1477 return ReadOnlySection;
1478
1479 // If this is marked const, put it into a const section. But if the dynamic
1480 // linker needs to write to it, put it in the data segment.
1481 if (Kind.isReadOnlyWithRel())
1482 return ConstDataSection;
1483
1484 // Put zero initialized globals with strong external linkage in the
1485 // DATA, __common section with the .zerofill directive.
1486 if (Kind.isBSSExtern())
1487 return DataCommonSection;
1488
1489 // Put zero initialized globals with local linkage in __DATA,__bss directive
1490 // with the .zerofill directive (aka .lcomm).
1491 if (Kind.isBSSLocal())
1492 return DataBSSSection;
1493
1494 // Otherwise, just drop the variable in the normal data section.
1495 return DataSection;
1496}
1497
1499 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1500 const Function *F) const {
1501 // If this constant requires a relocation, we have to put it in the data
1502 // segment, not in the text segment.
1503 if (Kind.isData() || Kind.isReadOnlyWithRel())
1504 return ConstDataSection;
1505
1506 if (Kind.isMergeableConst4())
1508 if (Kind.isMergeableConst8())
1510 if (Kind.isMergeableConst16())
1512 return ReadOnlySection; // .const
1513}
1514
1519
1521 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
1522 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1523 // The mach-o version of this method defaults to returning a stub reference.
1524
1525 if (Encoding & DW_EH_PE_indirect) {
1526 MachineModuleInfoMachO &MachOMMI =
1528
1529 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1530
1531 // Add information about the stub reference to MachOMMI so that the stub
1532 // gets emitted by the asmprinter.
1533 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1534 if (!StubSym.getPointer()) {
1535 MCSymbol *Sym = TM.getSymbol(GV);
1537 }
1538
1541 Encoding & ~DW_EH_PE_indirect, Streamer);
1542 }
1543
1545 MMI, Streamer);
1546}
1547
1549 const GlobalValue *GV, const TargetMachine &TM,
1550 MachineModuleInfo *MMI) const {
1551 // The mach-o version of this method defaults to returning a stub reference.
1552 MachineModuleInfoMachO &MachOMMI =
1554
1555 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1556
1557 // Add information about the stub reference to MachOMMI so that the stub
1558 // gets emitted by the asmprinter.
1559 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1560 if (!StubSym.getPointer()) {
1561 MCSymbol *Sym = TM.getSymbol(GV);
1563 }
1564
1565 return SSym;
1566}
1567
1569 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
1570 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1571 // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1572 // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1573 // through a non_lazy_ptr stub instead. One advantage is that it allows the
1574 // computation of deltas to final external symbols. Example:
1575 //
1576 // _extgotequiv:
1577 // .long _extfoo
1578 //
1579 // _delta:
1580 // .long _extgotequiv-_delta
1581 //
1582 // is transformed to:
1583 //
1584 // _delta:
1585 // .long L_extfoo$non_lazy_ptr-(_delta+0)
1586 //
1587 // .section __IMPORT,__pointers,non_lazy_symbol_pointers
1588 // L_extfoo$non_lazy_ptr:
1589 // .indirect_symbol _extfoo
1590 // .long 0
1591 //
1592 // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1593 // may point to both local (same translation unit) and global (other
1594 // translation units) symbols. Example:
1595 //
1596 // .section __DATA,__pointers,non_lazy_symbol_pointers
1597 // L1:
1598 // .indirect_symbol _myGlobal
1599 // .long 0
1600 // L2:
1601 // .indirect_symbol _myLocal
1602 // .long _myLocal
1603 //
1604 // If the symbol is local, instead of the symbol's index, the assembler
1605 // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1606 // Then the linker will notice the constant in the table and will look at the
1607 // content of the symbol.
1608 MachineModuleInfoMachO &MachOMMI =
1610 MCContext &Ctx = getContext();
1611
1612 // The offset must consider the original displacement from the base symbol
1613 // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1614 Offset = -MV.getConstant();
1615 const MCSymbol *BaseSym = MV.getSubSym();
1616
1617 // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1618 // non_lazy_ptr stubs.
1619 SmallString<128> Name;
1620 StringRef Suffix = "$non_lazy_ptr";
1622 Name += Sym->getName();
1623 Name += Suffix;
1624 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1625
1626 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1627
1628 if (!StubSym.getPointer())
1629 StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1630 !GV->hasLocalLinkage());
1631
1632 const MCExpr *BSymExpr = MCSymbolRefExpr::create(BaseSym, Ctx);
1633 const MCExpr *LHS = MCSymbolRefExpr::create(Stub, Ctx);
1634
1635 if (!Offset)
1636 return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1637
1638 const MCExpr *RHS =
1640 return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1641}
1642
1643static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
1644 const MCSection &Section) {
1646 return true;
1647
1648 // FIXME: we should be able to use private labels for sections that can't be
1649 // dead-stripped (there's no issue with blocking atomization there), but `ld
1650 // -r` sometimes drops the no_dead_strip attribute from sections so for safety
1651 // we don't allow it.
1652 return false;
1653}
1654
1656 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1657 const TargetMachine &TM) const {
1658 bool CannotUsePrivateLabel = true;
1659 if (auto *GO = GV->getAliaseeObject()) {
1661 const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
1662 CannotUsePrivateLabel = !canUsePrivateLabel(TM.getMCAsmInfo(), *TheSection);
1663 }
1664 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1665}
1666
1667//===----------------------------------------------------------------------===//
1668// COFF
1669//===----------------------------------------------------------------------===//
1670
1671static unsigned
1673 unsigned Flags = 0;
1675
1676 if (K.isMetadata())
1677 Flags |=
1679 else if (K.isExclude())
1680 Flags |=
1682 else if (K.isText())
1683 Flags |=
1688 else if (K.isBSS())
1689 Flags |=
1693 else if (K.isThreadLocal())
1694 Flags |=
1698 else if (K.isReadOnly() || K.isReadOnlyWithRel())
1699 Flags |=
1702 else if (K.isWriteable())
1703 Flags |=
1707
1708 return Flags;
1709}
1710
1712 const Comdat *C = GV->getComdat();
1713 assert(C && "expected GV to have a Comdat!");
1714
1715 StringRef ComdatGVName = C->getName();
1716 const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1717 if (!ComdatGV)
1718 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1719 "' does not exist.");
1720
1721 if (ComdatGV->getComdat() != C)
1722 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1723 "' is not a key for its COMDAT.");
1724
1725 return ComdatGV;
1726}
1727
1728static int getSelectionForCOFF(const GlobalValue *GV) {
1729 if (const Comdat *C = GV->getComdat()) {
1730 const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
1731 if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1732 ComdatKey = GA->getAliaseeObject();
1733 if (ComdatKey == GV) {
1734 switch (C->getSelectionKind()) {
1735 case Comdat::Any:
1737 case Comdat::ExactMatch:
1739 case Comdat::Largest:
1743 case Comdat::SameSize:
1745 }
1746 } else {
1748 }
1749 }
1750 return 0;
1751}
1752
1754 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1755 StringRef Name = handlePragmaClangSection(GO, Kind);
1756 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::COFF,
1757 /*AddSegmentInfo=*/false) ||
1758 Name == getInstrProfSectionName(IPSK_covfun, Triple::COFF,
1759 /*AddSegmentInfo=*/false) ||
1760 Name == getInstrProfSectionName(IPSK_covdata, Triple::COFF,
1761 /*AddSegmentInfo=*/false) ||
1762 Name == getInstrProfSectionName(IPSK_covname, Triple::COFF,
1763 /*AddSegmentInfo=*/false) ||
1764 Name == ".llvmbc" || Name == ".llvmcmd")
1765 Kind = SectionKind::getMetadata();
1766 int Selection = 0;
1767 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1768 StringRef COMDATSymName = "";
1769 if (GO->hasComdat()) {
1771 const GlobalValue *ComdatGV;
1773 ComdatGV = getComdatGVForCOFF(GO);
1774 else
1775 ComdatGV = GO;
1776
1777 if (!ComdatGV->hasPrivateLinkage()) {
1778 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1779 COMDATSymName = Sym->getName();
1780 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1781 } else {
1782 Selection = 0;
1783 }
1784 }
1785
1786 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1787 Selection);
1788}
1789
1791 if (Kind.isText())
1792 return ".text";
1793 if (Kind.isBSS())
1794 return ".bss";
1795 if (Kind.isThreadLocal())
1796 return ".tls$";
1797 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1798 return ".rdata";
1799 return ".data";
1800}
1801
1803 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1804 // If we have -ffunction-sections then we should emit the global value to a
1805 // uniqued section specifically for it.
1806 bool EmitUniquedSection;
1807 if (Kind.isText())
1808 EmitUniquedSection = TM.getFunctionSections();
1809 else
1810 EmitUniquedSection = TM.getDataSections();
1811
1812 if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1814
1815 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1816
1817 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1819 if (!Selection)
1821 const GlobalValue *ComdatGV;
1822 if (GO->hasComdat())
1823 ComdatGV = getComdatGVForCOFF(GO);
1824 else
1825 ComdatGV = GO;
1826
1828 if (EmitUniquedSection)
1829 UniqueID = NextUniqueID++;
1830
1831 if (!ComdatGV->hasPrivateLinkage()) {
1832 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1833 StringRef COMDATSymName = Sym->getName();
1834
1835 if (const auto *F = dyn_cast<Function>(GO))
1836 if (std::optional<StringRef> Prefix = F->getSectionPrefix())
1837 raw_svector_ostream(Name) << '$' << *Prefix;
1838
1839 // Append "$symbol" to the section name *before* IR-level mangling is
1840 // applied when targetting mingw. This is what GCC does, and the ld.bfd
1841 // COFF linker will not properly handle comdats otherwise.
1842 if (getContext().getTargetTriple().isOSCygMing())
1843 raw_svector_ostream(Name) << '$' << ComdatGV->getName();
1844
1845 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1847 } else {
1848 SmallString<256> TmpData;
1849 getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
1850 return getContext().getCOFFSection(Name, Characteristics, TmpData,
1852 }
1853 }
1854
1855 if (Kind.isText())
1856 return TextSection;
1857
1858 if (Kind.isThreadLocal())
1859 return TLSDataSection;
1860
1861 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1862 return ReadOnlySection;
1863
1864 // Note: we claim that common symbols are put in BSSSection, but they are
1865 // really emitted with the magic .comm directive, which creates a symbol table
1866 // entry but not a section.
1867 if (Kind.isBSS() || Kind.isCommon())
1868 return BSSSection;
1869
1870 return DataSection;
1871}
1872
1874 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1875 const TargetMachine &TM) const {
1876 bool CannotUsePrivateLabel = false;
1877 if (GV->hasPrivateLinkage() &&
1878 ((isa<Function>(GV) && TM.getFunctionSections()) ||
1879 (isa<GlobalVariable>(GV) && TM.getDataSections())))
1880 CannotUsePrivateLabel = true;
1881
1882 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1883}
1884
1886 const Function &F, const TargetMachine &TM) const {
1887 // If the function can be removed, produce a unique section so that
1888 // the table doesn't prevent the removal.
1889 const Comdat *C = F.getComdat();
1890 bool EmitUniqueSection = TM.getFunctionSections() || C;
1891 if (!EmitUniqueSection)
1892 return ReadOnlySection;
1893
1894 // FIXME: we should produce a symbol for F instead.
1895 if (F.hasPrivateLinkage())
1896 return ReadOnlySection;
1897
1898 MCSymbol *Sym = TM.getSymbol(&F);
1899 StringRef COMDATSymName = Sym->getName();
1900
1903 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1904 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1905 unsigned UniqueID = NextUniqueID++;
1906
1907 return getContext().getCOFFSection(SecName, Characteristics, COMDATSymName,
1909 UniqueID);
1910}
1911
1913 bool UsesLabelDifference, const Function &F) const {
1914 if (TM->getTargetTriple().getArch() == Triple::x86_64) {
1916 // We can always create relative relocations, so use another section
1917 // that can be marked non-executable.
1918 return false;
1919 }
1920 }
1922 UsesLabelDifference, F);
1923}
1924
1926 Module &M) const {
1927 emitLinkerDirectives(Streamer, M);
1928
1929 unsigned Version = 0;
1930 unsigned Flags = 0;
1931 StringRef Section;
1932
1933 GetObjCImageInfo(M, Version, Flags, Section);
1934 if (!Section.empty()) {
1935 auto &C = getContext();
1936 auto *S = C.getCOFFSection(Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1938 Streamer.switchSection(S);
1939 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1940 Streamer.emitInt32(Version);
1941 Streamer.emitInt32(Flags);
1942 Streamer.addBlankLine();
1943 }
1944
1945 emitCGProfileMetadata(Streamer, M);
1946 emitPseudoProbeDescMetadata(Streamer, M, [](MCStreamer &Streamer) {
1947 if (MCSymbol *Sym =
1948 static_cast<MCSectionCOFF *>(Streamer.getCurrentSectionOnly())
1949 ->getCOMDATSymbol())
1950 if (Sym->isUndefined()) {
1951 // COMDAT symbol must be external to perform deduplication.
1952 Streamer.emitSymbolAttribute(Sym, MCSA_Global);
1953 Streamer.emitLabel(Sym);
1954 }
1955 });
1956}
1957
1959 MCStreamer &Streamer, Module &M) const {
1960 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1961 // Emit the linker options to the linker .drectve section. According to the
1962 // spec, this section is a space-separated string containing flags for
1963 // linker.
1965 Streamer.switchSection(Sec);
1966 for (const auto *Option : LinkerOptions->operands()) {
1967 for (const auto &Piece : cast<MDNode>(Option)->operands()) {
1968 // Lead with a space for consistency with our dllexport implementation.
1969 std::string Directive(" ");
1970 Directive.append(std::string(cast<MDString>(Piece)->getString()));
1971 Streamer.emitBytes(Directive);
1972 }
1973 }
1974 }
1975
1976 // Emit /EXPORT: flags for each exported global as necessary.
1977 std::string Flags;
1978 for (const GlobalValue &GV : M.global_values()) {
1979 raw_string_ostream OS(Flags);
1980 emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
1981 getMangler());
1982 if (!Flags.empty()) {
1983 Streamer.switchSection(getDrectveSection());
1984 Streamer.emitBytes(Flags);
1985 }
1986 Flags.clear();
1987 }
1988
1989 // Emit /INCLUDE: flags for each used global as necessary.
1990 if (const auto *LU = M.getNamedGlobal("llvm.used")) {
1991 assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
1992 assert(isa<ArrayType>(LU->getValueType()) &&
1993 "expected llvm.used to be an array type");
1994 if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
1995 for (const Value *Op : A->operands()) {
1996 const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
1997 // Global symbols with internal or private linkage are not visible to
1998 // the linker, and thus would cause an error when the linker tried to
1999 // preserve the symbol due to the `/include:` directive.
2000 if (GV->hasLocalLinkage())
2001 continue;
2002
2003 raw_string_ostream OS(Flags);
2004 emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
2005 getMangler());
2006
2007 if (!Flags.empty()) {
2008 Streamer.switchSection(getDrectveSection());
2009 Streamer.emitBytes(Flags);
2010 }
2011 Flags.clear();
2012 }
2013 }
2014 }
2015}
2016
2018 const TargetMachine &TM) {
2020 this->TM = &TM;
2021 const Triple &T = TM.getTargetTriple();
2022 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2024 Ctx.getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2027 Ctx.getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2029 } else {
2030 StaticCtorSection = Ctx.getCOFFSection(
2033 StaticDtorSection = Ctx.getCOFFSection(
2036 }
2037}
2038
2040 const Triple &T, bool IsCtor,
2041 unsigned Priority,
2042 const MCSymbol *KeySym,
2044 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2045 // If the priority is the default, use .CRT$XCU, possibly associative.
2046 if (Priority == 65535)
2047 return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
2048
2049 // Otherwise, we need to compute a new section name. Low priorities should
2050 // run earlier. The linker will sort sections ASCII-betically, and we need a
2051 // string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
2052 // make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
2053 // low priorities need to sort before 'L', since the CRT uses that
2054 // internally, so we use ".CRT$XCA00001" for them. We have a contract with
2055 // the frontend that "init_seg(compiler)" corresponds to priority 200 and
2056 // "init_seg(lib)" corresponds to priority 400, and those respectively use
2057 // 'C' and 'L' without the priority suffix. Priorities between 200 and 400
2058 // use 'C' with the priority as a suffix.
2059 SmallString<24> Name;
2060 char LastLetter = 'T';
2061 bool AddPrioritySuffix = Priority != 200 && Priority != 400;
2062 if (Priority < 200)
2063 LastLetter = 'A';
2064 else if (Priority < 400)
2065 LastLetter = 'C';
2066 else if (Priority == 400)
2067 LastLetter = 'L';
2068 raw_svector_ostream OS(Name);
2069 OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;
2070 if (AddPrioritySuffix)
2071 OS << format("%05u", Priority);
2072 MCSectionCOFF *Sec = Ctx.getCOFFSection(
2074 return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
2075 }
2076
2077 std::string Name = IsCtor ? ".ctors" : ".dtors";
2078 if (Priority != 65535)
2079 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
2080
2081 return Ctx.getAssociativeCOFFSection(
2082 Ctx.getCOFFSection(Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2085 KeySym, 0);
2086}
2087
2089 unsigned Priority, const MCSymbol *KeySym) const {
2091 getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
2092 static_cast<MCSectionCOFF *>(StaticCtorSection));
2093}
2094
2096 unsigned Priority, const MCSymbol *KeySym) const {
2098 getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
2099 static_cast<MCSectionCOFF *>(StaticDtorSection));
2100}
2101
2103 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
2104 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
2105 const Triple &T = TM.getTargetTriple();
2106 if (T.isOSCygMing())
2107 return nullptr;
2108
2109 // Our symbols should exist in address space zero, cowardly no-op if
2110 // otherwise.
2111 if (LHS->getType()->getPointerAddressSpace() != 0 ||
2112 RHS->getType()->getPointerAddressSpace() != 0)
2113 return nullptr;
2114
2115 // Both ptrtoint instructions must wrap global objects:
2116 // - Only global variables are eligible for image relative relocations.
2117 // - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
2118 // We expect __ImageBase to be a global variable without a section, externally
2119 // defined.
2120 //
2121 // It should look something like this: @__ImageBase = external constant i8
2122 if (!isa<GlobalObject>(LHS) || !isa<GlobalVariable>(RHS) ||
2123 LHS->isThreadLocal() || RHS->isThreadLocal() ||
2124 RHS->getName() != "__ImageBase" || !RHS->hasExternalLinkage() ||
2125 cast<GlobalVariable>(RHS)->hasInitializer() || RHS->hasSection())
2126 return nullptr;
2127
2128 const MCExpr *Res = MCSymbolRefExpr::create(
2129 TM.getSymbol(LHS), MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
2130 if (Addend != 0)
2132 Res, MCConstantExpr::create(Addend, getContext()), getContext());
2133 return Res;
2134}
2135
2136static std::string APIntToHexString(const APInt &AI) {
2137 unsigned Width = (AI.getBitWidth() / 8) * 2;
2138 std::string HexString = toString(AI, 16, /*Signed=*/false);
2139 llvm::transform(HexString, HexString.begin(), tolower);
2140 unsigned Size = HexString.size();
2141 assert(Width >= Size && "hex string is too large!");
2142 HexString.insert(HexString.begin(), Width - Size, '0');
2143
2144 return HexString;
2145}
2146
2147static std::string scalarConstantToHexString(const Constant *C) {
2148 Type *Ty = C->getType();
2149 if (isa<UndefValue>(C)) {
2150 return APIntToHexString(APInt::getZero(Ty->getPrimitiveSizeInBits()));
2151 } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
2152 if (CFP->getType()->isFloatingPointTy())
2153 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2154
2155 std::string HexString;
2156 unsigned NumElements =
2157 cast<FixedVectorType>(CFP->getType())->getNumElements();
2158 for (unsigned I = 0; I < NumElements; ++I)
2159 HexString += APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2160 return HexString;
2161 } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
2162 if (CI->getType()->isIntegerTy())
2163 return APIntToHexString(CI->getValue());
2164
2165 std::string HexString;
2166 unsigned NumElements =
2167 cast<FixedVectorType>(CI->getType())->getNumElements();
2168 for (unsigned I = 0; I < NumElements; ++I)
2169 HexString += APIntToHexString(CI->getValue());
2170 return HexString;
2171 } else {
2172 unsigned NumElements;
2173 if (auto *VTy = dyn_cast<VectorType>(Ty))
2174 NumElements = cast<FixedVectorType>(VTy)->getNumElements();
2175 else
2176 NumElements = Ty->getArrayNumElements();
2177 std::string HexString;
2178 for (int I = NumElements - 1, E = -1; I != E; --I)
2179 HexString += scalarConstantToHexString(C->getAggregateElement(I));
2180 return HexString;
2181 }
2182}
2183
2185 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2186 const Function *F) const {
2187 if (Kind.isMergeableConst() && C &&
2188 getContext().getAsmInfo().hasCOFFComdatConstants()) {
2189 // This creates comdat sections with the given symbol name, but unless
2190 // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
2191 // will be created with a null storage class, which makes GNU binutils
2192 // error out.
2193 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2196 std::string COMDATSymName;
2197 if (Kind.isMergeableConst4()) {
2198 if (Alignment <= 4) {
2199 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2200 Alignment = Align(4);
2201 }
2202 } else if (Kind.isMergeableConst8()) {
2203 if (Alignment <= 8) {
2204 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2205 Alignment = Align(8);
2206 }
2207 } else if (Kind.isMergeableConst16()) {
2208 // FIXME: These may not be appropriate for non-x86 architectures.
2209 if (Alignment <= 16) {
2210 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
2211 Alignment = Align(16);
2212 }
2213 } else if (Kind.isMergeableConst32()) {
2214 if (Alignment <= 32) {
2215 COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
2216 Alignment = Align(32);
2217 }
2218 }
2219
2220 if (!COMDATSymName.empty())
2221 return getContext().getCOFFSection(".rdata", Characteristics,
2222 COMDATSymName,
2224 }
2225
2226 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, Alignment,
2227 F);
2228}
2229
2230//===----------------------------------------------------------------------===//
2231// Wasm
2232//===----------------------------------------------------------------------===//
2233
2234static const Comdat *getWasmComdat(const GlobalValue *GV) {
2235 const Comdat *C = GV->getComdat();
2236 if (!C)
2237 return nullptr;
2238
2239 if (C->getSelectionKind() != Comdat::Any)
2240 report_fatal_error("WebAssembly COMDATs only support "
2241 "SelectionKind::Any, '" + C->getName() + "' cannot be "
2242 "lowered.");
2243
2244 return C;
2245}
2246
2247static unsigned getWasmSectionFlags(SectionKind K, bool Retain) {
2248 unsigned Flags = 0;
2249
2250 if (K.isThreadLocal())
2251 Flags |= wasm::WASM_SEG_FLAG_TLS;
2252
2253 if (K.isMergeableCString())
2255
2256 if (Retain)
2258
2259 // TODO(sbc): Add suport for K.isMergeableConst()
2260
2261 return Flags;
2262}
2263
2266 collectUsedGlobalVariables(M, Vec, false);
2267 for (GlobalValue *GV : Vec)
2268 if (auto *GO = dyn_cast<GlobalObject>(GV))
2269 Used.insert(GO);
2270}
2271
2273 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2274 // We don't support explict section names for functions in the wasm object
2275 // format. Each function has to be in its own unique section.
2276 if (isa<Function>(GO)) {
2277 return SelectSectionForGlobal(GO, Kind, TM);
2278 }
2279
2280 StringRef Name = GO->getSection();
2281
2282 // Certain data sections we treat as named custom sections rather than
2283 // segments within the data section.
2284 // This could be avoided if all data segements (the wasm sense) were
2285 // represented as their own sections (in the llvm sense).
2286 // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2287 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::Wasm,
2288 /*AddSegmentInfo=*/false) ||
2289 Name == getInstrProfSectionName(IPSK_covfun, Triple::Wasm,
2290 /*AddSegmentInfo=*/false) ||
2291 Name == ".llvmbc" || Name == ".llvmcmd")
2292 Kind = SectionKind::getMetadata();
2293
2294 StringRef Group = "";
2295 if (const Comdat *C = getWasmComdat(GO)) {
2296 Group = C->getName();
2297 }
2298
2299 unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
2300 MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
2302
2303 return Section;
2304}
2305
2306static MCSectionWasm *
2308 SectionKind Kind, Mangler &Mang,
2309 const TargetMachine &TM, bool EmitUniqueSection,
2310 unsigned *NextUniqueID, bool Retain) {
2311 StringRef Group = "";
2312 if (const Comdat *C = getWasmComdat(GO)) {
2313 Group = C->getName();
2314 }
2315
2316 bool UniqueSectionNames = TM.getUniqueSectionNames();
2317 SmallString<128> Name = getSectionPrefixForGlobal(Kind, /*IsLarge=*/false);
2318
2319 if (const auto *F = dyn_cast<Function>(GO)) {
2320 const auto &OptionalPrefix = F->getSectionPrefix();
2321 if (OptionalPrefix)
2322 raw_svector_ostream(Name) << '.' << *OptionalPrefix;
2323 }
2324
2325 if (EmitUniqueSection && UniqueSectionNames) {
2326 Name.push_back('.');
2327 TM.getNameWithPrefix(Name, GO, Mang, true);
2328 }
2330 if (EmitUniqueSection && !UniqueSectionNames) {
2331 UniqueID = *NextUniqueID;
2332 (*NextUniqueID)++;
2333 }
2334
2335 unsigned Flags = getWasmSectionFlags(Kind, Retain);
2336 return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2337}
2338
2340 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2341
2342 if (Kind.isCommon())
2343 report_fatal_error("mergable sections not supported yet on wasm");
2344
2345 // If we have -ffunction-section or -fdata-section then we should emit the
2346 // global value to a uniqued section specifically for it.
2347 bool EmitUniqueSection = false;
2348 if (Kind.isText())
2349 EmitUniqueSection = TM.getFunctionSections();
2350 else
2351 EmitUniqueSection = TM.getDataSections();
2352 EmitUniqueSection |= GO->hasComdat();
2353 bool Retain = Used.count(GO);
2354 EmitUniqueSection |= Retain;
2355
2356 return selectWasmSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
2357 EmitUniqueSection, &NextUniqueID, Retain);
2358}
2359
2361 bool UsesLabelDifference, const Function &F) const {
2362 // We can always create relative relocations, so use another section
2363 // that can be marked non-executable.
2364 return false;
2365}
2366
2370
2371 // We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2372 // .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2374}
2375
2377 unsigned Priority, const MCSymbol *KeySym) const {
2378 return Priority == UINT16_MAX ?
2380 getContext().getWasmSection(".init_array." + utostr(Priority),
2382}
2383
2385 unsigned Priority, const MCSymbol *KeySym) const {
2386 report_fatal_error("@llvm.global_dtors should have been lowered already");
2387}
2388
2389//===----------------------------------------------------------------------===//
2390// XCOFF
2391//===----------------------------------------------------------------------===//
2393 const MachineFunction *MF) {
2394 if (!MF->getLandingPads().empty())
2395 return true;
2396
2397 const Function &F = MF->getFunction();
2398 if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2399 return false;
2400
2401 const GlobalValue *Per =
2402 dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2403 assert(Per && "Personality routine is not a GlobalValue type.");
2405 return false;
2406
2407 return true;
2408}
2409
2411 const MachineFunction *MF) {
2412 const Function &F = MF->getFunction();
2413 if (!F.hasStackProtectorFnAttr())
2414 return false;
2415 // FIXME: check presence of canary word
2416 // There are cases that the stack protectors are not really inserted even if
2417 // the attributes are on.
2418 return true;
2419}
2420
2421MCSymbol *
2423 auto *EHInfoSym =
2424 static_cast<MCSymbolXCOFF *>(MF->getContext().getOrCreateSymbol(
2425 "__ehinfo." + Twine(MF->getFunctionNumber())));
2426 EHInfoSym->setEHInfo();
2427 return EHInfoSym;
2428}
2429
2430MCSymbol *
2432 const TargetMachine &TM) const {
2433 // We always use a qualname symbol for a GV that represents
2434 // a declaration, a function descriptor, or a common symbol. An IFunc is
2435 // lowered as a special trampoline function which has an entry point and a
2436 // descriptor.
2437 // If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2438 // also return a qualname so that a label symbol could be avoided.
2439 // It is inherently ambiguous when the GO represents the address of a
2440 // function, as the GO could either represent a function descriptor or a
2441 // function entry point. We choose to always return a function descriptor
2442 // here.
2443 if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2444 if (GO->isDeclarationForLinker())
2445 return static_cast<const MCSectionXCOFF *>(
2447 ->getQualNameSymbol();
2448
2449 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2450 if (GVar->hasAttribute("toc-data"))
2451 return static_cast<const MCSectionXCOFF *>(
2453 ->getQualNameSymbol();
2454
2455 if (isa<GlobalIFunc>(GO))
2456 return static_cast<const MCSectionXCOFF *>(
2458 ->getQualNameSymbol();
2459
2460 SectionKind GOKind = getKindForGlobal(GO, TM);
2461 if (GOKind.isText())
2462 return static_cast<const MCSectionXCOFF *>(
2464 ->getQualNameSymbol();
2465 if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2466 GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2467 return static_cast<const MCSectionXCOFF *>(
2468 SectionForGlobal(GO, GOKind, TM))
2469 ->getQualNameSymbol();
2470 }
2471
2472 // For all other cases, fall back to getSymbol to return the unqualified name.
2473 return nullptr;
2474}
2475
2477 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2478 if (!GO->hasSection())
2479 report_fatal_error("#pragma clang section is not yet supported");
2480
2482
2483 // Handle the XCOFF::TD case first, then deal with the rest.
2484 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2485 if (GVar->hasAttribute("toc-data"))
2486 return getContext().getXCOFFSection(
2487 SectionName, Kind,
2489 /* MultiSymbolsAllowed*/ true);
2490
2491 XCOFF::StorageMappingClass MappingClass;
2492 if (Kind.isText())
2493 MappingClass = XCOFF::XMC_PR;
2494 else if (Kind.isData() || Kind.isBSS())
2495 MappingClass = XCOFF::XMC_RW;
2496 else if (Kind.isReadOnlyWithRel())
2497 MappingClass =
2498 TM.Options.XCOFFReadOnlyPointers ? XCOFF::XMC_RO : XCOFF::XMC_RW;
2499 else if (Kind.isReadOnly())
2500 MappingClass = XCOFF::XMC_RO;
2501 else
2502 report_fatal_error("XCOFF other section types not yet implemented.");
2503
2504 return getContext().getXCOFFSection(
2505 SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
2506 /* MultiSymbolsAllowed*/ true);
2507}
2508
2510 const GlobalObject *GO, const TargetMachine &TM) const {
2512 "Tried to get ER section for a defined global.");
2513
2514 SmallString<128> Name;
2515 getNameWithPrefix(Name, GO, TM);
2516
2517 // AIX TLS local-dynamic does not need the external reference for the
2518 // "_$TLSML" symbol.
2520 GO->hasName() && GO->getName() == "_$TLSML") {
2521 return getContext().getXCOFFSection(
2522 Name, SectionKind::getData(),
2524 }
2525
2528 if (GO->isThreadLocal())
2529 SMC = XCOFF::XMC_UL;
2530
2531 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2532 if (GVar->hasAttribute("toc-data"))
2533 SMC = XCOFF::XMC_TD;
2534
2535 // Externals go into a csect of type ER.
2536 return getContext().getXCOFFSection(
2539}
2540
2542 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2543 // Handle the XCOFF::TD case first, then deal with the rest.
2544 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2545 if (GVar->hasAttribute("toc-data")) {
2546 SmallString<128> Name;
2547 getNameWithPrefix(Name, GO, TM);
2548 XCOFF::SymbolType symType =
2550 return getContext().getXCOFFSection(
2551 Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_TD, symType),
2552 /* MultiSymbolsAllowed*/ true);
2553 }
2554
2555 // Common symbols go into a csect with matching name which will get mapped
2556 // into the .bss section.
2557 // Zero-initialized local TLS symbols go into a csect with matching name which
2558 // will get mapped into the .tbss section.
2559 if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2560 SmallString<128> Name;
2561 getNameWithPrefix(Name, GO, TM);
2562 XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ? XCOFF::XMC_BS
2563 : Kind.isCommon() ? XCOFF::XMC_RW
2564 : XCOFF::XMC_UL;
2565 return getContext().getXCOFFSection(
2566 Name, Kind, XCOFF::CsectProperties(SMC, XCOFF::XTY_CM));
2567 }
2568
2569 if (Kind.isText()) {
2570 if (TM.getFunctionSections()) {
2571 return static_cast<const MCSymbolXCOFF *>(
2573 ->getRepresentedCsect();
2574 }
2575 return TextSection;
2576 }
2577
2578 if (TM.Options.XCOFFReadOnlyPointers && Kind.isReadOnlyWithRel()) {
2579 if (!TM.getDataSections())
2581 "ReadOnlyPointers is supported only if data sections is turned on");
2582
2583 SmallString<128> Name;
2584 getNameWithPrefix(Name, GO, TM);
2585 return getContext().getXCOFFSection(
2588 }
2589
2590 // For BSS kind, zero initialized data must be emitted to the .data section
2591 // because external linkage control sections that get mapped to the .bss
2592 // section will be linked as tentative definitions, which is only appropriate
2593 // for SectionKind::Common.
2594 if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2595 if (TM.getDataSections()) {
2596 SmallString<128> Name;
2597 getNameWithPrefix(Name, GO, TM);
2598 return getContext().getXCOFFSection(
2599 Name, SectionKind::getData(),
2601 }
2602 return DataSection;
2603 }
2604
2605 if (Kind.isReadOnly()) {
2606 if (TM.getDataSections()) {
2607 SmallString<128> Name;
2608 getNameWithPrefix(Name, GO, TM);
2609 return getContext().getXCOFFSection(
2612 }
2613 return ReadOnlySection;
2614 }
2615
2616 // External/weak TLS data and initialized local TLS data are not eligible
2617 // to be put into common csect. If data sections are enabled, thread
2618 // data are emitted into separate sections. Otherwise, thread data
2619 // are emitted into the .tdata section.
2620 if (Kind.isThreadLocal()) {
2621 if (TM.getDataSections()) {
2622 SmallString<128> Name;
2623 getNameWithPrefix(Name, GO, TM);
2624 return getContext().getXCOFFSection(
2626 }
2627 return TLSDataSection;
2628 }
2629
2630 report_fatal_error("XCOFF other section types not yet implemented.");
2631}
2632
2634 const Function &F, const TargetMachine &TM) const {
2635 assert (!F.getComdat() && "Comdat not supported on XCOFF.");
2636
2637 if (!TM.getFunctionSections())
2638 return ReadOnlySection;
2639
2640 // If the function can be removed, produce a unique section so that
2641 // the table doesn't prevent the removal.
2642 SmallString<128> NameStr(".rodata.jmp..");
2643 getNameWithPrefix(NameStr, &F, TM);
2644 return getContext().getXCOFFSection(
2645 NameStr, SectionKind::getReadOnly(),
2647}
2648
2650 bool UsesLabelDifference, const Function &F) const {
2651 return false;
2652}
2653
2654/// Given a mergeable constant with the specified size and relocation
2655/// information, return a section that it should be placed in.
2657 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2658 const Function *F) const {
2659 // TODO: Enable emiting constant pool to unique sections when we support it.
2660 if (Alignment > Align(16))
2661 report_fatal_error("Alignments greater than 16 not yet supported.");
2662
2663 if (Alignment == Align(8)) {
2664 assert(ReadOnly8Section && "Section should always be initialized.");
2665 return ReadOnly8Section;
2666 }
2667
2668 if (Alignment == Align(16)) {
2669 assert(ReadOnly16Section && "Section should always be initialized.");
2670 return ReadOnly16Section;
2671 }
2672
2673 return ReadOnlySection;
2674}
2675
2677 const TargetMachine &TgtM) {
2681 (TgtM.getTargetTriple().isArch32Bit() ? dwarf::DW_EH_PE_sdata4
2684 LSDAEncoding = 0;
2686
2687 // AIX debug for thread local location is not ready. And for integrated as
2688 // mode, the relocatable address for the thread local variable will cause
2689 // linker error. So disable the location attribute generation for thread local
2690 // variables for now.
2691 // FIXME: when TLS debug on AIX is ready, remove this setting.
2693}
2694
2696 unsigned Priority, const MCSymbol *KeySym) const {
2697 report_fatal_error("no static constructor section on AIX");
2698}
2699
2701 unsigned Priority, const MCSymbol *KeySym) const {
2702 report_fatal_error("no static destructor section on AIX");
2703}
2704
2707 assert(!isa<GlobalIFunc>(GV) && "GlobalIFunc is not supported on AIX.");
2708
2709 switch (GV->getLinkage()) {
2712 return XCOFF::C_HIDEXT;
2716 return XCOFF::C_EXT;
2722 return XCOFF::C_WEAKEXT;
2725 "There is no mapping that implements AppendingLinkage for XCOFF.");
2726 }
2727 llvm_unreachable("Unknown linkage type!");
2728}
2729
2731 const GlobalValue *Func, const TargetMachine &TM) const {
2732 assert((isa<Function>(Func) || isa<GlobalIFunc>(Func) ||
2733 (isa<GlobalAlias>(Func) &&
2735 cast<GlobalAlias>(Func)->getAliaseeObject()))) &&
2736 "Func must be a function or an alias which has a function as base "
2737 "object.");
2738
2739 SmallString<128> NameStr;
2740 NameStr.push_back('.');
2741 getNameWithPrefix(NameStr, Func, TM);
2742
2743 // When -function-sections is enabled and explicit section is not specified,
2744 // it's not necessary to emit function entry point label any more. We will use
2745 // function entry point csect instead. And for function delcarations, the
2746 // undefined symbols gets treated as csect with XTY_ER property.
2747 if (((TM.getFunctionSections() && !Func->hasSection()) ||
2748 Func->isDeclarationForLinker()) &&
2749 (isa<Function>(Func) || isa<GlobalIFunc>(Func))) {
2750 return getContext()
2752 NameStr, SectionKind::getText(),
2753 XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclarationForLinker()
2755 : XCOFF::XTY_SD))
2757 }
2758
2759 return getContext().getOrCreateSymbol(NameStr);
2760}
2761
2763 const GlobalObject *F, const TargetMachine &TM) const {
2765 "F must be a function or ifunc object.");
2766 SmallString<128> NameStr;
2767 getNameWithPrefix(NameStr, F, TM);
2768 return getContext().getXCOFFSection(
2769 NameStr, SectionKind::getData(),
2771}
2772
2774 const MCSymbol *Sym, const TargetMachine &TM) const {
2775 const XCOFF::StorageMappingClass SMC = [](const MCSymbol *Sym,
2776 const TargetMachine &TM) {
2777 auto *XSym = static_cast<const MCSymbolXCOFF *>(Sym);
2778
2779 // The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC,
2780 // otherwise the AIX assembler will complain.
2781 if (XSym->getSymbolTableName() == "_$TLSML")
2782 return XCOFF::XMC_TC;
2783
2784 // Use large code model toc entries for ehinfo symbols as they are
2785 // never referenced directly. The runtime loads their TOC entry
2786 // addresses from the trace-back table.
2787 if (XSym->isEHInfo())
2788 return XCOFF::XMC_TE;
2789
2790 // If the symbol does not have a code model specified use the module value.
2791 if (!XSym->hasPerSymbolCodeModel())
2792 return TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE
2793 : XCOFF::XMC_TC;
2794
2795 return XSym->getPerSymbolCodeModel() == MCSymbolXCOFF::CM_Large
2797 : XCOFF::XMC_TC;
2798 }(Sym, TM);
2799
2800 return getContext().getXCOFFSection(
2801 static_cast<const MCSymbolXCOFF *>(Sym)->getSymbolTableName(),
2803}
2804
2806 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2807 auto *LSDA = static_cast<MCSectionXCOFF *>(LSDASection);
2808 if (TM.getFunctionSections()) {
2809 // If option -ffunction-sections is on, append the function name to the
2810 // name of the LSDA csect so that each function has its own LSDA csect.
2811 // This helps the linker to garbage-collect EH info of unused functions.
2812 SmallString<128> NameStr = LSDA->getName();
2813 raw_svector_ostream(NameStr) << '.' << F.getName();
2814 LSDA = getContext().getXCOFFSection(NameStr, LSDA->getKind(),
2815 LSDA->getCsectProp());
2816 }
2817 return LSDA;
2818}
2819//===----------------------------------------------------------------------===//
2820// GOFF
2821//===----------------------------------------------------------------------===//
2823
2825 // Construct the default names for the root SD and the ADA PR symbol.
2826 StringRef FileName = sys::path::stem(M.getSourceFileName());
2827 if (FileName.size() > 1 && FileName.starts_with('<') &&
2828 FileName.ends_with('>'))
2829 FileName = FileName.substr(1, FileName.size() - 2);
2830 DefaultRootSDName = Twine(FileName).concat("#C").str();
2831 DefaultADAPRName = Twine(FileName).concat("#S").str();
2832 MCSectionGOFF *RootSD =
2833 static_cast<MCSectionGOFF *>(TextSection)->getParent();
2834 MCSectionGOFF *ADAPR = static_cast<MCSectionGOFF *>(ADASection);
2835 RootSD->setName(DefaultRootSDName);
2836 ADAPR->setName(DefaultADAPRName);
2837 // Initialize the label for the text section.
2838 MCSymbolGOFF *TextLD = static_cast<MCSymbolGOFF *>(
2839 getContext().getOrCreateSymbol(RootSD->getName()));
2842 TextLD->setExternal(false);
2843 TextLD->setWeak(false);
2844 TextLD->setADA(ADAPR);
2845 TextSection->setBeginSymbol(TextLD);
2846 // Initialize the label for the ADA section.
2847 MCSymbolGOFF *ADASym = static_cast<MCSymbolGOFF *>(
2849 ADAPR->setBeginSymbol(ADASym);
2850}
2851
2853 bool UsesLabelDifference, const Function &F) const {
2854 return true;
2855}
2856
2861
2863 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2864 std::string Name = ".gcc_exception_table." + F.getName().str();
2865
2866 MCSectionGOFF *WSA = getContext().getGOFFSection(
2871 static_cast<MCSectionGOFF *>(TextSection)->getParent());
2872 WSA->setAlignment(Align(4)); // Fullword
2873 return getContext().getGOFFSection(SectionKind::getData(), Name,
2877 WSA);
2878}
2879
2881 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2882 auto *Symbol = TM.getSymbol(GO);
2883
2884 if (Kind.isBSS() || Kind.isData()) {
2885 GOFF::ESDBindingScope PRBindingScope =
2886 GO->hasExternalLinkage()
2890 GOFF::ESDBindingScope SDBindingScope =
2893 MaybeAlign Alignment;
2894 if (auto *F = dyn_cast<Function>(GO))
2895 Alignment = F->getAlign();
2896 else if (auto *V = dyn_cast<GlobalVariable>(GO))
2897 Alignment = V->getAlign();
2898 MCSectionGOFF *SD = getContext().getGOFFSection(
2899 SectionKind::getMetadata(), Symbol->getName(),
2900 GOFF::SDAttr{GOFF::ESD_TA_Unspecified, SDBindingScope});
2901 MCSectionGOFF *ED = getContext().getGOFFSection(
2906 SD);
2907 ED->setAlignment(Alignment.value_or(llvm::Align(8)));
2908 return getContext().getGOFFSection(Kind, Symbol->getName(),
2909 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
2910 GOFF::ESD_LT_XPLink,
2911 PRBindingScope, 0},
2912 ED);
2913 }
2914 return TextSection;
2915}
2916
2917MCSection *
2919 // XL C/C++ compilers on z/OS support priorities from min-int to max-int, with
2920 // sinit as source priority 0. For clang, sinit has source priority 65535.
2921 // For GOFF, the priority sortkey field is an unsigned value. So, we
2922 // add min-int to get sorting to work properly but also subtract the
2923 // clang sinit (65535) value so internally xl sinit and clang sinit have
2924 // the same unsigned GOFF priority sortkey field value (i.e. 0x80000000).
2925 static constexpr const uint32_t ClangDefaultSinitPriority = 65535;
2926 uint32_t Prio = Priority + (0x80000000 - ClangDefaultSinitPriority);
2927
2928 std::string Name(".xtor");
2929 if (Priority != ClangDefaultSinitPriority)
2930 Name = llvm::Twine(Name).concat(".").concat(llvm::utostr(Priority)).str();
2931
2932 MCContext &Ctx = getContext();
2933 MCSectionGOFF *SInit = Ctx.getGOFFSection(
2939 static_cast<const MCSectionGOFF *>(TextSection)->getParent());
2940
2941 MCSectionGOFF *Xtor = Ctx.getGOFFSection(
2942 SectionKind::getData(), Name,
2944 GOFF::ESD_BSC_Section, Prio},
2945 SInit);
2946 return Xtor;
2947}
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:446
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
const char * Msg
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:1513
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:274
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:521
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:205
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:66
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:342
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
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
void setAlignment(Align Value)
Definition MCSection.h:658
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:425
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:509
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:767
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:438
void emitInt8(uint64_t Value)
Definition MCStreamer.h:765
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:213
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:1069
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1426
Metadata * get() const
Definition Metadata.h:920
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:305
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:320
A tuple of MDNodes.
Definition Metadata.h:1753
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:597
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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.
MCTargetOptions MCOptions
Machine level options.
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:751
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:511
bool isOSFreeBSD() const
Definition Triple.h:745
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:319
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:1262
@ SHF_STRINGS
Definition ELF.h:1265
@ SHF_AARCH64_PURECODE
Definition ELF.h:1354
@ SHF_EXCLUDE
Definition ELF.h:1290
@ SHF_ALLOC
Definition ELF.h:1256
@ SHF_LINK_ORDER
Definition ELF.h:1271
@ SHF_GROUP
Definition ELF.h:1278
@ SHF_SUNW_NODISCARD
Definition ELF.h:1297
@ SHF_X86_64_LARGE
Definition ELF.h:1319
@ SHF_GNU_RETAIN
Definition ELF.h:1287
@ SHF_WRITE
Definition ELF.h:1253
@ SHF_TLS
Definition ELF.h:1281
@ SHF_ARM_PURECODE
Definition ELF.h:1351
@ SHF_EXECINSTR
Definition ELF.h:1259
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition ELF.h:1186
@ SHT_PROGBITS
Definition ELF.h:1155
@ SHT_LLVM_LINKER_OPTIONS
Definition ELF.h:1183
@ SHT_NOBITS
Definition ELF.h:1162
@ SHT_LLVM_OFFLOADING
Definition ELF.h:1194
@ SHT_LLVM_LTO
Definition ELF.h:1195
@ SHT_PREINIT_ARRAY
Definition ELF.h:1168
@ SHT_INIT_ARRAY
Definition ELF.h:1166
@ SHT_NOTE
Definition ELF.h:1161
@ SHT_FINI_ARRAY
Definition ELF.h:1167
@ 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
@ ESD_ALIGN_Doubleword
Definition GOFF.h:148
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:887
@ DW_EH_PE_pcrel
Definition Dwarf.h:885
@ DW_EH_PE_sdata4
Definition Dwarf.h:882
@ DW_EH_PE_sdata8
Definition Dwarf.h:883
@ DW_EH_PE_absptr
Definition Dwarf.h:874
@ DW_EH_PE_udata4
Definition Dwarf.h:878
@ DW_EH_PE_udata8
Definition Dwarf.h:879
@ DW_EH_PE_indirect
Definition Dwarf.h:890
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:596
@ 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:573
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:2026
std::string encodeBase64(InputBytes const &Bytes)
Definition Base64.h:24
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:94
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
LLVM_ABI 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:898
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