LLVM 24.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
82 "jumptable-in-function-section", cl::Hidden, cl::init(false),
83 cl::desc("Putting Jump Table in function section"));
84
85static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
86 StringRef &Section) {
88 M.getModuleFlagsMetadata(ModuleFlags);
89
90 for (const auto &MFE: ModuleFlags) {
91 // Ignore flags with 'Require' behaviour.
92 if (MFE.Behavior == Module::Require)
93 continue;
94
95 StringRef Key = MFE.Key->getString();
96 if (Key == "Objective-C Image Info Version") {
97 Version = mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
98 } else if (Key == "Objective-C Garbage Collection" ||
99 Key == "Objective-C GC Only" ||
100 Key == "Objective-C Is Simulated" ||
101 Key == "Objective-C Class Properties" ||
102 Key == "Objective-C Image Swift Version") {
103 Flags |= mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
104 } else if (Key == "Objective-C Image Info Section") {
105 Section = cast<MDString>(MFE.Val)->getString();
106 }
107 // Backend generates L_OBJC_IMAGE_INFO from Swift ABI version + major + minor +
108 // "Objective-C Garbage Collection".
109 else if (Key == "Swift ABI Version") {
110 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 8;
111 } else if (Key == "Swift Major Version") {
112 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 24;
113 } else if (Key == "Swift Minor Version") {
114 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 16;
115 }
116 }
117}
118
119//===----------------------------------------------------------------------===//
120// ELF
121//===----------------------------------------------------------------------===//
122
124 const TargetMachine &TgtM) {
126
127 const CodeModel::Model CM = TgtM.getCodeModel();
129
130 switch (TgtM.getTargetTriple().getArch()) {
131 case Triple::arm:
132 case Triple::armeb:
133 case Triple::thumb:
134 case Triple::thumbeb:
135 if (Ctx.getAsmInfo().getExceptionHandlingType() == ExceptionHandling::ARM)
136 break;
137 // Fallthrough if not using EHABI
138 [[fallthrough]];
139 case Triple::ppc:
140 case Triple::ppcle:
141 case Triple::x86:
154 break;
155 case Triple::x86_64: {
156 // The large EH encoding forces 64-bit-wide EH pointers regardless of the
157 // code model, so treat it like the Large code model when selecting
158 // encodings below.
159 const CodeModel::Model EHCM =
161 if (isPositionIndependent()) {
164 ((EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
171 ((EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
174 } else {
176 (EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
183 }
184 break;
185 }
186 case Triple::hexagon:
190 if (isPositionIndependent()) {
194 }
195 break;
196 case Triple::aarch64:
199 // The small model guarantees static code/data size < 4GB, but not where it
200 // will be in memory. Most of these could end up >2GB away so even a signed
201 // pc-relative 32-bit address is insufficient, theoretically.
202 //
203 // Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
205 (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32
210 break;
211 case Triple::lanai:
215 break;
216 case Triple::mips:
217 case Triple::mipsel:
218 case Triple::mips64:
219 case Triple::mips64el:
220 // MIPS uses indirect pointer to refer personality functions and types, so
221 // that the eh_frame section can be read-only. DW.ref.personality will be
222 // generated for relocation.
224 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
225 // identify N64 from just a triple.
228
229 // FreeBSD must be explicit about the data size and using pcrel since it's
230 // assembler/linker won't do the automatic conversion that the Linux tools
231 // do.
235 }
236 break;
237 case Triple::ppc64:
238 case Triple::ppc64le:
244 break;
245 case Triple::sparcel:
246 case Triple::sparc:
247 if (isPositionIndependent()) {
253 } else {
257 }
259 break;
260 case Triple::riscv32:
261 case Triple::riscv64:
270 break;
271 case Triple::sparcv9:
273 if (isPositionIndependent()) {
278 } else {
281 }
282 break;
283 case Triple::systemz:
284 // All currently-defined code models guarantee that 4-byte PC-relative
285 // values will be in range.
286 if (isPositionIndependent()) {
292 } else {
296 }
297 break;
305 break;
306 default:
307 break;
308 }
309}
310
313 collectUsedGlobalVariables(M, Vec, false);
314 for (GlobalValue *GV : Vec)
315 if (auto *GO = dyn_cast<GlobalObject>(GV))
316 Used.insert(GO);
317}
318
320 Module &M) const {
321 auto &C = getContext();
322
324
325 if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
326 auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
328
329 Streamer.switchSection(S);
330
331 for (const auto *Operand : DependentLibraries->operands()) {
332 Streamer.emitBytes(
333 cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
334 Streamer.emitInt8(0);
335 }
336 }
337
339
340 if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
341 // Emit the metadata for llvm statistics into .llvm_stats section, which is
342 // formatted as a list of key/value pair, the value is base64 encoded.
343 auto *S = C.getObjectFileInfo()->getLLVMStatsSection();
344 Streamer.switchSection(S);
345 for (const auto *Operand : LLVMStats->operands()) {
346 const auto *MD = cast<MDNode>(Operand);
347 assert(MD->getNumOperands() % 2 == 0 &&
348 ("Operand num should be even for a list of key/value pair"));
349 for (size_t I = 0; I < MD->getNumOperands(); I += 2) {
350 // Encode the key string size.
351 auto *Key = cast<MDString>(MD->getOperand(I));
352 Streamer.emitULEB128IntValue(Key->getString().size());
353 Streamer.emitBytes(Key->getString());
354 // Encode the value into a Base64 string.
355 std::string Value = encodeBase64(
356 Twine(mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1))
357 ->getZExtValue())
358 .str());
359 Streamer.emitULEB128IntValue(Value.size());
360 Streamer.emitBytes(Value);
361 }
362 }
363 }
364
365 unsigned Version = 0;
366 unsigned Flags = 0;
367 StringRef Section;
368
369 GetObjCImageInfo(M, Version, Flags, Section);
370 if (!Section.empty()) {
371 auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
372 Streamer.switchSection(S);
373 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
374 Streamer.emitInt32(Version);
375 Streamer.emitInt32(Flags);
376 Streamer.addBlankLine();
377 }
378
380}
381
383 Module &M) const {
384 auto &C = getContext();
385 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
386 auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS,
388
389 Streamer.switchSection(S);
390
391 for (const auto *Operand : LinkerOptions->operands()) {
392 if (cast<MDNode>(Operand)->getNumOperands() != 2)
393 report_fatal_error("invalid llvm.linker.options");
394 for (const auto &Option : cast<MDNode>(Operand)->operands()) {
395 Streamer.emitBytes(cast<MDString>(Option)->getString());
396 Streamer.emitInt8(0);
397 }
398 }
399 }
400}
401
403 const GlobalValue *GV, const TargetMachine &TM,
404 MachineModuleInfo *MMI) const {
405 unsigned Encoding = getPersonalityEncoding();
406 if ((Encoding & 0x80) == DW_EH_PE_indirect)
407 return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
408 TM.getSymbol(GV)->getName());
409 if ((Encoding & 0x70) == DW_EH_PE_absptr)
410 return TM.getSymbol(GV);
411 report_fatal_error("We do not support this DWARF encoding yet!");
412}
413
415 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
416 const MachineModuleInfo *MMI) const {
417 SmallString<64> NameData("DW.ref.");
418 NameData += Sym->getName();
419 auto *Label =
420 static_cast<MCSymbolELF *>(getContext().getOrCreateSymbol(NameData));
421 Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
422 Streamer.emitSymbolAttribute(Label, MCSA_Weak);
423 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
424 MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
425 ELF::SHT_PROGBITS, Flags, 0);
426 unsigned Size = DL.getPointerSize();
427 Streamer.switchSection(Sec);
428 Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0));
429 Streamer.emitSymbolAttribute(Label, MCSA_ELF_TypeObject);
431 Streamer.emitELFSize(Label, E);
432 Streamer.emitLabel(Label);
433
435}
436
438 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym,
439 const MachineModuleInfo *MMI) const {
440 Streamer.emitSymbolValue(Sym, DL.getPointerSize());
441}
442
444 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
446 if (Encoding & DW_EH_PE_indirect) {
448
449 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
450
451 // Add information about the stub reference to ELFMMI so that the stub
452 // gets emitted by the asmprinter.
454 if (!StubSym.getPointer()) {
455 MCSymbol *Sym = TM.getSymbol(GV);
457 }
458
461 Encoding & ~DW_EH_PE_indirect, Streamer);
462 }
463
465 MMI, Streamer);
466}
467
469 // N.B.: The defaults used in here are not the same ones used in MC.
470 // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
471 // both gas and MC will produce a section with no flags. Given
472 // section(".eh_frame") gcc will produce:
473 //
474 // .section .eh_frame,"a",@progbits
475
476 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
477 /*AddSegmentInfo=*/false) ||
478 Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
479 /*AddSegmentInfo=*/false) ||
480 Name == getInstrProfSectionName(IPSK_covdata, Triple::ELF,
481 /*AddSegmentInfo=*/false) ||
482 Name == getInstrProfSectionName(IPSK_covname, Triple::ELF,
483 /*AddSegmentInfo=*/false) ||
484 Name == ".llvmbc" || Name == ".llvmcmd")
486
487 if (!Name.starts_with(".")) return K;
488
489 // Default implementation based on some magic section names.
490 if (Name == ".bss" || Name.starts_with(".bss.") ||
491 Name.starts_with(".gnu.linkonce.b.") ||
492 Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
493 Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||
494 Name.starts_with(".llvm.linkonce.sb."))
495 return SectionKind::getBSS();
496
497 if (Name == ".tdata" || Name.starts_with(".tdata.") ||
498 Name.starts_with(".gnu.linkonce.td.") ||
499 Name.starts_with(".llvm.linkonce.td."))
501
502 if (Name == ".tbss" || Name.starts_with(".tbss.") ||
503 Name.starts_with(".gnu.linkonce.tb.") ||
504 Name.starts_with(".llvm.linkonce.tb."))
506
507 return K;
508}
509
511 return SectionName.consume_front(Prefix) &&
512 (SectionName.empty() || SectionName[0] == '.');
513}
514
515static unsigned getELFSectionType(StringRef Name, SectionKind K) {
516 // Use SHT_NOTE for section whose name starts with ".note" to allow
517 // emitting ELF notes from C variable declaration.
518 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
519 if (Name.starts_with(".note"))
520 return ELF::SHT_NOTE;
521
522 if (hasPrefix(Name, ".init_array"))
523 return ELF::SHT_INIT_ARRAY;
524
525 if (hasPrefix(Name, ".fini_array"))
526 return ELF::SHT_FINI_ARRAY;
527
528 if (hasPrefix(Name, ".preinit_array"))
530
531 if (hasPrefix(Name, ".llvm.offloading"))
533 if (Name == ".llvm.lto")
534 return ELF::SHT_LLVM_LTO;
535
536 if (K.isBSS() || K.isThreadBSS())
537 return ELF::SHT_NOBITS;
538
539 return ELF::SHT_PROGBITS;
540}
541
542static unsigned getELFSectionFlags(SectionKind K, const Triple &T) {
543 unsigned Flags = 0;
544
545 if (!K.isMetadata() && !K.isExclude())
546 Flags |= ELF::SHF_ALLOC;
547
548 if (K.isExclude())
549 Flags |= ELF::SHF_EXCLUDE;
550
551 if (K.isText())
552 Flags |= ELF::SHF_EXECINSTR;
553
554 if (K.isExecuteOnly()) {
555 if (T.isAArch64())
557 else if (T.isARM() || T.isThumb())
558 Flags |= ELF::SHF_ARM_PURECODE;
559 }
560
561 if (K.isWriteable())
562 Flags |= ELF::SHF_WRITE;
563
564 if (K.isThreadLocal())
565 Flags |= ELF::SHF_TLS;
566
567 if (K.isMergeableCString() || K.isMergeableConst())
568 Flags |= ELF::SHF_MERGE;
569
570 if (K.isMergeableCString())
571 Flags |= ELF::SHF_STRINGS;
572
573 return Flags;
574}
575
576static const Comdat *getELFComdat(const GlobalValue *GV) {
577 const Comdat *C = GV->getComdat();
578 if (!C)
579 return nullptr;
580
581 if (C->getSelectionKind() != Comdat::Any &&
582 C->getSelectionKind() != Comdat::NoDeduplicate)
583 report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
584 "SelectionKind::NoDeduplicate, '" +
585 C->getName() + "' cannot be lowered.");
586
587 return C;
588}
589
591 const TargetMachine &TM) {
592 MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
593 if (!MD)
594 return nullptr;
595
596 auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
597 auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
598 return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV))
599 : nullptr;
600}
601
602static unsigned getEntrySizeForKind(SectionKind Kind) {
603 if (Kind.isMergeable1ByteCString())
604 return 1;
605 else if (Kind.isMergeable2ByteCString())
606 return 2;
607 else if (Kind.isMergeable4ByteCString())
608 return 4;
609 else if (Kind.isMergeableConst4())
610 return 4;
611 else if (Kind.isMergeableConst8())
612 return 8;
613 else if (Kind.isMergeableConst16())
614 return 16;
615 else if (Kind.isMergeableConst32())
616 return 32;
617 else {
618 // We shouldn't have mergeable C strings or mergeable constants that we
619 // didn't handle above.
620 assert(!Kind.isMergeableCString() && "unknown string width");
621 assert(!Kind.isMergeableConst() && "unknown data width");
622 return 0;
623 }
624}
625
626/// Return the section prefix name used by options FunctionsSections and
627/// DataSections.
629 if (Kind.isText())
630 return IsLarge ? ".ltext" : ".text";
631 if (Kind.isReadOnly())
632 return IsLarge ? ".lrodata" : ".rodata";
633 if (Kind.isBSS())
634 return IsLarge ? ".lbss" : ".bss";
635 if (Kind.isThreadData())
636 return ".tdata";
637 if (Kind.isThreadBSS())
638 return ".tbss";
639 if (Kind.isData())
640 return IsLarge ? ".ldata" : ".data";
641 if (Kind.isReadOnlyWithRel())
642 return IsLarge ? ".ldata.rel.ro" : ".data.rel.ro";
643 llvm_unreachable("Unknown section kind");
644}
645
646static SmallString<128>
648 Mangler &Mang, const TargetMachine &TM,
649 bool UniqueSectionName,
650 const MachineJumpTableEntry *JTE) {
651 SmallString<128> Name =
653 unsigned EntrySize = getEntrySizeForKind(Kind);
654 if (Kind.isMergeableCString()) {
655 // We also need alignment here.
656 // FIXME: this is getting the alignment of the character, not the
657 // alignment of the global!
658 Align Alignment = GO->getDataLayout().getPreferredAlign(
660
661 Name += ".str";
662 Name += utostr(EntrySize);
663 Name += ".";
664 Name += utostr(Alignment.value());
665 } else if (Kind.isMergeableConst()) {
666 Name += ".cst";
667 Name += utostr(EntrySize);
668 }
669
670 bool HasPrefix = false;
671 SmallString<32> SectionPrefix;
672 if (const auto *F = dyn_cast<Function>(GO)) {
673 // Jump table hotness takes precedence over its enclosing function's hotness
674 // if it's known. The function's section prefix is used if jump table entry
675 // hotness is unknown.
676 if (JTE && JTE->Hotness != MachineFunctionDataHotness::Unknown) {
677 switch (JTE->Hotness) {
679 raw_svector_ostream(SectionPrefix) << ".unlikely";
680 break;
683 raw_svector_ostream(SectionPrefix) << ".hot";
684 break;
685 }
686 default:
687 llvm_unreachable("Unknown jump table hotness");
688 break;
689 }
690 } else if (std::optional<StringRef> Prefix = F->getSectionPrefix())
691 raw_svector_ostream(SectionPrefix) << "." << *Prefix;
692 } else if (const auto *GV = dyn_cast<GlobalVariable>(GO)) {
693 if (std::optional<StringRef> Prefix = GV->getSectionPrefix()) {
694 raw_svector_ostream(SectionPrefix) << "." << *Prefix;
695 }
696 }
697
698 if (!SectionPrefix.empty()) {
699 bool AddSectionPrefix = true;
700 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel() || Kind.isData() ||
701 Kind.isBSS()) {
702 AddSectionPrefix =
703 !SectionPrefix.starts_with(".hot") || PreserveHotDataSectionPrefix;
704 }
705
706 if (AddSectionPrefix) {
707 Name += SectionPrefix;
708 HasPrefix = true;
709 }
710 }
711
712 if (UniqueSectionName) {
713 Name.push_back('.');
714 TM.getNameWithPrefix(Name, GO, Mang, /*MayAlwaysUsePrivate*/true);
715 } else if (HasPrefix)
716 // For distinguishing between .text.${text-section-prefix}. (with trailing
717 // dot) and .text.${function-name}
718 Name.push_back('.');
719 return Name;
720}
721
722namespace {
723class LoweringDiagnosticInfo : public DiagnosticInfo {
724 const Twine &Msg;
725
726public:
727 LoweringDiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND,
728 DiagnosticSeverity Severity = DS_Error)
729 : DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
730 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
731};
732}
733
734/// Calculate an appropriate unique ID for a section, and update Flags,
735/// EntrySize and NextUniqueID where appropriate.
736static unsigned
738 SectionKind Kind, const TargetMachine &TM,
739 MCContext &Ctx, Mangler &Mang, unsigned &Flags,
740 unsigned &EntrySize, unsigned &NextUniqueID,
741 const bool Retain, const bool ForceUnique) {
742 // Increment uniqueID if we are forced to emit a unique section.
743 // This works perfectly fine with section attribute or pragma section as the
744 // sections with the same name are grouped together by the assembler.
745 if (ForceUnique)
746 return NextUniqueID++;
747
748 // A section can have at most one associated section. Put each global with
749 // MD_associated in a unique section.
750 const bool Associated = GO->getMetadata(LLVMContext::MD_associated);
751 if (Associated) {
752 Flags |= ELF::SHF_LINK_ORDER;
753 return NextUniqueID++;
754 }
755
756 if (Retain) {
757 if (TM.getTargetTriple().isOSSolaris())
759 else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
760 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36))
761 Flags |= ELF::SHF_GNU_RETAIN;
762 return NextUniqueID++;
763 }
764
765 // If two symbols with differing sizes end up in the same mergeable section
766 // that section can be assigned an incorrect entry size. To avoid this we
767 // usually put symbols of the same size into distinct mergeable sections with
768 // the same name. Doing so relies on the ",unique ," assembly feature. This
769 // feature is not available until binutils version 2.35
770 // (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
771 const bool SupportsUnique = Ctx.getAsmInfo().useIntegratedAssembler() ||
772 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35);
773 if (!SupportsUnique) {
774 Flags &= ~ELF::SHF_MERGE;
775 EntrySize = 0;
777 }
778
779 const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
780 const bool SeenSectionNameBefore =
781 Ctx.isELFGenericMergeableSection(SectionName);
782 // If this is the first occurrence of this section name, treat it as the
783 // generic section
784 if (!SymbolMergeable && !SeenSectionNameBefore) {
786 return NextUniqueID++;
787 else
789 }
790
791 // Symbols must be placed into sections with compatible entry sizes. Generate
792 // unique sections for symbols that have not been assigned to compatible
793 // sections.
794 const auto PreviousID =
795 Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
796 if (PreviousID &&
797 (!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
798 return *PreviousID;
799
800 // If the user has specified the same section name as would be created
801 // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
802 // to unique the section as the entry size for this symbol will be
803 // compatible with implicitly created sections.
804 SmallString<128> ImplicitSectionNameStem =
805 getELFSectionNameForGlobal(GO, Kind, Mang, TM, false, /*MJTE=*/nullptr);
806 if (SymbolMergeable &&
807 Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
808 SectionName.starts_with(ImplicitSectionNameStem))
810
811 // We have seen this section name before, but with different flags or entity
812 // size. Create a new unique ID.
813 return NextUniqueID++;
814}
815
816static std::tuple<StringRef, bool, unsigned, unsigned, unsigned>
819 StringRef Group = "";
820 bool IsComdat = false;
821 unsigned Flags = 0;
822 if (const Comdat *C = getELFComdat(GO)) {
823 Flags |= ELF::SHF_GROUP;
824 Group = C->getName();
825 IsComdat = C->getSelectionKind() == Comdat::Any;
826 }
827 if (TM.isLargeGlobalValue(GO))
828 Flags |= ELF::SHF_X86_64_LARGE;
829
830 unsigned Type, EntrySize;
831 if (MDNode *MD = GO->getMetadata(LLVMContext::MD_elf_section_properties)) {
832 Type = cast<ConstantAsMetadata>(MD->getOperand(0))
833 ->getValue()
834 ->getUniqueInteger()
835 .getZExtValue();
836 EntrySize = cast<ConstantAsMetadata>(MD->getOperand(1))
837 ->getValue()
838 ->getUniqueInteger()
839 .getZExtValue();
840 } else {
842 EntrySize = getEntrySizeForKind(Kind);
843 }
844
845 return {Group, IsComdat, Flags, Type, EntrySize};
846}
847
849 SectionKind Kind,
850 const TargetMachine &TM,
851 MCContext &Ctx, Mangler &Mang,
852 unsigned &NextUniqueID,
853 bool Retain, bool ForceUnique) {
856
857 // Infer section flags from the section name if we can.
859
860 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
861 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
862 getGlobalObjectInfo(GO, TM, SectionName, Kind);
863 Flags |= ExtraFlags;
864
866 GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
867 Retain, ForceUnique);
868
869 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
870 MCSectionELF *Section =
871 Ctx.getELFSection(SectionName, Type, Flags, EntrySize, Group, IsComdat,
872 UniqueID, LinkedToSym);
873 // Make sure that we did not get some other section with incompatible sh_link.
874 // This should not be possible due to UniqueID code above.
875 assert(Section->getLinkedToSymbol() == LinkedToSym &&
876 "Associated symbol mismatch between sections");
877
878 if (!(Ctx.getAsmInfo().useIntegratedAssembler() ||
879 Ctx.getAsmInfo().binutilsIsAtLeast(2, 35))) {
880 // If we are using GNU as before 2.35, then this symbol might have
881 // been placed in an incompatible mergeable section. Emit an error if this
882 // is the case to avoid creating broken output.
883 if ((Section->getFlags() & ELF::SHF_MERGE) &&
884 (Section->getEntrySize() != getEntrySizeForKind(Kind)))
885 GO->getContext().diagnose(LoweringDiagnosticInfo(
886 "Symbol '" + GO->getName() + "' from module '" +
887 (GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
888 "' required a section with entry-size=" +
889 Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
890 SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
891 ": Explicit assignment by pragma or attribute of an incompatible "
892 "symbol to this section?"));
893 }
894
895 return Section;
896}
897
899 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
901 NextUniqueID, Used.count(GO),
902 /* ForceUnique = */false);
903}
904
906 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
907 const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
908 unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol,
909 const MachineJumpTableEntry *MJTE = nullptr) {
910 bool UniqueSectionName = false;
912 if (EmitUniqueSection) {
913 if (TM.getUniqueSectionNames()) {
914 UniqueSectionName = true;
915 } else {
916 UniqueID = *NextUniqueID;
917 (*NextUniqueID)++;
918 }
919 }
920 SmallString<128> Name =
921 getELFSectionNameForGlobal(GO, Kind, Mang, TM, UniqueSectionName, MJTE);
922
923 auto [Group, IsComdat, ExtraFlags, Type, EntrySize] =
924 getGlobalObjectInfo(GO, TM, Name, Kind);
925 Flags |= ExtraFlags;
926
927 // Use 0 as the unique ID for execute-only text.
928 if (Kind.isExecuteOnly())
929 UniqueID = 0;
930 return Ctx.getELFSection(Name, Type, Flags, EntrySize, Group, IsComdat,
931 UniqueID, AssociatedSymbol);
932}
933
935 MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
936 const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
937 unsigned Flags, unsigned *NextUniqueID) {
938 const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
939 if (LinkedToSym) {
940 EmitUniqueSection = true;
941 Flags |= ELF::SHF_LINK_ORDER;
942 }
943 if (Retain) {
944 if (TM.getTargetTriple().isOSSolaris()) {
945 EmitUniqueSection = true;
947 } else if (Ctx.getAsmInfo().useIntegratedAssembler() ||
948 Ctx.getAsmInfo().binutilsIsAtLeast(2, 36)) {
949 EmitUniqueSection = true;
950 Flags |= ELF::SHF_GNU_RETAIN;
951 }
952 }
953 if (GO->hasMetadata(LLVMContext::MD_elf_section_properties))
954 EmitUniqueSection = true;
955
957 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
958 NextUniqueID, LinkedToSym);
959 assert(Section->getLinkedToSymbol() == LinkedToSym);
960 return Section;
961}
962
964 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
965 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
966
967 // If we have -ffunction-section or -fdata-section then we should emit the
968 // global value to a uniqued section specifically for it.
969 bool EmitUniqueSection = false;
970 if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
971 if (Kind.isText())
972 EmitUniqueSection = TM.getFunctionSections();
973 else
974 EmitUniqueSection = TM.getDataSections();
975 }
976 EmitUniqueSection |= GO->hasComdat();
977 return selectELFSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
978 Used.count(GO), EmitUniqueSection, Flags,
979 &NextUniqueID);
980}
981
983 const Function &F, const TargetMachine &TM) const {
985 unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple());
986 // If the function's section names is pre-determined via pragma or a
987 // section attribute, call selectExplicitSectionGlobal.
988 if (F.hasSection())
990 &F, Kind, TM, getContext(), getMangler(), NextUniqueID,
991 Used.count(&F), /* ForceUnique = */true);
992
994 getContext(), &F, Kind, getMangler(), TM, Used.count(&F),
995 /*EmitUniqueSection=*/true, Flags, &NextUniqueID);
996}
997
999 const Function &F, const TargetMachine &TM) const {
1000 return getSectionForJumpTable(F, TM, /*JTE=*/nullptr);
1001}
1002
1004 const Function &F, const TargetMachine &TM,
1005 const MachineJumpTableEntry *JTE) const {
1006 // If the function can be removed, produce a unique section so that
1007 // the table doesn't prevent the removal.
1008 const Comdat *C = F.getComdat();
1009 bool EmitUniqueSection = TM.getFunctionSections() || C;
1010 if (!EmitUniqueSection && !TM.getEnableStaticDataPartitioning())
1011 return ReadOnlySection;
1012
1014 getMangler(), TM, EmitUniqueSection,
1015 ELF::SHF_ALLOC, &NextUniqueID,
1016 /* AssociatedSymbol */ nullptr, JTE);
1017}
1018
1020 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
1021 // If neither COMDAT nor function sections, use the monolithic LSDA section.
1022 // Re-use this path if LSDASection is null as in the Arm EHABI.
1023 if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
1024 return LSDASection;
1025
1026 const auto *LSDA = static_cast<const MCSectionELF *>(LSDASection);
1027 unsigned Flags = LSDA->getFlags();
1028 const MCSymbolELF *LinkedToSym = nullptr;
1029 StringRef Group;
1030 bool IsComdat = false;
1031 if (const Comdat *C = getELFComdat(&F)) {
1032 Flags |= ELF::SHF_GROUP;
1033 Group = C->getName();
1034 IsComdat = C->getSelectionKind() == Comdat::Any;
1035 }
1036 // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
1037 // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
1038 if (TM.getFunctionSections() &&
1039 (getContext().getAsmInfo().useIntegratedAssembler() &&
1040 getContext().getAsmInfo().binutilsIsAtLeast(2, 36))) {
1041 Flags |= ELF::SHF_LINK_ORDER;
1042 LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym);
1043 }
1044
1045 // Append the function name as the suffix like GCC, assuming
1046 // -funique-section-names applies to .gcc_except_table sections.
1047 return getContext().getELFSection(
1048 (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
1049 : LSDA->getName()),
1050 LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
1051 LinkedToSym);
1052}
1053
1055 bool UsesLabelDifference, const Function &F) const {
1056 // We can always create relative relocations, so use another section
1057 // that can be marked non-executable.
1058 return false;
1059}
1060
1061/// Given a mergeable constant with the specified size and relocation
1062/// information, return a section that it should be placed in.
1064 SectionKind Kind,
1065 const Constant *C) const {
1066 if (!TM)
1067 return false;
1068 if (TM->getCodeModel() == CodeModel::Large)
1069 return TM->getTargetTriple().getArch() == Triple::x86_64;
1070 if (Kind.isMergeableCString() && C) {
1071 assert(C->getType()->isSized());
1072 return TM->isLargeDataSize(DL.getTypeAllocSize(C->getType()));
1073 }
1074 // Globals generated by the compiler, e.g. constant pool entries, are always
1075 // small under the x86-64 medium code model.
1076 return false;
1077}
1078
1080 const DataLayout &DL, SectionKind Kind, const Constant *C,
1081 StringRef SectionSuffix) const {
1082 auto &Context = getContext();
1083 unsigned MergeableCstFlags = ELF::SHF_ALLOC;
1084 if (Kind.isMergeableConst() || Kind.isMergeableCString())
1085 MergeableCstFlags |= ELF::SHF_MERGE;
1086 bool IsLarge = isLargeConstant(DL, Kind, C);
1087 if (IsLarge)
1088 MergeableCstFlags |= ELF::SHF_X86_64_LARGE;
1089
1090 StringRef CstPrefix = IsLarge ? ".lrodata" : ".rodata";
1091 SmallString<32> SectionSuffixStr;
1092 if (!SectionSuffix.empty()) {
1093 SectionSuffixStr.push_back('.');
1094 SectionSuffixStr += SectionSuffix;
1095 SectionSuffixStr.push_back('.');
1096 }
1097
1098 if (Kind.isMergeableConst4())
1099 return Context.getELFSection(CstPrefix + ".cst4" + SectionSuffixStr,
1100 ELF::SHT_PROGBITS, MergeableCstFlags, 4);
1101 if (Kind.isMergeableConst8())
1102 return Context.getELFSection(CstPrefix + ".cst8" + SectionSuffixStr,
1103 ELF::SHT_PROGBITS, MergeableCstFlags, 8);
1104 if (Kind.isMergeableConst16())
1105 return Context.getELFSection(CstPrefix + ".cst16" + SectionSuffixStr,
1106 ELF::SHT_PROGBITS, MergeableCstFlags, 16);
1107 if (Kind.isMergeableConst32())
1108 return Context.getELFSection(CstPrefix + ".cst32" + SectionSuffixStr,
1109 ELF::SHT_PROGBITS, MergeableCstFlags, 32);
1110 if (Kind.isReadOnly())
1111 return Context.getELFSection(CstPrefix + SectionSuffixStr,
1113
1114 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1115 return Context.getELFSection(".data.rel.ro" + SectionSuffixStr,
1118}
1119
1121 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1122 const Function *F) const {
1123 return getSectionForConstantImpl(DL, Kind, C, "");
1124}
1125
1127 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1128 const Function *F, StringRef SectionSuffix) const {
1129 if (SectionSuffix.empty())
1130 return getSectionForConstant(DL, Kind, C, Alignment, F);
1131
1132 return getSectionForConstantImpl(DL, Kind, C, SectionSuffix);
1133}
1134
1135/// Returns a unique section for the given machine basic block.
1137 const Function &F, const MachineBasicBlock &MBB,
1138 const TargetMachine &TM) const {
1139 assert(MBB.isBeginSection() && "Basic block does not start a section!");
1141
1142 // For cold sections use the .text.split. prefix along with the parent
1143 // function name. All cold blocks for the same function go to the same
1144 // section. Similarly all exception blocks are grouped by symbol name
1145 // under the .text.eh prefix. For regular sections, we either use a unique
1146 // name, or a unique ID for the section.
1147 SmallString<128> Name;
1148 StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
1149 if (FunctionSectionName == ".text" ||
1150 FunctionSectionName.starts_with(".text.")) {
1151 // Function is in a regular .text section.
1152 StringRef FunctionName = MBB.getParent()->getName();
1153 if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
1155 Name += FunctionName;
1156 } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
1157 Name += ".text.eh.";
1158 Name += FunctionName;
1159 } else {
1160 Name += FunctionSectionName;
1161 if (TM.getUniqueBasicBlockSectionNames()) {
1162 if (!Name.ends_with("."))
1163 Name += ".";
1164 Name += MBB.getSymbol()->getName();
1165 } else {
1166 UniqueID = NextUniqueID++;
1167 }
1168 }
1169 } else {
1170 // If the original function has a custom non-dot-text section, then emit
1171 // all basic block sections into that section too, each with a unique id.
1172 Name = FunctionSectionName;
1173 UniqueID = NextUniqueID++;
1174 }
1175
1176 unsigned Flags =
1177 static_cast<const MCSectionELF *>(MBB.getParent()->getSection())
1178 ->getFlags();
1179 std::string GroupName;
1180 if (F.hasComdat()) {
1181 Flags |= ELF::SHF_GROUP;
1182 GroupName = F.getComdat()->getName().str();
1183 }
1184 return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
1185 0 /* Entry Size */, GroupName,
1186 F.hasComdat(), UniqueID, nullptr);
1187}
1188
1189static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
1190 bool IsCtor, unsigned Priority,
1191 const MCSymbol *KeySym) {
1192 std::string Name;
1193 unsigned Type;
1194 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
1195 StringRef Comdat = KeySym ? KeySym->getName() : "";
1196
1197 if (KeySym)
1198 Flags |= ELF::SHF_GROUP;
1199
1200 if (UseInitArray) {
1201 if (IsCtor) {
1203 Name = ".init_array";
1204 } else {
1206 Name = ".fini_array";
1207 }
1208 if (Priority != 65535) {
1209 Name += '.';
1210 Name += utostr(Priority);
1211 }
1212 } else {
1213 // The default scheme is .ctor / .dtor, so we have to invert the priority
1214 // numbering.
1215 if (IsCtor)
1216 Name = ".ctors";
1217 else
1218 Name = ".dtors";
1219 if (Priority != 65535)
1220 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1222 }
1223
1224 return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
1225}
1226
1228 unsigned Priority, const MCSymbol *KeySym) const {
1229 return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
1230 KeySym);
1231}
1232
1234 unsigned Priority, const MCSymbol *KeySym) const {
1235 return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
1236 KeySym);
1237}
1238
1240 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1241 std::optional<int64_t> PCRelativeOffset) const {
1242 auto &Ctx = getContext();
1243 const MCExpr *Res;
1244 // Return a relocatable expression with the PLT specifier, %plt(GV) or
1245 // %plt(GV-RHS).
1246 if (PCRelativeOffset && PLTPCRelativeSpecifier) {
1247 Res = MCSymbolRefExpr::create(LHS, Ctx);
1248 // The current location is RHS plus *PCRelativeOffset. Compensate for it.
1249 Addend += *PCRelativeOffset;
1250 if (Addend)
1251 Res = MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx),
1252 Ctx);
1254 }
1255
1257 return nullptr;
1260 MCSymbolRefExpr::create(RHS, Ctx), Ctx);
1261 if (Addend)
1262 Res =
1263 MCBinaryExpr::createAdd(Res, MCConstantExpr::create(Addend, Ctx), Ctx);
1264 return Res;
1265}
1266
1267// Reference the PLT entry of a function, optionally with a subtrahend (`RHS`).
1269 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
1270 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
1271 if (RHS)
1272 return lowerSymbolDifference(LHS, RHS, Addend, PCRelativeOffset);
1273
1274 // Only the legacy MCSymbolRefExpr::VariantKind approach is implemented.
1275 // Reference LHS@plt or LHS@plt - RHS.
1278 return nullptr;
1279}
1280
1282 // Use ".GCC.command.line" since this feature is to support clang's
1283 // -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1284 // same name.
1285 return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
1287}
1288
1289void
1291 UseInitArray = UseInitArray_;
1292 MCContext &Ctx = getContext();
1293 if (!UseInitArray) {
1294 StaticCtorSection = Ctx.getELFSection(".ctors", ELF::SHT_PROGBITS,
1296
1297 StaticDtorSection = Ctx.getELFSection(".dtors", ELF::SHT_PROGBITS,
1299 return;
1300 }
1301
1302 StaticCtorSection = Ctx.getELFSection(".init_array", ELF::SHT_INIT_ARRAY,
1304 StaticDtorSection = Ctx.getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
1306}
1307
1308//===----------------------------------------------------------------------===//
1309// MachO
1310//===----------------------------------------------------------------------===//
1311
1315
1317 const TargetMachine &TM) {
1319 if (TM.getRelocationModel() == Reloc::Static) {
1320 StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0,
1322 StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0,
1324 } else {
1325 StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func",
1328 StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func",
1331 }
1332
1338}
1339
1341 unsigned Priority, const MCSymbol *KeySym) const {
1342 return StaticDtorSection;
1343 // In userspace, we lower global destructors via atexit(), but kernel/kext
1344 // environments do not provide this function so we still need to support the
1345 // legacy way here.
1346 // See the -disable-atexit-based-global-dtor-lowering CodeGen flag for more
1347 // context.
1348}
1349
1351 Module &M) const {
1352 // Emit the linker options if present.
1354
1356
1357 unsigned VersionVal = 0;
1358 unsigned ImageInfoFlags = 0;
1359 StringRef SectionVal;
1360
1361 GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1363
1364 // The section is mandatory. If we don't have it, then we don't have GC info.
1365 if (SectionVal.empty())
1366 return;
1367
1368 StringRef Segment, Section;
1369 unsigned TAA = 0, StubSize = 0;
1370 bool TAAParsed;
1372 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1373 // If invalid, report the error with report_fatal_error.
1374 report_fatal_error("Invalid section specifier '" + Section +
1375 "': " + toString(std::move(E)) + ".");
1376 }
1377
1378 // Get the section.
1380 Segment, Section, TAA, StubSize, SectionKind::getData());
1381 Streamer.switchSection(S);
1382 Streamer.emitLabel(getContext().
1383 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1384 Streamer.emitInt32(VersionVal);
1385 Streamer.emitInt32(ImageInfoFlags);
1386 Streamer.addBlankLine();
1387}
1388
1390 Module &M) const {
1391 if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1392 for (const auto *Option : LinkerOptions->operands()) {
1393 SmallVector<std::string, 4> StrOptions;
1394 for (const auto &Piece : cast<MDNode>(Option)->operands())
1395 StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1396 Streamer.emitLinkerOptions(StrOptions);
1397 }
1398 }
1399}
1400
1401static void checkMachOComdat(const GlobalValue *GV) {
1402 const Comdat *C = GV->getComdat();
1403 if (!C)
1404 return;
1405
1406 report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
1407 "' cannot be lowered.");
1408}
1409
1411 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1412
1415
1416 // Parse the section specifier and create it if valid.
1417 StringRef Segment, Section;
1418 unsigned TAA = 0, StubSize = 0;
1419 bool TAAParsed;
1420
1421 checkMachOComdat(GO);
1422
1424 SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1425 // If invalid, report the error with report_fatal_error.
1426 report_fatal_error("Global variable '" + GO->getName() +
1427 "' has an invalid section specifier '" +
1428 GO->getSection() + "': " + toString(std::move(E)) + ".");
1429 }
1430
1431 // Get the section.
1432 MCSectionMachO *S =
1433 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1434
1435 // If TAA wasn't set by ParseSectionSpecifier() above,
1436 // use the value returned by getMachOSection() as a default.
1437 if (!TAAParsed)
1438 TAA = S->getTypeAndAttributes();
1439
1440 // Okay, now that we got the section, verify that the TAA & StubSize agree.
1441 // If the user declared multiple globals with different section flags, we need
1442 // to reject it here.
1443 if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1444 // If invalid, report the error with report_fatal_error.
1445 report_fatal_error("Global variable '" + GO->getName() +
1446 "' section type or attributes does not match previous"
1447 " section specifier");
1448 }
1449
1450 return S;
1451}
1452
1454 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1455 checkMachOComdat(GO);
1456
1457 // Handle thread local data.
1458 if (Kind.isThreadBSS()) return TLSBSSSection;
1459 if (Kind.isThreadData()) return TLSDataSection;
1460
1461 if (Kind.isText())
1463
1464 // If this is weak/linkonce, put this in a coalescable section, either in text
1465 // or data depending on if it is writable.
1466 if (GO->isWeakForLinker()) {
1467 if (Kind.isReadOnly())
1468 return ConstTextCoalSection;
1469 if (Kind.isReadOnlyWithRel())
1470 return ConstDataCoalSection;
1471 return DataCoalSection;
1472 }
1473
1474 // FIXME: Alignment check should be handled by section classifier.
1475 if (Kind.isMergeable1ByteCString() &&
1477 cast<GlobalVariable>(GO)) < Align(32))
1478 return CStringSection;
1479
1480 // Do not put 16-bit arrays in the UString section if they have an
1481 // externally visible label, this runs into issues with certain linker
1482 // versions.
1483 if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1485 cast<GlobalVariable>(GO)) < Align(32))
1486 return UStringSection;
1487
1488 // With MachO only variables whose corresponding symbol starts with 'l' or
1489 // 'L' can be merged, so we only try merging GVs with private linkage.
1490 if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1491 if (Kind.isMergeableConst4())
1493 if (Kind.isMergeableConst8())
1495 if (Kind.isMergeableConst16())
1497 }
1498
1499 // Otherwise, if it is readonly, but not something we can specially optimize,
1500 // just drop it in .const.
1501 if (Kind.isReadOnly())
1502 return ReadOnlySection;
1503
1504 // If this is marked const, put it into a const section. But if the dynamic
1505 // linker needs to write to it, put it in the data segment.
1506 if (Kind.isReadOnlyWithRel())
1507 return ConstDataSection;
1508
1509 // Put zero initialized globals with strong external linkage in the
1510 // DATA, __common section with the .zerofill directive.
1511 if (Kind.isBSSExtern())
1512 return DataCommonSection;
1513
1514 // Put zero initialized globals with local linkage in __DATA,__bss directive
1515 // with the .zerofill directive (aka .lcomm).
1516 if (Kind.isBSSLocal())
1517 return DataBSSSection;
1518
1519 // Otherwise, just drop the variable in the normal data section.
1520 return DataSection;
1521}
1522
1524 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
1525 const Function *F) const {
1526 // If this constant requires a relocation, we have to put it in the data
1527 // segment, not in the text segment.
1528 if (Kind.isData() || Kind.isReadOnlyWithRel())
1529 return ConstDataSection;
1530
1531 if (Kind.isMergeableConst4())
1533 if (Kind.isMergeableConst8())
1535 if (Kind.isMergeableConst16())
1537 return ReadOnlySection; // .const
1538}
1539
1544
1546 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
1547 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1548 // The mach-o version of this method defaults to returning a stub reference.
1549
1550 if (Encoding & DW_EH_PE_indirect) {
1551 MachineModuleInfoMachO &MachOMMI =
1553
1554 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1555
1556 // Add information about the stub reference to MachOMMI so that the stub
1557 // gets emitted by the asmprinter.
1558 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1559 if (!StubSym.getPointer()) {
1560 MCSymbol *Sym = TM.getSymbol(GV);
1562 }
1563
1566 Encoding & ~DW_EH_PE_indirect, Streamer);
1567 }
1568
1570 MMI, Streamer);
1571}
1572
1574 const GlobalValue *GV, const TargetMachine &TM,
1575 MachineModuleInfo *MMI) const {
1576 // The mach-o version of this method defaults to returning a stub reference.
1577 MachineModuleInfoMachO &MachOMMI =
1579
1580 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1581
1582 // Add information about the stub reference to MachOMMI so that the stub
1583 // gets emitted by the asmprinter.
1584 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1585 if (!StubSym.getPointer()) {
1586 MCSymbol *Sym = TM.getSymbol(GV);
1588 }
1589
1590 return SSym;
1591}
1592
1594 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
1595 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1596 // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1597 // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1598 // through a non_lazy_ptr stub instead. One advantage is that it allows the
1599 // computation of deltas to final external symbols. Example:
1600 //
1601 // _extgotequiv:
1602 // .long _extfoo
1603 //
1604 // _delta:
1605 // .long _extgotequiv-_delta
1606 //
1607 // is transformed to:
1608 //
1609 // _delta:
1610 // .long L_extfoo$non_lazy_ptr-(_delta+0)
1611 //
1612 // .section __IMPORT,__pointers,non_lazy_symbol_pointers
1613 // L_extfoo$non_lazy_ptr:
1614 // .indirect_symbol _extfoo
1615 // .long 0
1616 //
1617 // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1618 // may point to both local (same translation unit) and global (other
1619 // translation units) symbols. Example:
1620 //
1621 // .section __DATA,__pointers,non_lazy_symbol_pointers
1622 // L1:
1623 // .indirect_symbol _myGlobal
1624 // .long 0
1625 // L2:
1626 // .indirect_symbol _myLocal
1627 // .long _myLocal
1628 //
1629 // If the symbol is local, instead of the symbol's index, the assembler
1630 // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1631 // Then the linker will notice the constant in the table and will look at the
1632 // content of the symbol.
1633 MachineModuleInfoMachO &MachOMMI =
1635 MCContext &Ctx = getContext();
1636
1637 // The offset must consider the original displacement from the base symbol
1638 // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1639 Offset = -MV.getConstant();
1640 const MCSymbol *BaseSym = MV.getSubSym();
1641
1642 // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1643 // non_lazy_ptr stubs.
1644 SmallString<128> Name;
1645 StringRef Suffix = "$non_lazy_ptr";
1647 Name += Sym->getName();
1648 Name += Suffix;
1649 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1650
1651 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1652
1653 if (!StubSym.getPointer())
1654 StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1655 !GV->hasLocalLinkage());
1656
1657 const MCExpr *BSymExpr = MCSymbolRefExpr::create(BaseSym, Ctx);
1658 const MCExpr *LHS = MCSymbolRefExpr::create(Stub, Ctx);
1659
1660 if (!Offset)
1661 return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1662
1663 const MCExpr *RHS =
1665 return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1666}
1667
1668static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
1669 const MCSection &Section) {
1671 return true;
1672
1673 // FIXME: we should be able to use private labels for sections that can't be
1674 // dead-stripped (there's no issue with blocking atomization there), but `ld
1675 // -r` sometimes drops the no_dead_strip attribute from sections so for safety
1676 // we don't allow it.
1677 return false;
1678}
1679
1681 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1682 const TargetMachine &TM) const {
1683 bool CannotUsePrivateLabel = true;
1684 if (auto *GO = GV->getAliaseeObject()) {
1686 const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
1687 CannotUsePrivateLabel = !canUsePrivateLabel(TM.getMCAsmInfo(), *TheSection);
1688 }
1689 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1690}
1691
1692//===----------------------------------------------------------------------===//
1693// COFF
1694//===----------------------------------------------------------------------===//
1695
1696static unsigned
1698 unsigned Flags = 0;
1700
1701 if (K.isMetadata())
1702 Flags |=
1704 else if (K.isExclude())
1705 Flags |=
1707 else if (K.isText())
1708 Flags |=
1713 else if (K.isBSS())
1714 Flags |=
1718 else if (K.isThreadLocal())
1719 Flags |=
1723 else if (K.isReadOnly() || K.isReadOnlyWithRel())
1724 Flags |=
1727 else if (K.isWriteable())
1728 Flags |=
1732
1733 return Flags;
1734}
1735
1737 const Comdat *C = GV->getComdat();
1738 assert(C && "expected GV to have a Comdat!");
1739
1740 StringRef ComdatGVName = C->getName();
1741 const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1742 if (!ComdatGV)
1743 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1744 "' does not exist.");
1745
1746 if (ComdatGV->getComdat() != C)
1747 report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1748 "' is not a key for its COMDAT.");
1749
1750 return ComdatGV;
1751}
1752
1753static int getSelectionForCOFF(const GlobalValue *GV) {
1754 if (const Comdat *C = GV->getComdat()) {
1755 const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
1756 if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1757 ComdatKey = GA->getAliaseeObject();
1758 if (ComdatKey == GV) {
1759 switch (C->getSelectionKind()) {
1760 case Comdat::Any:
1762 case Comdat::ExactMatch:
1764 case Comdat::Largest:
1768 case Comdat::SameSize:
1770 }
1771 } else {
1773 }
1774 }
1775 return 0;
1776}
1777
1779 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1781 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::COFF,
1782 /*AddSegmentInfo=*/false) ||
1783 Name == getInstrProfSectionName(IPSK_covfun, Triple::COFF,
1784 /*AddSegmentInfo=*/false) ||
1785 Name == getInstrProfSectionName(IPSK_covdata, Triple::COFF,
1786 /*AddSegmentInfo=*/false) ||
1787 Name == getInstrProfSectionName(IPSK_covname, Triple::COFF,
1788 /*AddSegmentInfo=*/false) ||
1789 Name == ".llvmbc" || Name == ".llvmcmd")
1790 Kind = SectionKind::getMetadata();
1791 int Selection = 0;
1792 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1793 StringRef COMDATSymName = "";
1794 if (GO->hasComdat()) {
1796 const GlobalValue *ComdatGV;
1798 ComdatGV = getComdatGVForCOFF(GO);
1799 else
1800 ComdatGV = GO;
1801
1802 if (!ComdatGV->hasPrivateLinkage()) {
1803 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1804 COMDATSymName = Sym->getName();
1805 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1806 } else {
1807 Selection = 0;
1808 }
1809 }
1810
1811 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1812 Selection);
1813}
1814
1816 if (Kind.isText())
1817 return ".text";
1818 if (Kind.isBSS())
1819 return ".bss";
1820 if (Kind.isThreadLocal())
1821 return ".tls$";
1822 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1823 return ".rdata";
1824 return ".data";
1825}
1826
1828 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1829 // If we have -ffunction-sections then we should emit the global value to a
1830 // uniqued section specifically for it.
1831 bool EmitUniquedSection;
1832 if (Kind.isText())
1833 EmitUniquedSection = TM.getFunctionSections();
1834 else
1835 EmitUniquedSection = TM.getDataSections();
1836
1837 if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1839
1840 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1841
1842 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1844 if (!Selection)
1846 const GlobalValue *ComdatGV;
1847 if (GO->hasComdat())
1848 ComdatGV = getComdatGVForCOFF(GO);
1849 else
1850 ComdatGV = GO;
1851
1853 if (EmitUniquedSection)
1854 UniqueID = NextUniqueID++;
1855
1856 if (!ComdatGV->hasPrivateLinkage()) {
1857 MCSymbol *Sym = TM.getSymbol(ComdatGV);
1858 StringRef COMDATSymName = Sym->getName();
1859
1860 if (const auto *F = dyn_cast<Function>(GO))
1861 if (std::optional<StringRef> Prefix = F->getSectionPrefix())
1862 raw_svector_ostream(Name) << '$' << *Prefix;
1863
1864 // Append "$symbol" to the section name *before* IR-level mangling is
1865 // applied when targetting mingw. This is what GCC does, and the ld.bfd
1866 // COFF linker will not properly handle comdats otherwise.
1867 if (getContext().getTargetTriple().isOSCygMing())
1868 raw_svector_ostream(Name) << '$' << ComdatGV->getName();
1869
1870 return getContext().getCOFFSection(Name, Characteristics, COMDATSymName,
1872 } else {
1873 SmallString<256> TmpData;
1874 getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
1875 return getContext().getCOFFSection(Name, Characteristics, TmpData,
1877 }
1878 }
1879
1880 if (Kind.isText())
1881 return TextSection;
1882
1883 if (Kind.isThreadLocal())
1884 return TLSDataSection;
1885
1886 if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1887 return ReadOnlySection;
1888
1889 // Note: we claim that common symbols are put in BSSSection, but they are
1890 // really emitted with the magic .comm directive, which creates a symbol table
1891 // entry but not a section.
1892 if (Kind.isBSS() || Kind.isCommon())
1893 return BSSSection;
1894
1895 return DataSection;
1896}
1897
1899 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1900 const TargetMachine &TM) const {
1901 bool CannotUsePrivateLabel = false;
1902 if (GV->hasPrivateLinkage() &&
1903 ((isa<Function>(GV) && TM.getFunctionSections()) ||
1904 (isa<GlobalVariable>(GV) && TM.getDataSections())))
1905 CannotUsePrivateLabel = true;
1906
1907 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1908}
1909
1911 const Function &F, const TargetMachine &TM) const {
1912 // If the function can be removed, produce a unique section so that
1913 // the table doesn't prevent the removal.
1914 const Comdat *C = F.getComdat();
1915 bool EmitUniqueSection = TM.getFunctionSections() || C;
1916 if (!EmitUniqueSection)
1917 return ReadOnlySection;
1918
1919 // FIXME: we should produce a symbol for F instead.
1920 if (F.hasPrivateLinkage())
1921 return ReadOnlySection;
1922
1923 MCSymbol *Sym = TM.getSymbol(&F);
1924 StringRef COMDATSymName = Sym->getName();
1925
1928 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
1929 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1930 unsigned UniqueID = NextUniqueID++;
1931
1932 return getContext().getCOFFSection(SecName, Characteristics, COMDATSymName,
1934 UniqueID);
1935}
1936
1938 bool UsesLabelDifference, const Function &F) const {
1939 if (TM->getTargetTriple().getArch() == Triple::x86_64) {
1941 // We can always create relative relocations, so use another section
1942 // that can be marked non-executable.
1943 return false;
1944 }
1945 }
1947 UsesLabelDifference, F);
1948}
1949
1951 Module &M) const {
1953
1954 unsigned Version = 0;
1955 unsigned Flags = 0;
1956 StringRef Section;
1957
1958 GetObjCImageInfo(M, Version, Flags, Section);
1959 if (!Section.empty()) {
1960 auto &C = getContext();
1961 auto *S = C.getCOFFSection(Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1963 Streamer.switchSection(S);
1964 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1965 Streamer.emitInt32(Version);
1966 Streamer.emitInt32(Flags);
1967 Streamer.addBlankLine();
1968 }
1969
1972 if (MCSymbol *Sym =
1973 static_cast<MCSectionCOFF *>(Streamer.getCurrentSectionOnly())
1974 ->getCOMDATSymbol())
1975 if (Sym->isUndefined()) {
1976 // COMDAT symbol must be external to perform deduplication.
1977 Streamer.emitSymbolAttribute(Sym, MCSA_Global);
1978 Streamer.emitLabel(Sym);
1979 }
1980 });
1981}
1982
1984 MCStreamer &Streamer, Module &M) const {
1985 if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1986 // Emit the linker options to the linker .drectve section. According to the
1987 // spec, this section is a space-separated string containing flags for
1988 // linker.
1990 Streamer.switchSection(Sec);
1991 for (const auto *Option : LinkerOptions->operands()) {
1992 for (const auto &Piece : cast<MDNode>(Option)->operands()) {
1993 // Lead with a space for consistency with our dllexport implementation.
1994 std::string Directive(" ");
1995 Directive.append(std::string(cast<MDString>(Piece)->getString()));
1996 Streamer.emitBytes(Directive);
1997 }
1998 }
1999 }
2000
2001 // Emit /EXPORT: flags for each exported global as necessary.
2002 std::string Flags;
2003 for (const GlobalValue &GV : M.global_values()) {
2004 raw_string_ostream OS(Flags);
2005 emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
2006 getMangler());
2007 if (!Flags.empty()) {
2008 Streamer.switchSection(getDrectveSection());
2009 Streamer.emitBytes(Flags);
2010 }
2011 Flags.clear();
2012 }
2013
2014 // Emit /INCLUDE: flags for each used global as necessary.
2015 if (const auto *LU = M.getNamedGlobal("llvm.used")) {
2016 assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
2017 assert(isa<ArrayType>(LU->getValueType()) &&
2018 "expected llvm.used to be an array type");
2019 if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
2020 for (const Value *Op : A->operands()) {
2021 const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
2022 // Global symbols with internal or private linkage are not visible to
2023 // the linker, and thus would cause an error when the linker tried to
2024 // preserve the symbol due to the `/include:` directive.
2025 if (GV->hasLocalLinkage())
2026 continue;
2027
2028 raw_string_ostream OS(Flags);
2029 emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
2030 getMangler());
2031
2032 if (!Flags.empty()) {
2033 Streamer.switchSection(getDrectveSection());
2034 Streamer.emitBytes(Flags);
2035 }
2036 Flags.clear();
2037 }
2038 }
2039 }
2040}
2041
2043 const TargetMachine &TM) {
2045 this->TM = &TM;
2046 const Triple &T = TM.getTargetTriple();
2047 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2049 Ctx.getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2052 Ctx.getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2054 } else {
2055 StaticCtorSection = Ctx.getCOFFSection(
2058 StaticDtorSection = Ctx.getCOFFSection(
2061 }
2062}
2063
2065 const Triple &T, bool IsCtor,
2066 unsigned Priority,
2067 const MCSymbol *KeySym,
2069 if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
2070 // If the priority is the default, use .CRT$XCU, possibly associative.
2071 if (Priority == 65535)
2072 return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
2073
2074 // Otherwise, we need to compute a new section name. Low priorities should
2075 // run earlier. The linker will sort sections ASCII-betically, and we need a
2076 // string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
2077 // make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
2078 // low priorities need to sort before 'L', since the CRT uses that
2079 // internally, so we use ".CRT$XCA00001" for them. We have a contract with
2080 // the frontend that "init_seg(compiler)" corresponds to priority 200 and
2081 // "init_seg(lib)" corresponds to priority 400, and those respectively use
2082 // 'C' and 'L' without the priority suffix. Priorities between 200 and 400
2083 // use 'C' with the priority as a suffix.
2084 SmallString<24> Name;
2085 char LastLetter = 'T';
2086 bool AddPrioritySuffix = Priority != 200 && Priority != 400;
2087 if (Priority < 200)
2088 LastLetter = 'A';
2089 else if (Priority < 400)
2090 LastLetter = 'C';
2091 else if (Priority == 400)
2092 LastLetter = 'L';
2093 raw_svector_ostream OS(Name);
2094 OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;
2095 if (AddPrioritySuffix)
2096 OS << format("%05u", Priority);
2097 MCSectionCOFF *Sec = Ctx.getCOFFSection(
2099 return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
2100 }
2101
2102 std::string Name = IsCtor ? ".ctors" : ".dtors";
2103 if (Priority != 65535)
2104 raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
2105
2106 return Ctx.getAssociativeCOFFSection(
2107 Ctx.getCOFFSection(Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2110 KeySym, 0);
2111}
2112
2114 unsigned Priority, const MCSymbol *KeySym) const {
2116 getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
2117 static_cast<MCSectionCOFF *>(StaticCtorSection));
2118}
2119
2121 unsigned Priority, const MCSymbol *KeySym) const {
2123 getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
2124 static_cast<MCSectionCOFF *>(StaticDtorSection));
2125}
2126
2128 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
2129 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
2130 const Triple &T = TM.getTargetTriple();
2131 if (T.isOSCygMing())
2132 return nullptr;
2133
2134 // Our symbols should exist in address space zero, cowardly no-op if
2135 // otherwise.
2136 if (LHS->getType()->getPointerAddressSpace() != 0 ||
2137 RHS->getType()->getPointerAddressSpace() != 0)
2138 return nullptr;
2139
2140 const auto *GA = dyn_cast<GlobalAlias>(LHS);
2141 const GlobalObject *GO = GA ? dyn_cast_or_null<GlobalObject>(GA->getAliasee())
2143
2144 // Both ptrtoint instructions must wrap global objects:
2145 // - Only global variables that are dso_local are eligible for image relative
2146 // relocations.
2147 // - FIXME: Referring to a dllimport function produces an image-relative
2148 // relocation against the local import thunk rather than the canonical
2149 // function pointer, which lacks program-wide pointer identity. This is
2150 // sufficient for use cases like MSVC exception handling metadata (where the
2151 // function is only invoked), but is not theoretically sound in general.
2152 // We probably need something like dso_local_equivalent to explicitly
2153 // request a callable local entry point.
2154 // - The subtrahend refers to the special symbol __ImageBase, a
2155 // GlobalVariable. We expect __ImageBase to be a global variable without a
2156 // section, externally defined.
2157 //
2158 // It should look something like this: @__ImageBase = external constant i8
2159 if (!GO || (isa<GlobalVariable>(GO) && !TM.shouldAssumeDSOLocal(LHS)) ||
2160 GO->isThreadLocal() || !isa<GlobalVariable>(RHS) ||
2161 RHS->isThreadLocal() || RHS->getName() != "__ImageBase" ||
2162 !RHS->hasExternalLinkage() ||
2163 cast<GlobalVariable>(RHS)->hasInitializer() || RHS->hasSection())
2164 return nullptr;
2165
2166 const MCExpr *Res = MCSymbolRefExpr::create(
2167 TM.getSymbol(LHS), MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
2168 if (Addend != 0)
2170 Res, MCConstantExpr::create(Addend, getContext()), getContext());
2171 return Res;
2172}
2173
2174static std::string APIntToHexString(const APInt &AI) {
2175 unsigned Width = (AI.getBitWidth() / 8) * 2;
2176 std::string HexString = toString(AI, 16, /*Signed=*/false);
2177 llvm::transform(HexString, HexString.begin(), tolower);
2178 unsigned Size = HexString.size();
2179 assert(Width >= Size && "hex string is too large!");
2180 HexString.insert(HexString.begin(), Width - Size, '0');
2181
2182 return HexString;
2183}
2184
2185static std::string scalarConstantToHexString(const Constant *C) {
2186 Type *Ty = C->getType();
2187 if (isa<UndefValue>(C)) {
2188 return APIntToHexString(APInt::getZero(Ty->getPrimitiveSizeInBits()));
2189 } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
2190 if (CFP->getType()->isFloatingPointTy())
2191 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2192
2193 std::string HexString;
2194 unsigned NumElements =
2195 cast<FixedVectorType>(CFP->getType())->getNumElements();
2196 for (unsigned I = 0; I < NumElements; ++I)
2197 HexString += APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2198 return HexString;
2199 } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
2200 if (CI->getType()->isIntegerTy())
2201 return APIntToHexString(CI->getValue());
2202
2203 std::string HexString;
2204 unsigned NumElements =
2205 cast<FixedVectorType>(CI->getType())->getNumElements();
2206 for (unsigned I = 0; I < NumElements; ++I)
2207 HexString += APIntToHexString(CI->getValue());
2208 return HexString;
2209 } else {
2210 unsigned NumElements;
2211 if (auto *VTy = dyn_cast<VectorType>(Ty))
2212 NumElements = cast<FixedVectorType>(VTy)->getNumElements();
2213 else
2214 NumElements = Ty->getArrayNumElements();
2215 std::string HexString;
2216 for (int I = NumElements - 1, E = -1; I != E; --I)
2217 HexString += scalarConstantToHexString(C->getAggregateElement(I));
2218 return HexString;
2219 }
2220}
2221
2223 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2224 const Function *F) const {
2225 if (Kind.isMergeableConst() && C &&
2226 getContext().getAsmInfo().hasCOFFComdatConstants()) {
2227 // This creates comdat sections with the given symbol name, but unless
2228 // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
2229 // will be created with a null storage class, which makes GNU binutils
2230 // error out.
2231 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2234 std::string COMDATSymName;
2235 if (Kind.isMergeableConst4()) {
2236 if (Alignment <= 4) {
2237 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2238 Alignment = Align(4);
2239 }
2240 } else if (Kind.isMergeableConst8()) {
2241 if (Alignment <= 8) {
2242 COMDATSymName = "__real@" + scalarConstantToHexString(C);
2243 Alignment = Align(8);
2244 }
2245 } else if (Kind.isMergeableConst16()) {
2246 // FIXME: These may not be appropriate for non-x86 architectures.
2247 if (Alignment <= 16) {
2248 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
2249 Alignment = Align(16);
2250 }
2251 } else if (Kind.isMergeableConst32()) {
2252 if (Alignment <= 32) {
2253 COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
2254 Alignment = Align(32);
2255 }
2256 }
2257
2258 if (!COMDATSymName.empty())
2259 return getContext().getCOFFSection(".rdata", Characteristics,
2260 COMDATSymName,
2262 }
2263
2264 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, Alignment,
2265 F);
2266}
2267
2268//===----------------------------------------------------------------------===//
2269// Wasm
2270//===----------------------------------------------------------------------===//
2271
2272static const Comdat *getWasmComdat(const GlobalValue *GV) {
2273 const Comdat *C = GV->getComdat();
2274 if (!C)
2275 return nullptr;
2276
2277 if (C->getSelectionKind() != Comdat::Any)
2278 report_fatal_error("WebAssembly COMDATs only support "
2279 "SelectionKind::Any, '" + C->getName() + "' cannot be "
2280 "lowered.");
2281
2282 return C;
2283}
2284
2285static unsigned getWasmSectionFlags(SectionKind K, bool Retain) {
2286 unsigned Flags = 0;
2287
2288 if (K.isThreadLocal())
2289 Flags |= wasm::WASM_SEG_FLAG_TLS;
2290
2291 if (K.isMergeableCString())
2293
2294 if (Retain)
2296
2297 // TODO(sbc): Add suport for K.isMergeableConst()
2298
2299 return Flags;
2300}
2301
2304 collectUsedGlobalVariables(M, Vec, false);
2305 for (GlobalValue *GV : Vec)
2306 if (auto *GO = dyn_cast<GlobalObject>(GV))
2307 Used.insert(GO);
2308}
2309
2311 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2312 // We don't support explict section names for functions in the wasm object
2313 // format. Each function has to be in its own unique section.
2314 if (isa<Function>(GO)) {
2315 return SelectSectionForGlobal(GO, Kind, TM);
2316 }
2317
2318 StringRef Name = GO->getSection();
2319
2320 // Certain data sections we treat as named custom sections rather than
2321 // segments within the data section.
2322 // This could be avoided if all data segements (the wasm sense) were
2323 // represented as their own sections (in the llvm sense).
2324 // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2325 if (Name == getInstrProfSectionName(IPSK_covmap, Triple::Wasm,
2326 /*AddSegmentInfo=*/false) ||
2327 Name == getInstrProfSectionName(IPSK_covfun, Triple::Wasm,
2328 /*AddSegmentInfo=*/false) ||
2329 Name == ".llvmbc" || Name == ".llvmcmd")
2330 Kind = SectionKind::getMetadata();
2331
2332 StringRef Group = "";
2333 if (const Comdat *C = getWasmComdat(GO)) {
2334 Group = C->getName();
2335 }
2336
2337 unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
2338 MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
2340
2341 return Section;
2342}
2343
2344static MCSectionWasm *
2346 SectionKind Kind, Mangler &Mang,
2347 const TargetMachine &TM, bool EmitUniqueSection,
2348 unsigned *NextUniqueID, bool Retain) {
2349 StringRef Group = "";
2350 if (const Comdat *C = getWasmComdat(GO)) {
2351 Group = C->getName();
2352 }
2353
2354 bool UniqueSectionNames = TM.getUniqueSectionNames();
2355 SmallString<128> Name = getSectionPrefixForGlobal(Kind, /*IsLarge=*/false);
2356
2357 if (const auto *F = dyn_cast<Function>(GO)) {
2358 const auto &OptionalPrefix = F->getSectionPrefix();
2359 if (OptionalPrefix)
2360 raw_svector_ostream(Name) << '.' << *OptionalPrefix;
2361 }
2362
2363 if (EmitUniqueSection && UniqueSectionNames) {
2364 Name.push_back('.');
2365 TM.getNameWithPrefix(Name, GO, Mang, true);
2366 }
2368 if (EmitUniqueSection && !UniqueSectionNames) {
2369 UniqueID = *NextUniqueID;
2370 (*NextUniqueID)++;
2371 }
2372
2373 unsigned Flags = getWasmSectionFlags(Kind, Retain);
2374 return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2375}
2376
2378 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2379
2380 if (Kind.isCommon())
2381 report_fatal_error("mergable sections not supported yet on wasm");
2382
2383 // If we have -ffunction-section or -fdata-section then we should emit the
2384 // global value to a uniqued section specifically for it.
2385 bool EmitUniqueSection = false;
2386 if (Kind.isText())
2387 EmitUniqueSection = TM.getFunctionSections();
2388 else
2389 EmitUniqueSection = TM.getDataSections();
2390 EmitUniqueSection |= GO->hasComdat();
2391 bool Retain = Used.count(GO);
2392 EmitUniqueSection |= Retain;
2393
2394 return selectWasmSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
2395 EmitUniqueSection, &NextUniqueID, Retain);
2396}
2397
2399 bool UsesLabelDifference, const Function &F) const {
2400 // We can always create relative relocations, so use another section
2401 // that can be marked non-executable.
2402 return false;
2403}
2404
2408
2409 // We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2410 // .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2412}
2413
2415 unsigned Priority, const MCSymbol *KeySym) const {
2416 return Priority == UINT16_MAX ?
2418 getContext().getWasmSection(".init_array." + utostr(Priority),
2420}
2421
2423 unsigned Priority, const MCSymbol *KeySym) const {
2424 report_fatal_error("@llvm.global_dtors should have been lowered already");
2425}
2426
2427//===----------------------------------------------------------------------===//
2428// XCOFF
2429//===----------------------------------------------------------------------===//
2431 const MachineFunction *MF) {
2432 if (!MF->getLandingPads().empty())
2433 return true;
2434
2435 const Function &F = MF->getFunction();
2436 if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2437 return false;
2438
2439 const GlobalValue *Per =
2440 dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2441 assert(Per && "Personality routine is not a GlobalValue type.");
2443 return false;
2444
2445 return true;
2446}
2447
2449 const MachineFunction *MF) {
2450 const Function &F = MF->getFunction();
2451 if (!F.hasStackProtectorFnAttr())
2452 return false;
2453 // FIXME: check presence of canary word
2454 // There are cases that the stack protectors are not really inserted even if
2455 // the attributes are on.
2456 return true;
2457}
2458
2459MCSymbol *
2461 auto *EHInfoSym =
2462 static_cast<MCSymbolXCOFF *>(MF->getContext().getOrCreateSymbol(
2463 "__ehinfo." + Twine(MF->getFunctionNumber())));
2464 EHInfoSym->setEHInfo();
2465 return EHInfoSym;
2466}
2467
2468MCSymbol *
2470 const TargetMachine &TM) const {
2471 // We always use a qualname symbol for a GV that represents
2472 // a declaration, a function descriptor, or a common symbol. An IFunc is
2473 // lowered as a special trampoline function which has an entry point and a
2474 // descriptor.
2475 // If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2476 // also return a qualname so that a label symbol could be avoided.
2477 // It is inherently ambiguous when the GO represents the address of a
2478 // function, as the GO could either represent a function descriptor or a
2479 // function entry point. We choose to always return a function descriptor
2480 // here.
2481 if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2482 if (GO->isDeclarationForLinker())
2483 return static_cast<const MCSectionXCOFF *>(
2485 ->getQualNameSymbol();
2486
2487 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2488 if (GVar->hasAttribute("toc-data"))
2489 return static_cast<const MCSectionXCOFF *>(
2491 ->getQualNameSymbol();
2492
2493 if (isa<GlobalIFunc>(GO))
2494 return static_cast<const MCSectionXCOFF *>(
2496 ->getQualNameSymbol();
2497
2498 SectionKind GOKind = getKindForGlobal(GO, TM);
2499 if (GOKind.isText())
2500 return static_cast<const MCSectionXCOFF *>(
2502 ->getQualNameSymbol();
2503 if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2504 GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2505 return static_cast<const MCSectionXCOFF *>(
2506 SectionForGlobal(GO, GOKind, TM))
2507 ->getQualNameSymbol();
2508 }
2509
2510 // For all other cases, fall back to getSymbol to return the unqualified name.
2511 return nullptr;
2512}
2513
2515 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2516 if (!GO->hasSection())
2517 report_fatal_error("#pragma clang section is not yet supported");
2518
2520
2521 // Handle the XCOFF::TD case first, then deal with the rest.
2522 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2523 if (GVar->hasAttribute("toc-data"))
2524 return getContext().getXCOFFSection(
2525 SectionName, Kind,
2527 /* MultiSymbolsAllowed*/ true);
2528
2529 XCOFF::StorageMappingClass MappingClass;
2530 if (Kind.isText())
2531 MappingClass = XCOFF::XMC_PR;
2532 else if (Kind.isData() || Kind.isBSS())
2533 MappingClass = XCOFF::XMC_RW;
2534 else if (Kind.isReadOnlyWithRel())
2535 MappingClass =
2536 TM.Options.XCOFFReadOnlyPointers ? XCOFF::XMC_RO : XCOFF::XMC_RW;
2537 else if (Kind.isReadOnly())
2538 MappingClass = XCOFF::XMC_RO;
2539 else
2540 report_fatal_error("XCOFF other section types not yet implemented.");
2541
2542 return getContext().getXCOFFSection(
2543 SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
2544 /* MultiSymbolsAllowed*/ true);
2545}
2546
2548 const GlobalObject *GO, const TargetMachine &TM) const {
2550 "Tried to get ER section for a defined global.");
2551
2552 SmallString<128> Name;
2553 getNameWithPrefix(Name, GO, TM);
2554
2555 // AIX TLS local-dynamic does not need the external reference for the
2556 // "_$TLSML" symbol.
2558 GO->hasName() && GO->getName() == "_$TLSML") {
2559 return getContext().getXCOFFSection(
2560 Name, SectionKind::getData(),
2562 }
2563
2566 if (GO->isThreadLocal())
2567 SMC = XCOFF::XMC_UL;
2568
2569 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2570 if (GVar->hasAttribute("toc-data"))
2571 SMC = XCOFF::XMC_TD;
2572
2573 // Externals go into a csect of type ER.
2574 return getContext().getXCOFFSection(
2577}
2578
2580 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2581 // Handle the XCOFF::TD case first, then deal with the rest.
2582 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2583 if (GVar->hasAttribute("toc-data")) {
2584 SmallString<128> Name;
2585 getNameWithPrefix(Name, GO, TM);
2586 XCOFF::SymbolType symType =
2588 return getContext().getXCOFFSection(
2589 Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_TD, symType),
2590 /* MultiSymbolsAllowed*/ true);
2591 }
2592
2593 // Common symbols go into a csect with matching name which will get mapped
2594 // into the .bss section.
2595 // Zero-initialized local TLS symbols go into a csect with matching name which
2596 // will get mapped into the .tbss section.
2597 if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2598 SmallString<128> Name;
2599 getNameWithPrefix(Name, GO, TM);
2600 XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ? XCOFF::XMC_BS
2601 : Kind.isCommon() ? XCOFF::XMC_RW
2602 : XCOFF::XMC_UL;
2603 return getContext().getXCOFFSection(
2604 Name, Kind, XCOFF::CsectProperties(SMC, XCOFF::XTY_CM));
2605 }
2606
2607 if (Kind.isText()) {
2608 if (TM.getFunctionSections()) {
2609 return static_cast<const MCSymbolXCOFF *>(
2611 ->getRepresentedCsect();
2612 }
2613 return TextSection;
2614 }
2615
2616 if (TM.Options.XCOFFReadOnlyPointers && Kind.isReadOnlyWithRel()) {
2617 if (!TM.getDataSections())
2619 "ReadOnlyPointers is supported only if data sections is turned on");
2620
2621 SmallString<128> Name;
2622 getNameWithPrefix(Name, GO, TM);
2623 return getContext().getXCOFFSection(
2626 }
2627
2628 // For BSS kind, zero initialized data must be emitted to the .data section
2629 // because external linkage control sections that get mapped to the .bss
2630 // section will be linked as tentative definitions, which is only appropriate
2631 // for SectionKind::Common.
2632 if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2633 if (TM.getDataSections()) {
2634 SmallString<128> Name;
2635 getNameWithPrefix(Name, GO, TM);
2636 return getContext().getXCOFFSection(
2637 Name, SectionKind::getData(),
2639 }
2640 return DataSection;
2641 }
2642
2643 if (Kind.isReadOnly()) {
2644 if (TM.getDataSections()) {
2645 SmallString<128> Name;
2646 getNameWithPrefix(Name, GO, TM);
2647 return getContext().getXCOFFSection(
2650 }
2651 return ReadOnlySection;
2652 }
2653
2654 // External/weak TLS data and initialized local TLS data are not eligible
2655 // to be put into common csect. If data sections are enabled, thread
2656 // data are emitted into separate sections. Otherwise, thread data
2657 // are emitted into the .tdata section.
2658 if (Kind.isThreadLocal()) {
2659 if (TM.getDataSections()) {
2660 SmallString<128> Name;
2661 getNameWithPrefix(Name, GO, TM);
2662 return getContext().getXCOFFSection(
2664 }
2665 return TLSDataSection;
2666 }
2667
2668 report_fatal_error("XCOFF other section types not yet implemented.");
2669}
2670
2672 const Function &F, const TargetMachine &TM) const {
2673 assert (!F.getComdat() && "Comdat not supported on XCOFF.");
2674
2675 if (!TM.getFunctionSections())
2676 return ReadOnlySection;
2677
2678 // If the function can be removed, produce a unique section so that
2679 // the table doesn't prevent the removal.
2680 SmallString<128> NameStr(".rodata.jmp..");
2681 getNameWithPrefix(NameStr, &F, TM);
2682 return getContext().getXCOFFSection(
2683 NameStr, SectionKind::getReadOnly(),
2685}
2686
2688 bool UsesLabelDifference, const Function &F) const {
2689 return false;
2690}
2691
2692/// Given a mergeable constant with the specified size and relocation
2693/// information, return a section that it should be placed in.
2695 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2696 const Function *F) const {
2697 // TODO: Enable emiting constant pool to unique sections when we support it.
2698 if (Alignment > Align(16))
2699 report_fatal_error("Alignments greater than 16 not yet supported.");
2700
2701 if (Alignment == Align(8)) {
2702 assert(ReadOnly8Section && "Section should always be initialized.");
2703 return ReadOnly8Section;
2704 }
2705
2706 if (Alignment == Align(16)) {
2707 assert(ReadOnly16Section && "Section should always be initialized.");
2708 return ReadOnly16Section;
2709 }
2710
2711 return ReadOnlySection;
2712}
2713
2715 const TargetMachine &TgtM) {
2719 (TgtM.getTargetTriple().isArch32Bit() ? dwarf::DW_EH_PE_sdata4
2722 LSDAEncoding = 0;
2724
2725 // AIX debug for thread local location is not ready. And for integrated as
2726 // mode, the relocatable address for the thread local variable will cause
2727 // linker error. So disable the location attribute generation for thread local
2728 // variables for now.
2729 // FIXME: when TLS debug on AIX is ready, remove this setting.
2731}
2732
2734 unsigned Priority, const MCSymbol *KeySym) const {
2735 report_fatal_error("no static constructor section on AIX");
2736}
2737
2739 unsigned Priority, const MCSymbol *KeySym) const {
2740 report_fatal_error("no static destructor section on AIX");
2741}
2742
2745 assert(!isa<GlobalIFunc>(GV) && "GlobalIFunc is not supported on AIX.");
2746
2747 switch (GV->getLinkage()) {
2750 return XCOFF::C_HIDEXT;
2754 return XCOFF::C_EXT;
2760 return XCOFF::C_WEAKEXT;
2763 "There is no mapping that implements AppendingLinkage for XCOFF.");
2764 }
2765 llvm_unreachable("Unknown linkage type!");
2766}
2767
2769 const GlobalValue *Func, const TargetMachine &TM) const {
2770 assert((isa<Function>(Func) || isa<GlobalIFunc>(Func) ||
2771 (isa<GlobalAlias>(Func) &&
2773 cast<GlobalAlias>(Func)->getAliaseeObject()))) &&
2774 "Func must be a function or an alias which has a function as base "
2775 "object.");
2776
2777 SmallString<128> NameStr;
2778 NameStr.push_back('.');
2779 getNameWithPrefix(NameStr, Func, TM);
2780
2781 // When -function-sections is enabled and explicit section is not specified,
2782 // it's not necessary to emit function entry point label any more. We will use
2783 // function entry point csect instead. And for function delcarations, the
2784 // undefined symbols gets treated as csect with XTY_ER property.
2785 if (((TM.getFunctionSections() && !Func->hasSection()) ||
2786 Func->isDeclarationForLinker()) &&
2787 (isa<Function>(Func) || isa<GlobalIFunc>(Func))) {
2788 return getContext()
2790 NameStr, SectionKind::getText(),
2791 XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclarationForLinker()
2793 : XCOFF::XTY_SD))
2795 }
2796
2797 return getContext().getOrCreateSymbol(NameStr);
2798}
2799
2801 const GlobalObject *F, const TargetMachine &TM) const {
2803 "F must be a function or ifunc object.");
2804 SmallString<128> NameStr;
2805 getNameWithPrefix(NameStr, F, TM);
2806 return getContext().getXCOFFSection(
2807 NameStr, SectionKind::getData(),
2809}
2810
2812 const MCSymbol *Sym, const TargetMachine &TM) const {
2813 const XCOFF::StorageMappingClass SMC = [](const MCSymbol *Sym,
2814 const TargetMachine &TM) {
2815 auto *XSym = static_cast<const MCSymbolXCOFF *>(Sym);
2816
2817 // The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC,
2818 // otherwise the AIX assembler will complain.
2819 if (XSym->getSymbolTableName() == "_$TLSML")
2820 return XCOFF::XMC_TC;
2821
2822 // Use large code model toc entries for ehinfo symbols as they are
2823 // never referenced directly. The runtime loads their TOC entry
2824 // addresses from the trace-back table.
2825 if (XSym->isEHInfo())
2826 return XCOFF::XMC_TE;
2827
2828 // If the symbol does not have a code model specified use the module value.
2829 if (!XSym->hasPerSymbolCodeModel())
2830 return TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE
2831 : XCOFF::XMC_TC;
2832
2833 return XSym->getPerSymbolCodeModel() == MCSymbolXCOFF::CM_Large
2835 : XCOFF::XMC_TC;
2836 }(Sym, TM);
2837
2838 return getContext().getXCOFFSection(
2839 static_cast<const MCSymbolXCOFF *>(Sym)->getSymbolTableName(),
2841}
2842
2844 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2845 auto *LSDA = static_cast<MCSectionXCOFF *>(LSDASection);
2846 if (TM.getFunctionSections()) {
2847 // If option -ffunction-sections is on, append the function name to the
2848 // name of the LSDA csect so that each function has its own LSDA csect.
2849 // This helps the linker to garbage-collect EH info of unused functions.
2850 SmallString<128> NameStr = LSDA->getName();
2851 raw_svector_ostream(NameStr) << '.' << F.getName();
2852 LSDA = getContext().getXCOFFSection(NameStr, LSDA->getKind(),
2853 LSDA->getCsectProp());
2854 }
2855 return LSDA;
2856}
2857//===----------------------------------------------------------------------===//
2858// GOFF
2859//===----------------------------------------------------------------------===//
2861
2863 // Construct the default names for the root SD and the ADA PR symbol.
2864 StringRef FileName = sys::path::stem(M.getSourceFileName());
2865 if (FileName.size() > 1 && FileName.starts_with('<') &&
2866 FileName.ends_with('>'))
2867 FileName = FileName.substr(1, FileName.size() - 2);
2868 DefaultRootSDName = Twine(FileName).concat("#C").str();
2869 DefaultADAPRName = Twine(FileName).concat("#S").str();
2870 MCSectionGOFF *RootSD =
2871 static_cast<MCSectionGOFF *>(TextSection)->getParent();
2872 MCSectionGOFF *ADAPR = static_cast<MCSectionGOFF *>(ADASection);
2873 RootSD->setName(DefaultRootSDName);
2874 ADAPR->setName(DefaultADAPRName);
2875 // Initialize the label for the text section.
2876 MCSymbolGOFF *TextLD = static_cast<MCSymbolGOFF *>(
2877 getContext().getOrCreateSymbol(RootSD->getName()));
2880 TextLD->setExternal(false);
2881 TextLD->setWeak(false);
2882 TextLD->setADA(ADAPR);
2883 TextSection->setBeginSymbol(TextLD);
2884 // Initialize the label for the ADA section.
2885 MCSymbolGOFF *ADASym = static_cast<MCSymbolGOFF *>(
2887 ADAPR->setBeginSymbol(ADASym);
2888}
2889
2891 bool UsesLabelDifference, const Function &F) const {
2892 return true;
2893}
2894
2896 const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
2897 const Function *F) const {
2898 return TextSection;
2899}
2900
2905
2907 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
2908 std::string Name = ".gcc_exception_table." + F.getName().str();
2909
2910 MCSectionGOFF *WSA = getContext().getGOFFSection(
2915 static_cast<MCSectionGOFF *>(TextSection)->getParent());
2916 WSA->setAlignment(Align(4)); // Fullword
2917 return getContext().getGOFFSection(SectionKind::getData(), Name,
2921 WSA);
2922}
2923
2925 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2926 auto *Symbol = TM.getSymbol(GO);
2927
2928 if (Kind.isBSS() || Kind.isData() || Kind.isReadOnlyWithRel()) {
2929 GOFF::ESDBindingScope PRBindingScope =
2930 GO->hasExternalLinkage()
2934 GOFF::ESDBindingScope SDBindingScope =
2937 MaybeAlign Alignment;
2938 if (auto *F = dyn_cast<Function>(GO))
2939 Alignment = F->getAlign();
2940 else if (auto *V = dyn_cast<GlobalVariable>(GO))
2941 Alignment = V->getAlign();
2942 MCSectionGOFF *SD = getContext().getGOFFSection(
2943 SectionKind::getMetadata(), Symbol->getName(),
2944 GOFF::SDAttr{GOFF::ESD_TA_Unspecified, SDBindingScope});
2945 MCSectionGOFF *ED = getContext().getGOFFSection(
2950 SD);
2951 ED->setAlignment(Alignment.value_or(llvm::Align(8)));
2952 MCSectionGOFF *PR = getContext().getGOFFSection(
2953 Kind, Symbol->getName(),
2954 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA, GOFF::ESD_LT_XPLink,
2955 PRBindingScope, 0},
2956 ED);
2957 // The binder rejects zero-length PR sections. Mark the PR so the writer
2958 // inflates it to a valid length if needed.
2960 return PR;
2961 }
2962 return TextSection;
2963}
2964
2965MCSection *
2967 // XL C/C++ compilers on z/OS support priorities from min-int to max-int, with
2968 // sinit as source priority 0. For clang, sinit has source priority 65535.
2969 // For GOFF, the priority sortkey field is an unsigned value. So, we
2970 // add min-int to get sorting to work properly but also subtract the
2971 // clang sinit (65535) value so internally xl sinit and clang sinit have
2972 // the same unsigned GOFF priority sortkey field value (i.e. 0x80000000).
2973 static constexpr const uint32_t ClangDefaultSinitPriority = 65535;
2974 uint32_t Prio = Priority + (0x80000000 - ClangDefaultSinitPriority);
2975
2976 std::string Name(".xtor");
2977 if (Priority != ClangDefaultSinitPriority)
2978 Name = llvm::Twine(Name).concat(".").concat(llvm::utostr(Priority)).str();
2979
2980 MCContext &Ctx = getContext();
2981 MCSectionGOFF *SInit = Ctx.getGOFFSection(
2987 static_cast<const MCSectionGOFF *>(TextSection)->getParent());
2988
2989 MCSectionGOFF *Xtor = Ctx.getGOFFSection(
2990 SectionKind::getData(), Name,
2992 GOFF::ESD_BSC_Section, Prio},
2993 SInit);
2994 return Xtor;
2995}
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_LIFETIME_BOUND
Definition Compiler.h:452
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.
cl::opt< bool > PreserveHotDataSectionPrefix("preserve-hot-data-section-prefix", cl::Hidden, cl::init(true), cl::desc("If true, hot data section prefixes are preserved"))
This file contains some functions that are useful when dealing with strings.
std::unique_ptr< MCStreamer > && Streamer
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
static MCSection * selectExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID, bool Retain, bool ForceUnique)
static int getSelectionForCOFF(const GlobalValue *GV)
static MCSectionCOFF * getCOFFStaticStructorSection(MCContext &Ctx, const Triple &T, bool IsCtor, unsigned Priority, const MCSymbol *KeySym, MCSectionCOFF *Default)
static unsigned getEntrySizeForKind(SectionKind Kind)
static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags, StringRef &Section)
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
static unsigned getELFSectionType(StringRef Name, SectionKind K)
static bool hasPrefix(StringRef SectionName, StringRef Prefix)
static MCSectionWasm * selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID, bool Retain)
static const MCSymbolELF * getLinkedToSymbol(const GlobalObject *GO, const TargetMachine &TM)
static unsigned calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &Flags, unsigned &EntrySize, unsigned &NextUniqueID, const bool Retain, const bool ForceUnique)
Calculate an appropriate unique ID for a section, and update Flags, EntrySize and NextUniqueID where ...
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
static const Comdat * getWasmComdat(const GlobalValue *GV)
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
static 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:1508
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
@ 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
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:67
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 * 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 * 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:580
void setAlignment(Align Value)
Definition MCSection.h:665
static constexpr unsigned NonUniqueID
Definition MCSection.h:585
void setBeginSymbol(MCSymbol *Sym)
Definition MCSection.h:657
StringRef getName() const
Definition MCSection.h:650
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
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:1081
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
Metadata * get() const
Definition Metadata.h:931
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
This class contains meta information specific to a module.
const Module * getModule() const
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition Mangler.cpp:121
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition Module.h:134
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition Module.h:310
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:325
A tuple of MDNodes.
Definition Metadata.h:1767
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
bool starts_with(StringRef Prefix) const
starts_with - Check if this string starts with the given Prefix.
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
MCSection * getSectionForConstantImpl(const DataLayout &DL, SectionKind Kind, const Constant *C, StringRef SectionSuffix) const
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
bool isLargeConstant(const DataLayout &DL, SectionKind Kind, const Constant *C) const
Given a mergeable constant with the specified size and relocation information, return a section that ...
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 * 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 * 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.
static StringRef getCustomSectionName(const GlobalObject *GO, const TargetMachine &TM)
Return the section name specified by 'pragma clang section' or the section attribute.
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:48
@ loongarch32
Definition Triple.h:65
@ loongarch64
Definition Triple.h:66
bool isOSSolaris() const
Definition Triple.h:754
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:514
bool isOSFreeBSD() const
Definition Triple.h:748
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:260
bool hasName() const
Definition Value.h:263
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
@ SHF_MERGE
Definition ELF.h:1265
@ SHF_STRINGS
Definition ELF.h:1268
@ SHF_AARCH64_PURECODE
Definition ELF.h:1357
@ SHF_EXCLUDE
Definition ELF.h:1293
@ SHF_ALLOC
Definition ELF.h:1259
@ SHF_LINK_ORDER
Definition ELF.h:1274
@ SHF_GROUP
Definition ELF.h:1281
@ SHF_SUNW_NODISCARD
Definition ELF.h:1300
@ SHF_X86_64_LARGE
Definition ELF.h:1322
@ SHF_GNU_RETAIN
Definition ELF.h:1290
@ SHF_WRITE
Definition ELF.h:1256
@ SHF_TLS
Definition ELF.h:1284
@ SHF_ARM_PURECODE
Definition ELF.h:1354
@ SHF_EXECINSTR
Definition ELF.h:1262
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition ELF.h:1188
@ SHT_PROGBITS
Definition ELF.h:1157
@ SHT_LLVM_LINKER_OPTIONS
Definition ELF.h:1185
@ SHT_NOBITS
Definition ELF.h:1164
@ SHT_LLVM_OFFLOADING
Definition ELF.h:1196
@ SHT_LLVM_LTO
Definition ELF.h:1197
@ SHT_PREINIT_ARRAY
Definition ELF.h:1170
@ SHT_INIT_ARRAY
Definition ELF.h:1168
@ SHT_NOTE
Definition ELF.h:1163
@ SHT_FINI_ARRAY
Definition ELF.h:1169
@ 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:972
@ DW_EH_PE_pcrel
Definition Dwarf.h:970
@ DW_EH_PE_sdata4
Definition Dwarf.h:967
@ DW_EH_PE_sdata8
Definition Dwarf.h:968
@ DW_EH_PE_absptr
Definition Dwarf.h:959
@ DW_EH_PE_udata4
Definition Dwarf.h:963
@ DW_EH_PE_udata8
Definition Dwarf.h:964
@ DW_EH_PE_indirect
Definition Dwarf.h:975
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition Metadata.h:707
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
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:577
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...
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
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:2042
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:102
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:951
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
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