LLVM  14.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 
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/BinaryFormat/COFF.h"
22 #include "llvm/BinaryFormat/ELF.h"
24 #include "llvm/BinaryFormat/Wasm.h"
30 #include "llvm/IR/Comdat.h"
31 #include "llvm/IR/Constants.h"
32 #include "llvm/IR/DataLayout.h"
33 #include "llvm/IR/DerivedTypes.h"
34 #include "llvm/IR/DiagnosticInfo.h"
36 #include "llvm/IR/Function.h"
37 #include "llvm/IR/GlobalAlias.h"
38 #include "llvm/IR/GlobalObject.h"
39 #include "llvm/IR/GlobalValue.h"
40 #include "llvm/IR/GlobalVariable.h"
41 #include "llvm/IR/Mangler.h"
42 #include "llvm/IR/Metadata.h"
43 #include "llvm/IR/Module.h"
44 #include "llvm/IR/PseudoProbe.h"
45 #include "llvm/IR/Type.h"
46 #include "llvm/MC/MCAsmInfo.h"
47 #include "llvm/MC/MCContext.h"
48 #include "llvm/MC/MCExpr.h"
49 #include "llvm/MC/MCSectionCOFF.h"
50 #include "llvm/MC/MCSectionELF.h"
51 #include "llvm/MC/MCSectionGOFF.h"
52 #include "llvm/MC/MCSectionMachO.h"
53 #include "llvm/MC/MCSectionWasm.h"
54 #include "llvm/MC/MCSectionXCOFF.h"
55 #include "llvm/MC/MCStreamer.h"
56 #include "llvm/MC/MCSymbol.h"
57 #include "llvm/MC/MCSymbolELF.h"
58 #include "llvm/MC/MCValue.h"
59 #include "llvm/MC/SectionKind.h"
61 #include "llvm/Support/Casting.h"
62 #include "llvm/Support/CodeGen.h"
64 #include "llvm/Support/Format.h"
67 #include <cassert>
68 #include <string>
69 
70 using namespace llvm;
71 using namespace dwarf;
72 
73 static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
74  StringRef &Section) {
76  M.getModuleFlagsMetadata(ModuleFlags);
77 
78  for (const auto &MFE: ModuleFlags) {
79  // Ignore flags with 'Require' behaviour.
80  if (MFE.Behavior == Module::Require)
81  continue;
82 
83  StringRef Key = MFE.Key->getString();
84  if (Key == "Objective-C Image Info Version") {
85  Version = mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
86  } else if (Key == "Objective-C Garbage Collection" ||
87  Key == "Objective-C GC Only" ||
88  Key == "Objective-C Is Simulated" ||
89  Key == "Objective-C Class Properties" ||
90  Key == "Objective-C Image Swift Version") {
91  Flags |= mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
92  } else if (Key == "Objective-C Image Info Section") {
93  Section = cast<MDString>(MFE.Val)->getString();
94  }
95  // Backend generates L_OBJC_IMAGE_INFO from Swift ABI version + major + minor +
96  // "Objective-C Garbage Collection".
97  else if (Key == "Swift ABI Version") {
98  Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 8;
99  } else if (Key == "Swift Major Version") {
100  Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 24;
101  } else if (Key == "Swift Minor Version") {
102  Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 16;
103  }
104  }
105 }
106 
107 //===----------------------------------------------------------------------===//
108 // ELF
109 //===----------------------------------------------------------------------===//
110 
114 }
115 
117  const TargetMachine &TgtM) {
119 
120  CodeModel::Model CM = TgtM.getCodeModel();
122 
123  switch (TgtM.getTargetTriple().getArch()) {
124  case Triple::arm:
125  case Triple::armeb:
126  case Triple::thumb:
127  case Triple::thumbeb:
129  break;
130  // Fallthrough if not using EHABI
132  case Triple::ppc:
133  case Triple::ppcle:
134  case Triple::x86:
147  break;
148  case Triple::x86_64:
149  if (isPositionIndependent()) {
151  ((CM == CodeModel::Small || CM == CodeModel::Medium)
154  (CM == CodeModel::Small
157  ((CM == CodeModel::Small || CM == CodeModel::Medium)
159  } else {
161  (CM == CodeModel::Small || CM == CodeModel::Medium)
167  }
168  break;
169  case Triple::hexagon:
173  if (isPositionIndependent()) {
177  }
178  break;
179  case Triple::aarch64:
180  case Triple::aarch64_be:
181  case Triple::aarch64_32:
182  // The small model guarantees static code/data size < 4GB, but not where it
183  // will be in memory. Most of these could end up >2GB away so even a signed
184  // pc-relative 32-bit address is insufficient, theoretically.
185  if (isPositionIndependent()) {
186  // ILP32 uses sdata4 instead of sdata8
193  } else {
199  }
200  } else {
204  }
205  break;
206  case Triple::lanai:
210  break;
211  case Triple::mips:
212  case Triple::mipsel:
213  case Triple::mips64:
214  case Triple::mips64el:
215  // MIPS uses indirect pointer to refer personality functions and types, so
216  // that the eh_frame section can be read-only. DW.ref.personality will be
217  // generated for relocation.
219  // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
220  // identify N64 from just a triple.
223  // We don't support PC-relative LSDA references in GAS so we use the default
224  // DW_EH_PE_absptr for those.
225 
226  // FreeBSD must be explicit about the data size and using pcrel since it's
227  // assembler/linker won't do the automatic conversion that the Linux tools
228  // do.
229  if (TgtM.getTargetTriple().isOSFreeBSD()) {
232  }
233  break;
234  case Triple::ppc64:
235  case Triple::ppc64le:
241  break;
242  case Triple::sparcel:
243  case Triple::sparc:
244  if (isPositionIndependent()) {
250  } else {
254  }
256  break;
257  case Triple::riscv32:
258  case Triple::riscv64:
265  break;
266  case Triple::sparcv9:
268  if (isPositionIndependent()) {
273  } else {
276  }
277  break;
278  case Triple::systemz:
279  // All currently-defined code models guarantee that 4-byte PC-relative
280  // values will be in range.
281  if (isPositionIndependent()) {
287  } else {
291  }
292  break;
293  default:
294  break;
295  }
296 }
297 
300  collectUsedGlobalVariables(M, Vec, false);
301  for (GlobalValue *GV : Vec)
302  if (auto *GO = dyn_cast<GlobalObject>(GV))
303  Used.insert(GO);
304 }
305 
307  Module &M) const {
308  auto &C = getContext();
309 
310  if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
311  auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS,
313 
314  Streamer.SwitchSection(S);
315 
316  for (const auto *Operand : LinkerOptions->operands()) {
317  if (cast<MDNode>(Operand)->getNumOperands() != 2)
318  report_fatal_error("invalid llvm.linker.options");
319  for (const auto &Option : cast<MDNode>(Operand)->operands()) {
320  Streamer.emitBytes(cast<MDString>(Option)->getString());
321  Streamer.emitInt8(0);
322  }
323  }
324  }
325 
326  if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
327  auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
329 
330  Streamer.SwitchSection(S);
331 
332  for (const auto *Operand : DependentLibraries->operands()) {
333  Streamer.emitBytes(
334  cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
335  Streamer.emitInt8(0);
336  }
337  }
338 
339  if (NamedMDNode *FuncInfo = M.getNamedMetadata(PseudoProbeDescMetadataName)) {
340  // Emit a descriptor for every function including functions that have an
341  // available external linkage. We may not want this for imported functions
342  // that has code in another thinLTO module but we don't have a good way to
343  // tell them apart from inline functions defined in header files. Therefore
344  // we put each descriptor in a separate comdat section and rely on the
345  // linker to deduplicate.
346  for (const auto *Operand : FuncInfo->operands()) {
347  const auto *MD = cast<MDNode>(Operand);
348  auto *GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
349  auto *Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
350  auto *Name = cast<MDString>(MD->getOperand(2));
351  auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(
352  TM->getFunctionSections() ? Name->getString() : StringRef());
353 
354  Streamer.SwitchSection(S);
355  Streamer.emitInt64(GUID->getZExtValue());
356  Streamer.emitInt64(Hash->getZExtValue());
357  Streamer.emitULEB128IntValue(Name->getString().size());
358  Streamer.emitBytes(Name->getString());
359  }
360  }
361 
362  unsigned Version = 0;
363  unsigned Flags = 0;
365 
366  GetObjCImageInfo(M, Version, Flags, Section);
367  if (!Section.empty()) {
368  auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
369  Streamer.SwitchSection(S);
370  Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
371  Streamer.emitInt32(Version);
372  Streamer.emitInt32(Flags);
373  Streamer.AddBlankLine();
374  }
375 
376  emitCGProfileMetadata(Streamer, M);
377 }
378 
380  const GlobalValue *GV, const TargetMachine &TM,
381  MachineModuleInfo *MMI) const {
382  unsigned Encoding = getPersonalityEncoding();
383  if ((Encoding & 0x80) == DW_EH_PE_indirect)
384  return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
385  TM.getSymbol(GV)->getName());
386  if ((Encoding & 0x70) == DW_EH_PE_absptr)
387  return TM.getSymbol(GV);
388  report_fatal_error("We do not support this DWARF encoding yet!");
389 }
390 
392  MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const {
393  SmallString<64> NameData("DW.ref.");
394  NameData += Sym->getName();
395  MCSymbolELF *Label =
396  cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
397  Streamer.emitSymbolAttribute(Label, MCSA_Hidden);
398  Streamer.emitSymbolAttribute(Label, MCSA_Weak);
399  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
400  MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
401  ELF::SHT_PROGBITS, Flags, 0);
402  unsigned Size = DL.getPointerSize();
403  Streamer.SwitchSection(Sec);
404  Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0).value());
405  Streamer.emitSymbolAttribute(Label, MCSA_ELF_TypeObject);
407  Streamer.emitELFSize(Label, E);
408  Streamer.emitLabel(Label);
409 
410  Streamer.emitSymbolValue(Sym, Size);
411 }
412 
414  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
415  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
416  if (Encoding & DW_EH_PE_indirect) {
418 
419  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
420 
421  // Add information about the stub reference to ELFMMI so that the stub
422  // gets emitted by the asmprinter.
423  MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
424  if (!StubSym.getPointer()) {
425  MCSymbol *Sym = TM.getSymbol(GV);
427  }
428 
431  Encoding & ~DW_EH_PE_indirect, Streamer);
432  }
433 
435  MMI, Streamer);
436 }
437 
439  // N.B.: The defaults used in here are not the same ones used in MC.
440  // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
441  // both gas and MC will produce a section with no flags. Given
442  // section(".eh_frame") gcc will produce:
443  //
444  // .section .eh_frame,"a",@progbits
445 
446  if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
447  /*AddSegmentInfo=*/false) ||
448  Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
449  /*AddSegmentInfo=*/false) ||
450  Name == ".llvmbc" || Name == ".llvmcmd")
451  return SectionKind::getMetadata();
452 
453  if (Name.empty() || Name[0] != '.') return K;
454 
455  // Default implementation based on some magic section names.
456  if (Name == ".bss" ||
457  Name.startswith(".bss.") ||
458  Name.startswith(".gnu.linkonce.b.") ||
459  Name.startswith(".llvm.linkonce.b.") ||
460  Name == ".sbss" ||
461  Name.startswith(".sbss.") ||
462  Name.startswith(".gnu.linkonce.sb.") ||
463  Name.startswith(".llvm.linkonce.sb."))
464  return SectionKind::getBSS();
465 
466  if (Name == ".tdata" ||
467  Name.startswith(".tdata.") ||
468  Name.startswith(".gnu.linkonce.td.") ||
469  Name.startswith(".llvm.linkonce.td."))
471 
472  if (Name == ".tbss" ||
473  Name.startswith(".tbss.") ||
474  Name.startswith(".gnu.linkonce.tb.") ||
475  Name.startswith(".llvm.linkonce.tb."))
476  return SectionKind::getThreadBSS();
477 
478  return K;
479 }
480 
482  // Use SHT_NOTE for section whose name starts with ".note" to allow
483  // emitting ELF notes from C variable declaration.
484  // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
485  if (Name.startswith(".note"))
486  return ELF::SHT_NOTE;
487 
488  if (Name == ".init_array")
489  return ELF::SHT_INIT_ARRAY;
490 
491  if (Name == ".fini_array")
492  return ELF::SHT_FINI_ARRAY;
493 
494  if (Name == ".preinit_array")
495  return ELF::SHT_PREINIT_ARRAY;
496 
497  if (K.isBSS() || K.isThreadBSS())
498  return ELF::SHT_NOBITS;
499 
500  return ELF::SHT_PROGBITS;
501 }
502 
503 static unsigned getELFSectionFlags(SectionKind K) {
504  unsigned Flags = 0;
505 
506  if (!K.isMetadata())
507  Flags |= ELF::SHF_ALLOC;
508 
509  if (K.isText())
510  Flags |= ELF::SHF_EXECINSTR;
511 
512  if (K.isExecuteOnly())
513  Flags |= ELF::SHF_ARM_PURECODE;
514 
515  if (K.isWriteable())
516  Flags |= ELF::SHF_WRITE;
517 
518  if (K.isThreadLocal())
519  Flags |= ELF::SHF_TLS;
520 
521  if (K.isMergeableCString() || K.isMergeableConst())
522  Flags |= ELF::SHF_MERGE;
523 
524  if (K.isMergeableCString())
525  Flags |= ELF::SHF_STRINGS;
526 
527  return Flags;
528 }
529 
530 static const Comdat *getELFComdat(const GlobalValue *GV) {
531  const Comdat *C = GV->getComdat();
532  if (!C)
533  return nullptr;
534 
535  if (C->getSelectionKind() != Comdat::Any &&
536  C->getSelectionKind() != Comdat::NoDeduplicate)
537  report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
538  "SelectionKind::NoDeduplicate, '" +
539  C->getName() + "' cannot be lowered.");
540 
541  return C;
542 }
543 
545  const TargetMachine &TM) {
546  MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
547  if (!MD)
548  return nullptr;
549 
550  const MDOperand &Op = MD->getOperand(0);
551  if (!Op.get())
552  return nullptr;
553 
554  auto *VM = dyn_cast<ValueAsMetadata>(Op);
555  if (!VM)
556  report_fatal_error("MD_associated operand is not ValueAsMetadata");
557 
558  auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
559  return OtherGV ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGV)) : nullptr;
560 }
561 
563  if (Kind.isMergeable1ByteCString())
564  return 1;
565  else if (Kind.isMergeable2ByteCString())
566  return 2;
567  else if (Kind.isMergeable4ByteCString())
568  return 4;
569  else if (Kind.isMergeableConst4())
570  return 4;
571  else if (Kind.isMergeableConst8())
572  return 8;
573  else if (Kind.isMergeableConst16())
574  return 16;
575  else if (Kind.isMergeableConst32())
576  return 32;
577  else {
578  // We shouldn't have mergeable C strings or mergeable constants that we
579  // didn't handle above.
580  assert(!Kind.isMergeableCString() && "unknown string width");
581  assert(!Kind.isMergeableConst() && "unknown data width");
582  return 0;
583  }
584 }
585 
586 /// Return the section prefix name used by options FunctionsSections and
587 /// DataSections.
589  if (Kind.isText())
590  return ".text";
591  if (Kind.isReadOnly())
592  return ".rodata";
593  if (Kind.isBSS())
594  return ".bss";
595  if (Kind.isThreadData())
596  return ".tdata";
597  if (Kind.isThreadBSS())
598  return ".tbss";
599  if (Kind.isData())
600  return ".data";
601  if (Kind.isReadOnlyWithRel())
602  return ".data.rel.ro";
603  llvm_unreachable("Unknown section kind");
604 }
605 
606 static SmallString<128>
608  Mangler &Mang, const TargetMachine &TM,
609  unsigned EntrySize, bool UniqueSectionName) {
611  if (Kind.isMergeableCString()) {
612  // We also need alignment here.
613  // FIXME: this is getting the alignment of the character, not the
614  // alignment of the global!
615  Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
616  cast<GlobalVariable>(GO));
617 
618  std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
619  Name = SizeSpec + utostr(Alignment.value());
620  } else if (Kind.isMergeableConst()) {
621  Name = ".rodata.cst";
622  Name += utostr(EntrySize);
623  } else {
625  }
626 
627  bool HasPrefix = false;
628  if (const auto *F = dyn_cast<Function>(GO)) {
629  if (Optional<StringRef> Prefix = F->getSectionPrefix()) {
630  raw_svector_ostream(Name) << '.' << *Prefix;
631  HasPrefix = true;
632  }
633  }
634 
635  if (UniqueSectionName) {
636  Name.push_back('.');
637  TM.getNameWithPrefix(Name, GO, Mang, /*MayAlwaysUsePrivate*/true);
638  } else if (HasPrefix)
639  // For distinguishing between .text.${text-section-prefix}. (with trailing
640  // dot) and .text.${function-name}
641  Name.push_back('.');
642  return Name;
643 }
644 
645 namespace {
646 class LoweringDiagnosticInfo : public DiagnosticInfo {
647  const Twine &Msg;
648 
649 public:
650  LoweringDiagnosticInfo(const Twine &DiagMsg,
651  DiagnosticSeverity Severity = DS_Error)
652  : DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
653  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
654 };
655 }
656 
657 /// Calculate an appropriate unique ID for a section, and update Flags,
658 /// EntrySize and NextUniqueID where appropriate.
659 static unsigned
662  MCContext &Ctx, Mangler &Mang, unsigned &Flags,
663  unsigned &EntrySize, unsigned &NextUniqueID,
664  const bool Retain, const bool ForceUnique) {
665  // Increment uniqueID if we are forced to emit a unique section.
666  // This works perfectly fine with section attribute or pragma section as the
667  // sections with the same name are grouped together by the assembler.
668  if (ForceUnique)
669  return NextUniqueID++;
670 
671  // A section can have at most one associated section. Put each global with
672  // MD_associated in a unique section.
673  const bool Associated = GO->getMetadata(LLVMContext::MD_associated);
674  if (Associated) {
675  Flags |= ELF::SHF_LINK_ORDER;
676  return NextUniqueID++;
677  }
678 
679  if (Retain) {
680  if (Ctx.getAsmInfo()->useIntegratedAssembler() ||
681  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))
682  Flags |= ELF::SHF_GNU_RETAIN;
683  return NextUniqueID++;
684  }
685 
686  // If two symbols with differing sizes end up in the same mergeable section
687  // that section can be assigned an incorrect entry size. To avoid this we
688  // usually put symbols of the same size into distinct mergeable sections with
689  // the same name. Doing so relies on the ",unique ," assembly feature. This
690  // feature is not avalible until bintuils version 2.35
691  // (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
692  const bool SupportsUnique = Ctx.getAsmInfo()->useIntegratedAssembler() ||
693  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35);
694  if (!SupportsUnique) {
695  Flags &= ~ELF::SHF_MERGE;
696  EntrySize = 0;
698  }
699 
700  const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
701  const bool SeenSectionNameBefore =
703  // If this is the first ocurrence of this section name, treat it as the
704  // generic section
705  if (!SymbolMergeable && !SeenSectionNameBefore)
707 
708  // Symbols must be placed into sections with compatible entry sizes. Generate
709  // unique sections for symbols that have not been assigned to compatible
710  // sections.
711  const auto PreviousID =
712  Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
713  if (PreviousID)
714  return *PreviousID;
715 
716  // If the user has specified the same section name as would be created
717  // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
718  // to unique the section as the entry size for this symbol will be
719  // compatible with implicitly created sections.
720  SmallString<128> ImplicitSectionNameStem =
721  getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false);
722  if (SymbolMergeable &&
724  SectionName.startswith(ImplicitSectionNameStem))
726 
727  // We have seen this section name before, but with different flags or entity
728  // size. Create a new unique ID.
729  return NextUniqueID++;
730 }
731 
733  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
734  MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
735  bool Retain, bool ForceUnique) {
737 
738  // Check if '#pragma clang section' name is applicable.
739  // Note that pragma directive overrides -ffunction-section, -fdata-section
740  // and so section name is exactly as user specified and not uniqued.
741  const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
742  if (GV && GV->hasImplicitSection()) {
743  auto Attrs = GV->getAttributes();
744  if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) {
745  SectionName = Attrs.getAttribute("bss-section").getValueAsString();
746  } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) {
747  SectionName = Attrs.getAttribute("rodata-section").getValueAsString();
748  } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) {
749  SectionName = Attrs.getAttribute("relro-section").getValueAsString();
750  } else if (Attrs.hasAttribute("data-section") && Kind.isData()) {
751  SectionName = Attrs.getAttribute("data-section").getValueAsString();
752  }
753  }
754  const Function *F = dyn_cast<Function>(GO);
755  if (F && F->hasFnAttribute("implicit-section-name")) {
756  SectionName = F->getFnAttribute("implicit-section-name").getValueAsString();
757  }
758 
759  // Infer section flags from the section name if we can.
761 
762  StringRef Group = "";
763  bool IsComdat = false;
764  unsigned Flags = getELFSectionFlags(Kind);
765  if (const Comdat *C = getELFComdat(GO)) {
766  Group = C->getName();
767  IsComdat = C->getSelectionKind() == Comdat::Any;
768  Flags |= ELF::SHF_GROUP;
769  }
770 
771  unsigned EntrySize = getEntrySizeForKind(Kind);
772  const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize(
773  GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
774  Retain, ForceUnique);
775 
776  const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
778  SectionName, getELFSectionType(SectionName, Kind), Flags, EntrySize,
779  Group, IsComdat, UniqueID, LinkedToSym);
780  // Make sure that we did not get some other section with incompatible sh_link.
781  // This should not be possible due to UniqueID code above.
782  assert(Section->getLinkedToSymbol() == LinkedToSym &&
783  "Associated symbol mismatch between sections");
784 
785  if (!(Ctx.getAsmInfo()->useIntegratedAssembler() ||
786  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35))) {
787  // If we are using GNU as before 2.35, then this symbol might have
788  // been placed in an incompatible mergeable section. Emit an error if this
789  // is the case to avoid creating broken output.
790  if ((Section->getFlags() & ELF::SHF_MERGE) &&
791  (Section->getEntrySize() != getEntrySizeForKind(Kind)))
792  GO->getContext().diagnose(LoweringDiagnosticInfo(
793  "Symbol '" + GO->getName() + "' from module '" +
794  (GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
795  "' required a section with entry-size=" +
796  Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
797  SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
798  ": Explicit assignment by pragma or attribute of an incompatible "
799  "symbol to this section?"));
800  }
801 
802  return Section;
803 }
804 
806  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
808  NextUniqueID, Used.count(GO),
809  /* ForceUnique = */false);
810 }
811 
813  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
814  const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
815  unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
816 
817  StringRef Group = "";
818  bool IsComdat = false;
819  if (const Comdat *C = getELFComdat(GO)) {
820  Flags |= ELF::SHF_GROUP;
821  Group = C->getName();
822  IsComdat = C->getSelectionKind() == Comdat::Any;
823  }
824 
825  // Get the section entry size based on the kind.
826  unsigned EntrySize = getEntrySizeForKind(Kind);
827 
828  bool UniqueSectionName = false;
829  unsigned UniqueID = MCContext::GenericSectionID;
830  if (EmitUniqueSection) {
831  if (TM.getUniqueSectionNames()) {
832  UniqueSectionName = true;
833  } else {
834  UniqueID = *NextUniqueID;
835  (*NextUniqueID)++;
836  }
837  }
839  GO, Kind, Mang, TM, EntrySize, UniqueSectionName);
840 
841  // Use 0 as the unique ID for execute-only text.
842  if (Kind.isExecuteOnly())
843  UniqueID = 0;
844  return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags,
845  EntrySize, Group, IsComdat, UniqueID,
846  AssociatedSymbol);
847 }
848 
850  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
851  const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
852  unsigned Flags, unsigned *NextUniqueID) {
853  const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
854  if (LinkedToSym) {
855  EmitUniqueSection = true;
856  Flags |= ELF::SHF_LINK_ORDER;
857  }
858  if (Retain && (Ctx.getAsmInfo()->useIntegratedAssembler() ||
859  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))) {
860  EmitUniqueSection = true;
861  Flags |= ELF::SHF_GNU_RETAIN;
862  }
863 
865  Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
866  NextUniqueID, LinkedToSym);
867  assert(Section->getLinkedToSymbol() == LinkedToSym);
868  return Section;
869 }
870 
872  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
873  unsigned Flags = getELFSectionFlags(Kind);
874 
875  // If we have -ffunction-section or -fdata-section then we should emit the
876  // global value to a uniqued section specifically for it.
877  bool EmitUniqueSection = false;
878  if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
879  if (Kind.isText())
880  EmitUniqueSection = TM.getFunctionSections();
881  else
882  EmitUniqueSection = TM.getDataSections();
883  }
884  EmitUniqueSection |= GO->hasComdat();
886  Used.count(GO), EmitUniqueSection, Flags,
887  &NextUniqueID);
888 }
889 
891  const Function &F, const TargetMachine &TM) const {
893  unsigned Flags = getELFSectionFlags(Kind);
894  // If the function's section names is pre-determined via pragma or a
895  // section attribute, call selectExplicitSectionGlobal.
896  if (F.hasSection() || F.hasFnAttribute("implicit-section-name"))
898  &F, Kind, TM, getContext(), getMangler(), NextUniqueID,
899  Used.count(&F), /* ForceUnique = */true);
900  else
902  getContext(), &F, Kind, getMangler(), TM, Used.count(&F),
903  /*EmitUniqueSection=*/true, Flags, &NextUniqueID);
904 }
905 
907  const Function &F, const TargetMachine &TM) const {
908  // If the function can be removed, produce a unique section so that
909  // the table doesn't prevent the removal.
910  const Comdat *C = F.getComdat();
911  bool EmitUniqueSection = TM.getFunctionSections() || C;
912  if (!EmitUniqueSection)
913  return ReadOnlySection;
914 
916  getMangler(), TM, EmitUniqueSection,
917  ELF::SHF_ALLOC, &NextUniqueID,
918  /* AssociatedSymbol */ nullptr);
919 }
920 
922  const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
923  // If neither COMDAT nor function sections, use the monolithic LSDA section.
924  // Re-use this path if LSDASection is null as in the Arm EHABI.
925  if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
926  return LSDASection;
927 
928  const auto *LSDA = cast<MCSectionELF>(LSDASection);
929  unsigned Flags = LSDA->getFlags();
930  const MCSymbolELF *LinkedToSym = nullptr;
931  StringRef Group;
932  bool IsComdat = false;
933  if (const Comdat *C = getELFComdat(&F)) {
934  Flags |= ELF::SHF_GROUP;
935  Group = C->getName();
936  IsComdat = C->getSelectionKind() == Comdat::Any;
937  }
938  // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
939  // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
940  if (TM.getFunctionSections() &&
941  (getContext().getAsmInfo()->useIntegratedAssembler() &&
942  getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
943  Flags |= ELF::SHF_LINK_ORDER;
944  LinkedToSym = cast<MCSymbolELF>(&FnSym);
945  }
946 
947  // Append the function name as the suffix like GCC, assuming
948  // -funique-section-names applies to .gcc_except_table sections.
949  return getContext().getELFSection(
950  (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
951  : LSDA->getName()),
952  LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
953  LinkedToSym);
954 }
955 
957  bool UsesLabelDifference, const Function &F) const {
958  // We can always create relative relocations, so use another section
959  // that can be marked non-executable.
960  return false;
961 }
962 
963 /// Given a mergeable constant with the specified size and relocation
964 /// information, return a section that it should be placed in.
966  const DataLayout &DL, SectionKind Kind, const Constant *C,
967  Align &Alignment) const {
968  if (Kind.isMergeableConst4() && MergeableConst4Section)
969  return MergeableConst4Section;
970  if (Kind.isMergeableConst8() && MergeableConst8Section)
971  return MergeableConst8Section;
972  if (Kind.isMergeableConst16() && MergeableConst16Section)
974  if (Kind.isMergeableConst32() && MergeableConst32Section)
976  if (Kind.isReadOnly())
977  return ReadOnlySection;
978 
979  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
980  return DataRelROSection;
981 }
982 
983 /// Returns a unique section for the given machine basic block.
985  const Function &F, const MachineBasicBlock &MBB,
986  const TargetMachine &TM) const {
987  assert(MBB.isBeginSection() && "Basic block does not start a section!");
988  unsigned UniqueID = MCContext::GenericSectionID;
989 
990  // For cold sections use the .text.split. prefix along with the parent
991  // function name. All cold blocks for the same function go to the same
992  // section. Similarly all exception blocks are grouped by symbol name
993  // under the .text.eh prefix. For regular sections, we either use a unique
994  // name, or a unique ID for the section.
998  Name += MBB.getParent()->getName();
1000  Name += ".text.eh.";
1001  Name += MBB.getParent()->getName();
1002  } else {
1003  Name += MBB.getParent()->getSection()->getName();
1005  if (!Name.endswith("."))
1006  Name += ".";
1007  Name += MBB.getSymbol()->getName();
1008  } else {
1009  UniqueID = NextUniqueID++;
1010  }
1011  }
1012 
1013  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
1014  std::string GroupName;
1015  if (F.hasComdat()) {
1016  Flags |= ELF::SHF_GROUP;
1017  GroupName = F.getComdat()->getName().str();
1018  }
1020  0 /* Entry Size */, GroupName,
1021  F.hasComdat(), UniqueID, nullptr);
1022 }
1023 
1024 static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
1025  bool IsCtor, unsigned Priority,
1026  const MCSymbol *KeySym) {
1027  std::string Name;
1028  unsigned Type;
1029  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
1030  StringRef Comdat = KeySym ? KeySym->getName() : "";
1031 
1032  if (KeySym)
1033  Flags |= ELF::SHF_GROUP;
1034 
1035  if (UseInitArray) {
1036  if (IsCtor) {
1038  Name = ".init_array";
1039  } else {
1041  Name = ".fini_array";
1042  }
1043  if (Priority != 65535) {
1044  Name += '.';
1045  Name += utostr(Priority);
1046  }
1047  } else {
1048  // The default scheme is .ctor / .dtor, so we have to invert the priority
1049  // numbering.
1050  if (IsCtor)
1051  Name = ".ctors";
1052  else
1053  Name = ".dtors";
1054  if (Priority != 65535)
1055  raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1057  }
1058 
1059  return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
1060 }
1061 
1063  unsigned Priority, const MCSymbol *KeySym) const {
1064  return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
1065  KeySym);
1066 }
1067 
1069  unsigned Priority, const MCSymbol *KeySym) const {
1070  return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
1071  KeySym);
1072 }
1073 
1075  const GlobalValue *LHS, const GlobalValue *RHS,
1076  const TargetMachine &TM) const {
1077  // We may only use a PLT-relative relocation to refer to unnamed_addr
1078  // functions.
1079  if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
1080  return nullptr;
1081 
1082  // Basic sanity checks.
1083  if (LHS->getType()->getPointerAddressSpace() != 0 ||
1084  RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
1085  RHS->isThreadLocal())
1086  return nullptr;
1087 
1088  return MCBinaryExpr::createSub(
1090  getContext()),
1092 }
1093 
1095  const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const {
1097 
1098  const auto *GV = Equiv->getGlobalValue();
1099 
1100  // A PLT entry is not needed for dso_local globals.
1101  if (GV->isDSOLocal() || GV->isImplicitDSOLocal())
1103 
1105  getContext());
1106 }
1107 
1109  // Use ".GCC.command.line" since this feature is to support clang's
1110  // -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1111  // same name.
1112  return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
1114 }
1115 
1116 void
1118  UseInitArray = UseInitArray_;
1119  MCContext &Ctx = getContext();
1120  if (!UseInitArray) {
1123 
1126  return;
1127  }
1128 
1133 }
1134 
1135 //===----------------------------------------------------------------------===//
1136 // MachO
1137 //===----------------------------------------------------------------------===//
1138 
1142 }
1143 
1145  const TargetMachine &TM) {
1147  if (TM.getRelocationModel() == Reloc::Static) {
1148  StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0,
1150  StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0,
1152  } else {
1153  StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func",
1156  StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func",
1159  }
1160 
1164  TTypeEncoding =
1166 }
1167 
1169  Module &M) const {
1170  // Emit the linker options if present.
1171  if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1172  for (const auto *Option : LinkerOptions->operands()) {
1173  SmallVector<std::string, 4> StrOptions;
1174  for (const auto &Piece : cast<MDNode>(Option)->operands())
1175  StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1176  Streamer.emitLinkerOptions(StrOptions);
1177  }
1178  }
1179 
1180  unsigned VersionVal = 0;
1181  unsigned ImageInfoFlags = 0;
1182  StringRef SectionVal;
1183 
1184  GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1185 
1186  // The section is mandatory. If we don't have it, then we don't have GC info.
1187  if (SectionVal.empty())
1188  return;
1189 
1190  StringRef Segment, Section;
1191  unsigned TAA = 0, StubSize = 0;
1192  bool TAAParsed;
1194  SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1195  // If invalid, report the error with report_fatal_error.
1196  report_fatal_error("Invalid section specifier '" + Section +
1197  "': " + toString(std::move(E)) + ".");
1198  }
1199 
1200  // Get the section.
1202  Segment, Section, TAA, StubSize, SectionKind::getData());
1203  Streamer.SwitchSection(S);
1204  Streamer.emitLabel(getContext().
1205  getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1206  Streamer.emitInt32(VersionVal);
1207  Streamer.emitInt32(ImageInfoFlags);
1208  Streamer.AddBlankLine();
1209 }
1210 
1211 static void checkMachOComdat(const GlobalValue *GV) {
1212  const Comdat *C = GV->getComdat();
1213  if (!C)
1214  return;
1215 
1216  report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
1217  "' cannot be lowered.");
1218 }
1219 
1221  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1222 
1224 
1225  const Function *F = dyn_cast<Function>(GO);
1226  if (F && F->hasFnAttribute("implicit-section-name")) {
1227  SectionName = F->getFnAttribute("implicit-section-name").getValueAsString();
1228  }
1229 
1230  // Parse the section specifier and create it if valid.
1231  StringRef Segment, Section;
1232  unsigned TAA = 0, StubSize = 0;
1233  bool TAAParsed;
1234 
1235  checkMachOComdat(GO);
1236 
1238  SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1239  // If invalid, report the error with report_fatal_error.
1240  report_fatal_error("Global variable '" + GO->getName() +
1241  "' has an invalid section specifier '" +
1242  GO->getSection() + "': " + toString(std::move(E)) + ".");
1243  }
1244 
1245  // Get the section.
1246  MCSectionMachO *S =
1247  getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1248 
1249  // If TAA wasn't set by ParseSectionSpecifier() above,
1250  // use the value returned by getMachOSection() as a default.
1251  if (!TAAParsed)
1252  TAA = S->getTypeAndAttributes();
1253 
1254  // Okay, now that we got the section, verify that the TAA & StubSize agree.
1255  // If the user declared multiple globals with different section flags, we need
1256  // to reject it here.
1257  if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1258  // If invalid, report the error with report_fatal_error.
1259  report_fatal_error("Global variable '" + GO->getName() +
1260  "' section type or attributes does not match previous"
1261  " section specifier");
1262  }
1263 
1264  return S;
1265 }
1266 
1268  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1269  checkMachOComdat(GO);
1270 
1271  // Handle thread local data.
1272  if (Kind.isThreadBSS()) return TLSBSSSection;
1273  if (Kind.isThreadData()) return TLSDataSection;
1274 
1275  if (Kind.isText())
1276  return GO->isWeakForLinker() ? TextCoalSection : TextSection;
1277 
1278  // If this is weak/linkonce, put this in a coalescable section, either in text
1279  // or data depending on if it is writable.
1280  if (GO->isWeakForLinker()) {
1281  if (Kind.isReadOnly())
1282  return ConstTextCoalSection;
1283  if (Kind.isReadOnlyWithRel())
1284  return ConstDataCoalSection;
1285  return DataCoalSection;
1286  }
1287 
1288  // FIXME: Alignment check should be handled by section classifier.
1289  if (Kind.isMergeable1ByteCString() &&
1291  cast<GlobalVariable>(GO)) < Align(32))
1292  return CStringSection;
1293 
1294  // Do not put 16-bit arrays in the UString section if they have an
1295  // externally visible label, this runs into issues with certain linker
1296  // versions.
1297  if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1299  cast<GlobalVariable>(GO)) < Align(32))
1300  return UStringSection;
1301 
1302  // With MachO only variables whose corresponding symbol starts with 'l' or
1303  // 'L' can be merged, so we only try merging GVs with private linkage.
1304  if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1305  if (Kind.isMergeableConst4())
1306  return FourByteConstantSection;
1307  if (Kind.isMergeableConst8())
1308  return EightByteConstantSection;
1309  if (Kind.isMergeableConst16())
1311  }
1312 
1313  // Otherwise, if it is readonly, but not something we can specially optimize,
1314  // just drop it in .const.
1315  if (Kind.isReadOnly())
1316  return ReadOnlySection;
1317 
1318  // If this is marked const, put it into a const section. But if the dynamic
1319  // linker needs to write to it, put it in the data segment.
1320  if (Kind.isReadOnlyWithRel())
1321  return ConstDataSection;
1322 
1323  // Put zero initialized globals with strong external linkage in the
1324  // DATA, __common section with the .zerofill directive.
1325  if (Kind.isBSSExtern())
1326  return DataCommonSection;
1327 
1328  // Put zero initialized globals with local linkage in __DATA,__bss directive
1329  // with the .zerofill directive (aka .lcomm).
1330  if (Kind.isBSSLocal())
1331  return DataBSSSection;
1332 
1333  // Otherwise, just drop the variable in the normal data section.
1334  return DataSection;
1335 }
1336 
1338  const DataLayout &DL, SectionKind Kind, const Constant *C,
1339  Align &Alignment) const {
1340  // If this constant requires a relocation, we have to put it in the data
1341  // segment, not in the text segment.
1342  if (Kind.isData() || Kind.isReadOnlyWithRel())
1343  return ConstDataSection;
1344 
1345  if (Kind.isMergeableConst4())
1346  return FourByteConstantSection;
1347  if (Kind.isMergeableConst8())
1348  return EightByteConstantSection;
1349  if (Kind.isMergeableConst16())
1351  return ReadOnlySection; // .const
1352 }
1353 
1355  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
1356  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1357  // The mach-o version of this method defaults to returning a stub reference.
1358 
1359  if (Encoding & DW_EH_PE_indirect) {
1360  MachineModuleInfoMachO &MachOMMI =
1362 
1363  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1364 
1365  // Add information about the stub reference to MachOMMI so that the stub
1366  // gets emitted by the asmprinter.
1367  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1368  if (!StubSym.getPointer()) {
1369  MCSymbol *Sym = TM.getSymbol(GV);
1370  StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1371  }
1372 
1375  Encoding & ~DW_EH_PE_indirect, Streamer);
1376  }
1377 
1379  MMI, Streamer);
1380 }
1381 
1383  const GlobalValue *GV, const TargetMachine &TM,
1384  MachineModuleInfo *MMI) const {
1385  // The mach-o version of this method defaults to returning a stub reference.
1386  MachineModuleInfoMachO &MachOMMI =
1388 
1389  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1390 
1391  // Add information about the stub reference to MachOMMI so that the stub
1392  // gets emitted by the asmprinter.
1393  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1394  if (!StubSym.getPointer()) {
1395  MCSymbol *Sym = TM.getSymbol(GV);
1396  StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1397  }
1398 
1399  return SSym;
1400 }
1401 
1403  const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
1404  int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1405  // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1406  // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1407  // through a non_lazy_ptr stub instead. One advantage is that it allows the
1408  // computation of deltas to final external symbols. Example:
1409  //
1410  // _extgotequiv:
1411  // .long _extfoo
1412  //
1413  // _delta:
1414  // .long _extgotequiv-_delta
1415  //
1416  // is transformed to:
1417  //
1418  // _delta:
1419  // .long L_extfoo$non_lazy_ptr-(_delta+0)
1420  //
1421  // .section __IMPORT,__pointers,non_lazy_symbol_pointers
1422  // L_extfoo$non_lazy_ptr:
1423  // .indirect_symbol _extfoo
1424  // .long 0
1425  //
1426  // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1427  // may point to both local (same translation unit) and global (other
1428  // translation units) symbols. Example:
1429  //
1430  // .section __DATA,__pointers,non_lazy_symbol_pointers
1431  // L1:
1432  // .indirect_symbol _myGlobal
1433  // .long 0
1434  // L2:
1435  // .indirect_symbol _myLocal
1436  // .long _myLocal
1437  //
1438  // If the symbol is local, instead of the symbol's index, the assembler
1439  // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1440  // Then the linker will notice the constant in the table and will look at the
1441  // content of the symbol.
1442  MachineModuleInfoMachO &MachOMMI =
1444  MCContext &Ctx = getContext();
1445 
1446  // The offset must consider the original displacement from the base symbol
1447  // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1448  Offset = -MV.getConstant();
1449  const MCSymbol *BaseSym = &MV.getSymB()->getSymbol();
1450 
1451  // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1452  // non_lazy_ptr stubs.
1454  StringRef Suffix = "$non_lazy_ptr";
1456  Name += Sym->getName();
1457  Name += Suffix;
1458  MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1459 
1460  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1461 
1462  if (!StubSym.getPointer())
1463  StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1464  !GV->hasLocalLinkage());
1465 
1466  const MCExpr *BSymExpr =
1468  const MCExpr *LHS =
1470 
1471  if (!Offset)
1472  return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1473 
1474  const MCExpr *RHS =
1476  return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1477 }
1478 
1479 static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
1480  const MCSection &Section) {
1481  if (!AsmInfo.isSectionAtomizableBySymbols(Section))
1482  return true;
1483 
1484  // FIXME: we should be able to use private labels for sections that can't be
1485  // dead-stripped (there's no issue with blocking atomization there), but `ld
1486  // -r` sometimes drops the no_dead_strip attribute from sections so for safety
1487  // we don't allow it.
1488  return false;
1489 }
1490 
1492  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1493  const TargetMachine &TM) const {
1494  bool CannotUsePrivateLabel = true;
1495  if (auto *GO = GV->getBaseObject()) {
1497  const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
1498  CannotUsePrivateLabel =
1499  !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
1500  }
1501  getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1502 }
1503 
1504 //===----------------------------------------------------------------------===//
1505 // COFF
1506 //===----------------------------------------------------------------------===//
1507 
1508 static unsigned
1510  unsigned Flags = 0;
1511  bool isThumb = TM.getTargetTriple().getArch() == Triple::thumb;
1512 
1513  if (K.isMetadata())
1514  Flags |=
1516  else if (K.isText())
1517  Flags |=
1522  else if (K.isBSS())
1523  Flags |=
1527  else if (K.isThreadLocal())
1528  Flags |=
1532  else if (K.isReadOnly() || K.isReadOnlyWithRel())
1533  Flags |=
1536  else if (K.isWriteable())
1537  Flags |=
1541 
1542  return Flags;
1543 }
1544 
1545 static const GlobalValue *getComdatGVForCOFF(const GlobalValue *GV) {
1546  const Comdat *C = GV->getComdat();
1547  assert(C && "expected GV to have a Comdat!");
1548 
1549  StringRef ComdatGVName = C->getName();
1550  const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1551  if (!ComdatGV)
1552  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1553  "' does not exist.");
1554 
1555  if (ComdatGV->getComdat() != C)
1556  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1557  "' is not a key for its COMDAT.");
1558 
1559  return ComdatGV;
1560 }
1561 
1562 static int getSelectionForCOFF(const GlobalValue *GV) {
1563  if (const Comdat *C = GV->getComdat()) {
1564  const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
1565  if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1566  ComdatKey = GA->getBaseObject();
1567  if (ComdatKey == GV) {
1568  switch (C->getSelectionKind()) {
1569  case Comdat::Any:
1571  case Comdat::ExactMatch:
1573  case Comdat::Largest:
1575  case Comdat::NoDeduplicate:
1577  case Comdat::SameSize:
1579  }
1580  } else {
1582  }
1583  }
1584  return 0;
1585 }
1586 
1588  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1589  int Selection = 0;
1591  StringRef Name = GO->getSection();
1592  StringRef COMDATSymName = "";
1593  if (GO->hasComdat()) {
1595  const GlobalValue *ComdatGV;
1597  ComdatGV = getComdatGVForCOFF(GO);
1598  else
1599  ComdatGV = GO;
1600 
1601  if (!ComdatGV->hasPrivateLinkage()) {
1602  MCSymbol *Sym = TM.getSymbol(ComdatGV);
1603  COMDATSymName = Sym->getName();
1605  } else {
1606  Selection = 0;
1607  }
1608  }
1609 
1610  return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
1611  Selection);
1612 }
1613 
1615  if (Kind.isText())
1616  return ".text";
1617  if (Kind.isBSS())
1618  return ".bss";
1619  if (Kind.isThreadLocal())
1620  return ".tls$";
1621  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1622  return ".rdata";
1623  return ".data";
1624 }
1625 
1627  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1628  // If we have -ffunction-sections then we should emit the global value to a
1629  // uniqued section specifically for it.
1630  bool EmitUniquedSection;
1631  if (Kind.isText())
1632  EmitUniquedSection = TM.getFunctionSections();
1633  else
1634  EmitUniquedSection = TM.getDataSections();
1635 
1636  if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1638 
1640 
1642  int Selection = getSelectionForCOFF(GO);
1643  if (!Selection)
1645  const GlobalValue *ComdatGV;
1646  if (GO->hasComdat())
1647  ComdatGV = getComdatGVForCOFF(GO);
1648  else
1649  ComdatGV = GO;
1650 
1651  unsigned UniqueID = MCContext::GenericSectionID;
1652  if (EmitUniquedSection)
1653  UniqueID = NextUniqueID++;
1654 
1655  if (!ComdatGV->hasPrivateLinkage()) {
1656  MCSymbol *Sym = TM.getSymbol(ComdatGV);
1657  StringRef COMDATSymName = Sym->getName();
1658 
1659  if (const auto *F = dyn_cast<Function>(GO))
1660  if (Optional<StringRef> Prefix = F->getSectionPrefix())
1661  raw_svector_ostream(Name) << '$' << *Prefix;
1662 
1663  // Append "$symbol" to the section name *before* IR-level mangling is
1664  // applied when targetting mingw. This is what GCC does, and the ld.bfd
1665  // COFF linker will not properly handle comdats otherwise.
1666  if (getContext().getTargetTriple().isWindowsGNUEnvironment())
1667  raw_svector_ostream(Name) << '$' << ComdatGV->getName();
1668 
1670  COMDATSymName, Selection, UniqueID);
1671  } else {
1672  SmallString<256> TmpData;
1673  getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
1674  return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
1675  Selection, UniqueID);
1676  }
1677  }
1678 
1679  if (Kind.isText())
1680  return TextSection;
1681 
1682  if (Kind.isThreadLocal())
1683  return TLSDataSection;
1684 
1685  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1686  return ReadOnlySection;
1687 
1688  // Note: we claim that common symbols are put in BSSSection, but they are
1689  // really emitted with the magic .comm directive, which creates a symbol table
1690  // entry but not a section.
1691  if (Kind.isBSS() || Kind.isCommon())
1692  return BSSSection;
1693 
1694  return DataSection;
1695 }
1696 
1698  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1699  const TargetMachine &TM) const {
1700  bool CannotUsePrivateLabel = false;
1701  if (GV->hasPrivateLinkage() &&
1702  ((isa<Function>(GV) && TM.getFunctionSections()) ||
1703  (isa<GlobalVariable>(GV) && TM.getDataSections())))
1704  CannotUsePrivateLabel = true;
1705 
1706  getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1707 }
1708 
1710  const Function &F, const TargetMachine &TM) const {
1711  // If the function can be removed, produce a unique section so that
1712  // the table doesn't prevent the removal.
1713  const Comdat *C = F.getComdat();
1714  bool EmitUniqueSection = TM.getFunctionSections() || C;
1715  if (!EmitUniqueSection)
1716  return ReadOnlySection;
1717 
1718  // FIXME: we should produce a symbol for F instead.
1719  if (F.hasPrivateLinkage())
1720  return ReadOnlySection;
1721 
1722  MCSymbol *Sym = TM.getSymbol(&F);
1723  StringRef COMDATSymName = Sym->getName();
1724 
1729  unsigned UniqueID = NextUniqueID++;
1730 
1731  return getContext().getCOFFSection(
1732  SecName, Characteristics, Kind, COMDATSymName,
1734 }
1735 
1737  Module &M) const {
1738  emitLinkerDirectives(Streamer, M);
1739 
1740  unsigned Version = 0;
1741  unsigned Flags = 0;
1743 
1744  GetObjCImageInfo(M, Version, Flags, Section);
1745  if (!Section.empty()) {
1746  auto &C = getContext();
1747  auto *S = C.getCOFFSection(Section,
1751  Streamer.SwitchSection(S);
1752  Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1753  Streamer.emitInt32(Version);
1754  Streamer.emitInt32(Flags);
1755  Streamer.AddBlankLine();
1756  }
1757 
1758  emitCGProfileMetadata(Streamer, M);
1759 }
1760 
1761 void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
1762  MCStreamer &Streamer, Module &M) const {
1763  if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1764  // Emit the linker options to the linker .drectve section. According to the
1765  // spec, this section is a space-separated string containing flags for
1766  // linker.
1767  MCSection *Sec = getDrectveSection();
1768  Streamer.SwitchSection(Sec);
1769  for (const auto *Option : LinkerOptions->operands()) {
1770  for (const auto &Piece : cast<MDNode>(Option)->operands()) {
1771  // Lead with a space for consistency with our dllexport implementation.
1772  std::string Directive(" ");
1773  Directive.append(std::string(cast<MDString>(Piece)->getString()));
1774  Streamer.emitBytes(Directive);
1775  }
1776  }
1777  }
1778 
1779  // Emit /EXPORT: flags for each exported global as necessary.
1780  std::string Flags;
1781  for (const GlobalValue &GV : M.global_values()) {
1782  raw_string_ostream OS(Flags);
1783  emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
1784  getMangler());
1785  OS.flush();
1786  if (!Flags.empty()) {
1787  Streamer.SwitchSection(getDrectveSection());
1788  Streamer.emitBytes(Flags);
1789  }
1790  Flags.clear();
1791  }
1792 
1793  // Emit /INCLUDE: flags for each used global as necessary.
1794  if (const auto *LU = M.getNamedGlobal("llvm.used")) {
1795  assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
1796  assert(isa<ArrayType>(LU->getValueType()) &&
1797  "expected llvm.used to be an array type");
1798  if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
1799  for (const Value *Op : A->operands()) {
1800  const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
1801  // Global symbols with internal or private linkage are not visible to
1802  // the linker, and thus would cause an error when the linker tried to
1803  // preserve the symbol due to the `/include:` directive.
1804  if (GV->hasLocalLinkage())
1805  continue;
1806 
1807  raw_string_ostream OS(Flags);
1808  emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
1809  getMangler());
1810  OS.flush();
1811 
1812  if (!Flags.empty()) {
1813  Streamer.SwitchSection(getDrectveSection());
1814  Streamer.emitBytes(Flags);
1815  }
1816  Flags.clear();
1817  }
1818  }
1819  }
1820 }
1821 
1823  const TargetMachine &TM) {
1825  this->TM = &TM;
1826  const Triple &T = TM.getTargetTriple();
1827  if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1836  } else {
1845  }
1846 }
1847 
1849  const Triple &T, bool IsCtor,
1850  unsigned Priority,
1851  const MCSymbol *KeySym,
1852  MCSectionCOFF *Default) {
1853  if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1854  // If the priority is the default, use .CRT$XCU, possibly associative.
1855  if (Priority == 65535)
1856  return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
1857 
1858  // Otherwise, we need to compute a new section name. Low priorities should
1859  // run earlier. The linker will sort sections ASCII-betically, and we need a
1860  // string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
1861  // make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
1862  // low priorities need to sort before 'L', since the CRT uses that
1863  // internally, so we use ".CRT$XCA00001" for them.
1866  OS << ".CRT$X" << (IsCtor ? "C" : "T") <<
1867  (Priority < 200 ? 'A' : 'T') << format("%05u", Priority);
1868  MCSectionCOFF *Sec = Ctx.getCOFFSection(
1871  return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
1872  }
1873 
1874  std::string Name = IsCtor ? ".ctors" : ".dtors";
1875  if (Priority != 65535)
1876  raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1877 
1878  return Ctx.getAssociativeCOFFSection(
1883  KeySym, 0);
1884 }
1885 
1887  unsigned Priority, const MCSymbol *KeySym) const {
1889  getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
1890  cast<MCSectionCOFF>(StaticCtorSection));
1891 }
1892 
1894  unsigned Priority, const MCSymbol *KeySym) const {
1896  getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
1897  cast<MCSectionCOFF>(StaticDtorSection));
1898 }
1899 
1901  const GlobalValue *LHS, const GlobalValue *RHS,
1902  const TargetMachine &TM) const {
1903  const Triple &T = TM.getTargetTriple();
1904  if (T.isOSCygMing())
1905  return nullptr;
1906 
1907  // Our symbols should exist in address space zero, cowardly no-op if
1908  // otherwise.
1909  if (LHS->getType()->getPointerAddressSpace() != 0 ||
1910  RHS->getType()->getPointerAddressSpace() != 0)
1911  return nullptr;
1912 
1913  // Both ptrtoint instructions must wrap global objects:
1914  // - Only global variables are eligible for image relative relocations.
1915  // - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
1916  // We expect __ImageBase to be a global variable without a section, externally
1917  // defined.
1918  //
1919  // It should look something like this: @__ImageBase = external constant i8
1920  if (!isa<GlobalObject>(LHS) || !isa<GlobalVariable>(RHS) ||
1921  LHS->isThreadLocal() || RHS->isThreadLocal() ||
1922  RHS->getName() != "__ImageBase" || !RHS->hasExternalLinkage() ||
1923  cast<GlobalVariable>(RHS)->hasInitializer() || RHS->hasSection())
1924  return nullptr;
1925 
1926  return MCSymbolRefExpr::create(TM.getSymbol(LHS),
1928  getContext());
1929 }
1930 
1931 static std::string APIntToHexString(const APInt &AI) {
1932  unsigned Width = (AI.getBitWidth() / 8) * 2;
1933  std::string HexString = toString(AI, 16, /*Signed=*/false);
1934  llvm::transform(HexString, HexString.begin(), tolower);
1935  unsigned Size = HexString.size();
1936  assert(Width >= Size && "hex string is too large!");
1937  HexString.insert(HexString.begin(), Width - Size, '0');
1938 
1939  return HexString;
1940 }
1941 
1942 static std::string scalarConstantToHexString(const Constant *C) {
1943  Type *Ty = C->getType();
1944  if (isa<UndefValue>(C)) {
1946  } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
1947  return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
1948  } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
1949  return APIntToHexString(CI->getValue());
1950  } else {
1951  unsigned NumElements;
1952  if (auto *VTy = dyn_cast<VectorType>(Ty))
1953  NumElements = cast<FixedVectorType>(VTy)->getNumElements();
1954  else
1955  NumElements = Ty->getArrayNumElements();
1956  std::string HexString;
1957  for (int I = NumElements - 1, E = -1; I != E; --I)
1958  HexString += scalarConstantToHexString(C->getAggregateElement(I));
1959  return HexString;
1960  }
1961 }
1962 
1964  const DataLayout &DL, SectionKind Kind, const Constant *C,
1965  Align &Alignment) const {
1966  if (Kind.isMergeableConst() && C &&
1967  getContext().getAsmInfo()->hasCOFFComdatConstants()) {
1968  // This creates comdat sections with the given symbol name, but unless
1969  // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
1970  // will be created with a null storage class, which makes GNU binutils
1971  // error out.
1975  std::string COMDATSymName;
1976  if (Kind.isMergeableConst4()) {
1977  if (Alignment <= 4) {
1978  COMDATSymName = "__real@" + scalarConstantToHexString(C);
1979  Alignment = Align(4);
1980  }
1981  } else if (Kind.isMergeableConst8()) {
1982  if (Alignment <= 8) {
1983  COMDATSymName = "__real@" + scalarConstantToHexString(C);
1984  Alignment = Align(8);
1985  }
1986  } else if (Kind.isMergeableConst16()) {
1987  // FIXME: These may not be appropriate for non-x86 architectures.
1988  if (Alignment <= 16) {
1989  COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
1990  Alignment = Align(16);
1991  }
1992  } else if (Kind.isMergeableConst32()) {
1993  if (Alignment <= 32) {
1994  COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
1995  Alignment = Align(32);
1996  }
1997  }
1998 
1999  if (!COMDATSymName.empty())
2000  return getContext().getCOFFSection(".rdata", Characteristics, Kind,
2001  COMDATSymName,
2003  }
2004 
2006  Alignment);
2007 }
2008 
2009 //===----------------------------------------------------------------------===//
2010 // Wasm
2011 //===----------------------------------------------------------------------===//
2012 
2013 static const Comdat *getWasmComdat(const GlobalValue *GV) {
2014  const Comdat *C = GV->getComdat();
2015  if (!C)
2016  return nullptr;
2017 
2018  if (C->getSelectionKind() != Comdat::Any)
2019  report_fatal_error("WebAssembly COMDATs only support "
2020  "SelectionKind::Any, '" + C->getName() + "' cannot be "
2021  "lowered.");
2022 
2023  return C;
2024 }
2025 
2026 static unsigned getWasmSectionFlags(SectionKind K) {
2027  unsigned Flags = 0;
2028 
2029  if (K.isThreadLocal())
2030  Flags |= wasm::WASM_SEG_FLAG_TLS;
2031 
2032  if (K.isMergeableCString())
2033  Flags |= wasm::WASM_SEG_FLAG_STRINGS;
2034 
2035  // TODO(sbc): Add suport for K.isMergeableConst()
2036 
2037  return Flags;
2038 }
2039 
2041  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2042  // We don't support explict section names for functions in the wasm object
2043  // format. Each function has to be in its own unique section.
2044  if (isa<Function>(GO)) {
2045  return SelectSectionForGlobal(GO, Kind, TM);
2046  }
2047 
2048  StringRef Name = GO->getSection();
2049 
2050  // Certain data sections we treat as named custom sections rather than
2051  // segments within the data section.
2052  // This could be avoided if all data segements (the wasm sense) were
2053  // represented as their own sections (in the llvm sense).
2054  // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2055  if (Name == ".llvmcmd" || Name == ".llvmbc")
2057 
2058  StringRef Group = "";
2059  if (const Comdat *C = getWasmComdat(GO)) {
2060  Group = C->getName();
2061  }
2062 
2063  unsigned Flags = getWasmSectionFlags(Kind);
2065  Name, Kind, Flags, Group, MCContext::GenericSectionID);
2066 
2067  return Section;
2068 }
2069 
2071  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
2072  const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID) {
2073  StringRef Group = "";
2074  if (const Comdat *C = getWasmComdat(GO)) {
2075  Group = C->getName();
2076  }
2077 
2078  bool UniqueSectionNames = TM.getUniqueSectionNames();
2080 
2081  if (const auto *F = dyn_cast<Function>(GO)) {
2082  const auto &OptionalPrefix = F->getSectionPrefix();
2083  if (OptionalPrefix)
2084  raw_svector_ostream(Name) << '.' << *OptionalPrefix;
2085  }
2086 
2087  if (EmitUniqueSection && UniqueSectionNames) {
2088  Name.push_back('.');
2089  TM.getNameWithPrefix(Name, GO, Mang, true);
2090  }
2091  unsigned UniqueID = MCContext::GenericSectionID;
2092  if (EmitUniqueSection && !UniqueSectionNames) {
2093  UniqueID = *NextUniqueID;
2094  (*NextUniqueID)++;
2095  }
2096 
2097  unsigned Flags = getWasmSectionFlags(Kind);
2098  return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2099 }
2100 
2102  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2103 
2104  if (Kind.isCommon())
2105  report_fatal_error("mergable sections not supported yet on wasm");
2106 
2107  // If we have -ffunction-section or -fdata-section then we should emit the
2108  // global value to a uniqued section specifically for it.
2109  bool EmitUniqueSection = false;
2110  if (Kind.isText())
2111  EmitUniqueSection = TM.getFunctionSections();
2112  else
2113  EmitUniqueSection = TM.getDataSections();
2114  EmitUniqueSection |= GO->hasComdat();
2115 
2117  EmitUniqueSection, &NextUniqueID);
2118 }
2119 
2121  bool UsesLabelDifference, const Function &F) const {
2122  // We can always create relative relocations, so use another section
2123  // that can be marked non-executable.
2124  return false;
2125 }
2126 
2128  const GlobalValue *LHS, const GlobalValue *RHS,
2129  const TargetMachine &TM) const {
2130  // We may only use a PLT-relative relocation to refer to unnamed_addr
2131  // functions.
2132  if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
2133  return nullptr;
2134 
2135  // Basic sanity checks.
2136  if (LHS->getType()->getPointerAddressSpace() != 0 ||
2137  RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
2138  RHS->isThreadLocal())
2139  return nullptr;
2140 
2141  return MCBinaryExpr::createSub(
2143  getContext()),
2145 }
2146 
2149  getContext().getWasmSection(".init_array", SectionKind::getData());
2150 
2151  // We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2152  // .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2154 }
2155 
2157  unsigned Priority, const MCSymbol *KeySym) const {
2158  return Priority == UINT16_MAX ?
2160  getContext().getWasmSection(".init_array." + utostr(Priority),
2162 }
2163 
2165  unsigned Priority, const MCSymbol *KeySym) const {
2166  llvm_unreachable("@llvm.global_dtors should have been lowered already");
2167  return nullptr;
2168 }
2169 
2170 //===----------------------------------------------------------------------===//
2171 // XCOFF
2172 //===----------------------------------------------------------------------===//
2174  const MachineFunction *MF) {
2175  if (!MF->getLandingPads().empty())
2176  return true;
2177 
2178  const Function &F = MF->getFunction();
2179  if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2180  return false;
2181 
2182  const GlobalValue *Per =
2183  dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2184  assert(Per && "Personality routine is not a GlobalValue type.");
2186  return false;
2187 
2188  return true;
2189 }
2190 
2192  const MachineFunction *MF) {
2193  const Function &F = MF->getFunction();
2194  if (!F.hasStackProtectorFnAttr())
2195  return false;
2196  // FIXME: check presence of canary word
2197  // There are cases that the stack protectors are not really inserted even if
2198  // the attributes are on.
2199  return true;
2200 }
2201 
2202 MCSymbol *
2204  return MF->getMMI().getContext().getOrCreateSymbol(
2205  "__ehinfo." + Twine(MF->getFunctionNumber()));
2206 }
2207 
2208 MCSymbol *
2210  const TargetMachine &TM) const {
2211  // We always use a qualname symbol for a GV that represents
2212  // a declaration, a function descriptor, or a common symbol.
2213  // If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2214  // also return a qualname so that a label symbol could be avoided.
2215  // It is inherently ambiguous when the GO represents the address of a
2216  // function, as the GO could either represent a function descriptor or a
2217  // function entry point. We choose to always return a function descriptor
2218  // here.
2219  if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2220  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2221  if (GVar->hasAttribute("toc-data"))
2222  return cast<MCSectionXCOFF>(
2224  ->getQualNameSymbol();
2225 
2226  if (GO->isDeclarationForLinker())
2227  return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
2228  ->getQualNameSymbol();
2229 
2230  SectionKind GOKind = getKindForGlobal(GO, TM);
2231  if (GOKind.isText())
2232  return cast<MCSectionXCOFF>(
2233  getSectionForFunctionDescriptor(cast<Function>(GO), TM))
2234  ->getQualNameSymbol();
2235  if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2236  GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2237  return cast<MCSectionXCOFF>(SectionForGlobal(GO, GOKind, TM))
2238  ->getQualNameSymbol();
2239  }
2240 
2241  // For all other cases, fall back to getSymbol to return the unqualified name.
2242  return nullptr;
2243 }
2244 
2246  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2247  if (!GO->hasSection())
2248  report_fatal_error("#pragma clang section is not yet supported");
2249 
2251 
2252  // Handle the XCOFF::TD case first, then deal with the rest.
2253  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2254  if (GVar->hasAttribute("toc-data"))
2255  return getContext().getXCOFFSection(
2256  SectionName, Kind,
2258  /* MultiSymbolsAllowed*/ true);
2259 
2260  XCOFF::StorageMappingClass MappingClass;
2261  if (Kind.isText())
2262  MappingClass = XCOFF::XMC_PR;
2263  else if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS())
2264  MappingClass = XCOFF::XMC_RW;
2265  else if (Kind.isReadOnly())
2266  MappingClass = XCOFF::XMC_RO;
2267  else
2268  report_fatal_error("XCOFF other section types not yet implemented.");
2269 
2270  return getContext().getXCOFFSection(
2272  /* MultiSymbolsAllowed*/ true);
2273 }
2274 
2276  const GlobalObject *GO, const TargetMachine &TM) const {
2278  "Tried to get ER section for a defined global.");
2279 
2281  getNameWithPrefix(Name, GO, TM);
2282 
2284  isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA;
2285  if (GO->isThreadLocal())
2286  SMC = XCOFF::XMC_UL;
2287 
2288  // Externals go into a csect of type ER.
2289  return getContext().getXCOFFSection(
2292 }
2293 
2295  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2296  // Handle the XCOFF::TD case first, then deal with the rest.
2297  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2298  if (GVar->hasAttribute("toc-data")) {
2300  getNameWithPrefix(Name, GO, TM);
2301  return getContext().getXCOFFSection(
2303  /* MultiSymbolsAllowed*/ true);
2304  }
2305 
2306  // Common symbols go into a csect with matching name which will get mapped
2307  // into the .bss section.
2308  // Zero-initialized local TLS symbols go into a csect with matching name which
2309  // will get mapped into the .tbss section.
2310  if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2312  getNameWithPrefix(Name, GO, TM);
2313  XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ? XCOFF::XMC_BS
2314  : Kind.isCommon() ? XCOFF::XMC_RW
2315  : XCOFF::XMC_UL;
2316  return getContext().getXCOFFSection(
2318  }
2319 
2320  if (Kind.isMergeableCString()) {
2321  Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
2322  cast<GlobalVariable>(GO));
2323 
2324  unsigned EntrySize = getEntrySizeForKind(Kind);
2325  std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
2327  Name = SizeSpec + utostr(Alignment.value());
2328 
2329  if (TM.getDataSections())
2330  getNameWithPrefix(Name, GO, TM);
2331 
2332  return getContext().getXCOFFSection(
2334  /* MultiSymbolsAllowed*/ !TM.getDataSections());
2335  }
2336 
2337  if (Kind.isText()) {
2338  if (TM.getFunctionSections()) {
2339  return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM))
2340  ->getRepresentedCsect();
2341  }
2342  return TextSection;
2343  }
2344 
2345  // TODO: We may put Kind.isReadOnlyWithRel() under option control, because
2346  // user may want to have read-only data with relocations placed into a
2347  // read-only section by the compiler.
2348  // For BSS kind, zero initialized data must be emitted to the .data section
2349  // because external linkage control sections that get mapped to the .bss
2350  // section will be linked as tentative defintions, which is only appropriate
2351  // for SectionKind::Common.
2352  if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2353  if (TM.getDataSections()) {
2355  getNameWithPrefix(Name, GO, TM);
2356  return getContext().getXCOFFSection(
2359  }
2360  return DataSection;
2361  }
2362 
2363  if (Kind.isReadOnly()) {
2364  if (TM.getDataSections()) {
2366  getNameWithPrefix(Name, GO, TM);
2367  return getContext().getXCOFFSection(
2370  }
2371  return ReadOnlySection;
2372  }
2373 
2374  // External/weak TLS data and initialized local TLS data are not eligible
2375  // to be put into common csect. If data sections are enabled, thread
2376  // data are emitted into separate sections. Otherwise, thread data
2377  // are emitted into the .tdata section.
2378  if (Kind.isThreadLocal()) {
2379  if (TM.getDataSections()) {
2381  getNameWithPrefix(Name, GO, TM);
2382  return getContext().getXCOFFSection(
2384  }
2385  return TLSDataSection;
2386  }
2387 
2388  report_fatal_error("XCOFF other section types not yet implemented.");
2389 }
2390 
2392  const Function &F, const TargetMachine &TM) const {
2393  assert (!F.getComdat() && "Comdat not supported on XCOFF.");
2394 
2395  if (!TM.getFunctionSections())
2396  return ReadOnlySection;
2397 
2398  // If the function can be removed, produce a unique section so that
2399  // the table doesn't prevent the removal.
2400  SmallString<128> NameStr(".rodata.jmp..");
2401  getNameWithPrefix(NameStr, &F, TM);
2402  return getContext().getXCOFFSection(
2403  NameStr, SectionKind::getReadOnly(),
2405 }
2406 
2408  bool UsesLabelDifference, const Function &F) const {
2409  return false;
2410 }
2411 
2412 /// Given a mergeable constant with the specified size and relocation
2413 /// information, return a section that it should be placed in.
2415  const DataLayout &DL, SectionKind Kind, const Constant *C,
2416  Align &Alignment) const {
2417  //TODO: Enable emiting constant pool to unique sections when we support it.
2418  return ReadOnlySection;
2419 }
2420 
2422  const TargetMachine &TgtM) {
2424  TTypeEncoding =
2428  PersonalityEncoding = 0;
2429  LSDAEncoding = 0;
2431 }
2432 
2434  unsigned Priority, const MCSymbol *KeySym) const {
2435  report_fatal_error("no static constructor section on AIX");
2436 }
2437 
2439  unsigned Priority, const MCSymbol *KeySym) const {
2440  report_fatal_error("no static destructor section on AIX");
2441 }
2442 
2444  const GlobalValue *LHS, const GlobalValue *RHS,
2445  const TargetMachine &TM) const {
2446  report_fatal_error("XCOFF not yet implemented.");
2447 }
2448 
2451  assert(!isa<GlobalIFunc>(GV) && "GlobalIFunc is not supported on AIX.");
2452 
2453  switch (GV->getLinkage()) {
2456  return XCOFF::C_HIDEXT;
2460  return XCOFF::C_EXT;
2466  return XCOFF::C_WEAKEXT;
2469  "There is no mapping that implements AppendingLinkage for XCOFF.");
2470  }
2471  llvm_unreachable("Unknown linkage type!");
2472 }
2473 
2475  const GlobalValue *Func, const TargetMachine &TM) const {
2476  assert(
2477  (isa<Function>(Func) ||
2478  (isa<GlobalAlias>(Func) &&
2479  isa_and_nonnull<Function>(cast<GlobalAlias>(Func)->getBaseObject()))) &&
2480  "Func must be a function or an alias which has a function as base "
2481  "object.");
2482 
2483  SmallString<128> NameStr;
2484  NameStr.push_back('.');
2485  getNameWithPrefix(NameStr, Func, TM);
2486 
2487  // When -function-sections is enabled and explicit section is not specified,
2488  // it's not necessary to emit function entry point label any more. We will use
2489  // function entry point csect instead. And for function delcarations, the
2490  // undefined symbols gets treated as csect with XTY_ER property.
2491  if (((TM.getFunctionSections() && !Func->hasSection()) ||
2492  Func->isDeclaration()) &&
2493  isa<Function>(Func)) {
2494  return getContext()
2495  .getXCOFFSection(
2496  NameStr, SectionKind::getText(),
2497  XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclaration()
2498  ? XCOFF::XTY_ER
2499  : XCOFF::XTY_SD))
2500  ->getQualNameSymbol();
2501  }
2502 
2503  return getContext().getOrCreateSymbol(NameStr);
2504 }
2505 
2507  const Function *F, const TargetMachine &TM) const {
2508  SmallString<128> NameStr;
2509  getNameWithPrefix(NameStr, F, TM);
2510  return getContext().getXCOFFSection(
2511  NameStr, SectionKind::getData(),
2513 }
2514 
2516  const MCSymbol *Sym, const TargetMachine &TM) const {
2517  // Use TE storage-mapping class when large code model is enabled so that
2518  // the chance of needing -bbigtoc is decreased.
2519  return getContext().getXCOFFSection(
2520  cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
2523  XCOFF::XTY_SD));
2524 }
2525 
2526 //===----------------------------------------------------------------------===//
2527 // GOFF
2528 //===----------------------------------------------------------------------===//
2531 
2533  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2534  return SelectSectionForGlobal(GO, Kind, TM);
2535 }
2536 
2538  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2539  auto *Symbol = TM.getSymbol(GO);
2540  if (Kind.isBSS())
2541  return getContext().getGOFFSection(Symbol->getName(),
2543 
2545 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCObjectFileInfo::TextCoalSection
MCSection * TextCoalSection
Definition: MCObjectFileInfo.h:202
llvm::SectionKind::isText
bool isText() const
Definition: SectionKind.h:121
llvm::MCObjectFileInfo::ConstTextCoalSection
MCSection * ConstTextCoalSection
Definition: MCObjectFileInfo.h:203
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:74
llvm::TargetLoweringObjectFile::StaticDtorSection
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
Definition: TargetLoweringObjectFile.h:64
llvm::SectionKind::isWriteable
bool isWriteable() const
Definition: SectionKind.h:147
llvm::COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition: COFF.h:410
llvm::TargetLoweringObjectFileELF::getSectionForLSDA
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:921
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:427
llvm::DK_Lowering
@ DK_Lowering
Definition: DiagnosticInfo.h:60
MachineModuleInfoImpls.h
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::XCOFF::XTY_ER
@ XTY_ER
External reference.
Definition: XCOFF.h:184
llvm::SectionKind::isThreadLocal
bool isThreadLocal() const
Definition: SectionKind.h:151
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
getCOFFStaticStructorSection
static MCSectionCOFF * getCOFFStaticStructorSection(MCContext &Ctx, const Triple &T, bool IsCtor, unsigned Priority, const MCSymbol *KeySym, MCSectionCOFF *Default)
Definition: TargetLoweringObjectFileImpl.cpp:1848
calcUniqueIDUpdateFlagsAndSize
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 ...
Definition: TargetLoweringObjectFileImpl.cpp:660
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: COFF.h:290
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::dwarf::DW_EH_PE_sdata4
@ DW_EH_PE_sdata4
Definition: Dwarf.h:440
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::Triple::GNUILP32
@ GNUILP32
Definition: Triple.h:213
Comdat.h
selectELFSectionForGlobal
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol)
Definition: TargetLoweringObjectFileImpl.cpp:812
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1386
llvm::SectionKind::getMetadata
static SectionKind getMetadata()
Definition: SectionKind.h:182
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition: GlobalValue.h:449
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::TargetLoweringObjectFileELF::TargetLoweringObjectFileELF
TargetLoweringObjectFileELF()
Definition: TargetLoweringObjectFileImpl.cpp:111
llvm::MCObjectFileInfo::EightByteConstantSection
MCSection * EightByteConstantSection
Definition: MCObjectFileInfo.h:210
llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:871
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:50
print
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Definition: ArchiveWriter.cpp:147
Metadata.h
llvm::TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel
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.
Definition: TargetLoweringObjectFileImpl.cpp:1402
llvm::TargetLoweringObjectFile::getNameWithPrefix
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
Definition: TargetLoweringObjectFile.cpp:433
llvm::DataLayout::getPreferredAlign
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:901
llvm::Comdat::ExactMatch
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:35
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition: MachineModuleInfo.h:167
llvm::GlobalValue::hasExternalLinkage
bool hasExternalLinkage() const
Definition: GlobalValue.h:431
llvm::BBSectionsColdTextPrefix
cl::opt< std::string > BBSectionsColdTextPrefix
llvm::TargetMachine::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames() const
Return true if unique basic block section names must be generated.
Definition: TargetMachine.h:264
llvm::MCObjectFileInfo::MergeableConst16Section
MCSection * MergeableConst16Section
Definition: MCObjectFileInfo.h:185
llvm::MCAsmInfo::useIntegratedAssembler
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:814
llvm::MCObjectFileInfo::ReadOnlySection
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
Definition: MCObjectFileInfo.h:67
llvm::TargetLoweringObjectFileXCOFF::getSectionForTOCEntry
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.
Definition: TargetLoweringObjectFileImpl.cpp:2515
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
getELFSectionType
static unsigned getELFSectionType(StringRef Name, SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:481
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:461
llvm::COFF::IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition: COFF.h:407
llvm::XCOFF::XMC_TD
@ XMC_TD
Scalar data item in the TOC.
Definition: XCOFF.h:63
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
getELFSectionNameForGlobal
static SmallString< 128 > getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, unsigned EntrySize, bool UniqueSectionName)
Definition: TargetLoweringObjectFileImpl.cpp:607
llvm::Function
Definition: Function.h:61
llvm::SectionKind::isReadOnly
bool isReadOnly() const
Definition: SectionKind.h:125
llvm::TargetLoweringObjectFileELF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:1062
llvm::MCStreamer::emitELFSize
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition: MCStreamer.cpp:1178
StringRef.h
llvm::SectionKind::isBSS
bool isBSS() const
Definition: SectionKind.h:163
llvm::TargetLoweringObjectFileELF::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
Definition: TargetLoweringObjectFileImpl.cpp:306
llvm::MCSA_ELF_TypeObject
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition: MCDirectives.h:25
llvm::SectionKind::isThreadBSS
bool isThreadBSS() const
Definition: SectionKind.h:155
llvm::MCStreamer::emitInt64
void emitInt64(uint64_t Value)
Definition: MCStreamer.h:706
llvm::Triple::x86
@ x86
Definition: Triple.h:83
llvm::XCOFF::XMC_TE
@ XMC_TE
Symbol mapped at the end of TOC.
Definition: XCOFF.h:71
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:623
llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase
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...
Definition: TargetLoweringObjectFile.cpp:129
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:112
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1020
llvm::TargetLoweringObjectFileELF::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:805
llvm::CodeModel::Medium
@ Medium
Definition: CodeGen.h:28
MCSectionELF.h
llvm::Comdat::NoDeduplicate
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:37
llvm::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:703
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::MCObjectFileInfo::SixteenByteConstantSection
MCSection * SixteenByteConstantSection
Definition: MCObjectFileInfo.h:211
llvm::MCObjectFileInfo::FourByteConstantSection
MCSection * FourByteConstantSection
Definition: MCObjectFileInfo.h:209
llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_MEM_DISCARDABLE
Definition: COFF.h:316
llvm::TargetLoweringObjectFileMachO::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1267
llvm::TargetLoweringObjectFileWasm::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:2040
ErrorHandling.h
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:733
MCSectionCOFF.h
llvm::TargetLoweringObjectFile::SectionForGlobal
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...
Definition: TargetLoweringObjectFile.cpp:316
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::GlobalObject::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1197
llvm::TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO
TargetLoweringObjectFileMachO()
Definition: TargetLoweringObjectFileImpl.cpp:1139
llvm::XCOFF::XMC_PR
@ XMC_PR
Program Code.
Definition: XCOFF.h:48
llvm::dwarf::DW_EH_PE_sdata8
@ DW_EH_PE_sdata8
Definition: Dwarf.h:441
llvm::MachineFunction::getFunctionNumber
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
Definition: MachineFunction.h:597
checkMachOComdat
static void checkMachOComdat(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:1211
llvm::MCObjectFileInfo::DataBSSSection
MCSection * DataBSSSection
Definition: MCObjectFileInfo.h:208
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
MachineBasicBlock.h
COFF.h
llvm::TargetLoweringObjectFileELF::InitializeELF
void InitializeELF(bool UseInitArray_)
Definition: TargetLoweringObjectFileImpl.cpp:1117
llvm::MachineModuleInfoImpl::StubValueTy
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
Definition: MachineModuleInfo.h:62
llvm::XCOFF::XMC_UA
@ XMC_UA
Unclassified - Treated as Read Write.
Definition: XCOFF.h:65
llvm::TargetLoweringObjectFileXCOFF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2391
llvm::ELF::SHT_INIT_ARRAY
@ SHT_INIT_ARRAY
Definition: ELF.h:921
llvm::TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2203
llvm::TargetMachine::getRelocationModel
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
Definition: TargetMachine.cpp:70
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1581
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:991
Module.h
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:705
llvm::XCOFF::XMC_TC
@ XMC_TC
General TOC item.
Definition: XCOFF.h:62
llvm::TargetMachine::getUniqueSectionNames
bool getUniqueSectionNames() const
Definition: TargetMachine.h:261
llvm::GlobalValue::hasSection
bool hasSection() const
Definition: GlobalValue.h:267
llvm::Triple::ppc
@ ppc
Definition: Triple.h:67
llvm::SectionKind::isMergeableConst
bool isMergeableConst() const
Definition: SectionKind.h:138
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:411
llvm::Optional
Definition: APInt.h:33
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::Triple::hexagon
@ hexagon
Definition: Triple.h:60
llvm::MCStreamer::AddBlankLine
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:361
GlobalObject.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Comdat::Largest
@ Largest
The linker will choose the largest COMDAT.
Definition: Comdat.h:36
llvm::MCObjectFileInfo::ConstDataCoalSection
MCSection * ConstDataCoalSection
Definition: MCObjectFileInfo.h:206
llvm::MCStreamer::emitLinkerOptions
virtual void emitLinkerOptions(ArrayRef< std::string > Kind)
Emit the given list Options of strings as linker options into the output.
Definition: MCStreamer.h:481
llvm::MachineModuleInfoMachO::getGVStubEntry
StubValueTy & getGVStubEntry(MCSymbol *Sym)
Definition: MachineModuleInfoImpls.h:44
llvm::TargetLoweringObjectFile::StaticCtorSection
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
Definition: TargetLoweringObjectFile.h:61
llvm::TargetLoweringObjectFileXCOFF::getSectionForExternalReference
MCSection * getSectionForExternalReference(const GlobalObject *GO, const TargetMachine &TM) const override
For external functions, this will always return a function descriptor csect.
Definition: TargetLoweringObjectFileImpl.cpp:2275
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::Mangler
Definition: Mangler.h:27
llvm::Triple::aarch64_32
@ aarch64_32
Definition: Triple.h:54
llvm::TargetLoweringObjectFileMachO::getTTypeGlobalReference
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.
Definition: TargetLoweringObjectFileImpl.cpp:1354
llvm::TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock
static bool ShouldEmitEHBlock(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2173
Format.h
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:232
getELFKindForNamedSection
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:438
llvm::Triple::mips64
@ mips64
Definition: Triple.h:64
llvm::TargetLoweringObjectFileELF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:906
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition: ELF.h:916
llvm::MachO::S_MOD_TERM_FUNC_POINTERS
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition: MachO.h:148
llvm::MCContext::isELFImplicitMergeableSectionNamePrefix
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:601
llvm::TargetLoweringObjectFile::CallSiteEncoding
unsigned CallSiteEncoding
Definition: TargetLoweringObjectFile.h:58
llvm::ELF::SHF_LINK_ORDER
@ SHF_LINK_ORDER
Definition: ELF.h:1003
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::collectUsedGlobalVariables
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:778
llvm::XCOFF::CsectProperties
Definition: XCOFF.h:412
llvm::MCContext::getMachOSection
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.
Definition: MCContext.cpp:420
llvm::MachineBasicBlock::isBeginSection
bool isBeginSection() const
Returns true if this block begins any section.
Definition: MachineBasicBlock.h:564
llvm::MCSymbolELF
Definition: MCSymbolELF.h:14
llvm::TargetLoweringObjectFile
Definition: TargetLoweringObjectFile.h:43
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:910
llvm::TargetLoweringObjectFileCOFF::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1697
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition: EHPersonalities.cpp:21
llvm::TargetLoweringObjectFileXCOFF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:2421
llvm::SectionKind::getReadOnly
static SectionKind getReadOnly()
Definition: SectionKind.h:185
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:60
llvm::TargetLoweringObjectFileXCOFF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:2433
getELFSectionFlags
static unsigned getELFSectionFlags(SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:503
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::MCObjectFileInfo::LSDASection
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
Definition: MCObjectFileInfo.h:71
llvm::TargetLoweringObjectFileMachO::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition: TargetLoweringObjectFileImpl.cpp:1337
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:289
llvm::Triple::sparc
@ sparc
Definition: Triple.h:75
llvm::MCContext::getOrCreateSymbol
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:191
llvm::TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition: TargetLoweringObjectFileImpl.cpp:956
GlobalValue.h
llvm::Triple::sparcv9
@ sparcv9
Definition: Triple.h:76
llvm::SectionKind::getThreadBSS
static SectionKind getThreadBSS()
Definition: SectionKind.h:199
llvm::Triple::sparcel
@ sparcel
Definition: Triple.h:77
ELF.h
llvm::TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:2245
llvm::ELF::SHF_TLS
@ SHF_TLS
Definition: ELF.h:1013
TargetMachine.h
llvm::XCOFF::XMC_RO
@ XMC_RO
Read Only Constant.
Definition: XCOFF.h:49
llvm::MCContext::isELFGenericMergeableSection
bool isELFGenericMergeableSection(StringRef Name)
Definition: MCContext.cpp:606
llvm::dwarf::DW_EH_PE_indirect
@ DW_EH_PE_indirect
Definition: Dwarf.h:448
Constants.h
llvm::ELF::SHF_GNU_RETAIN
@ SHF_GNU_RETAIN
Definition: ELF.h:1019
llvm::COFF::IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition: COFF.h:409
llvm::TargetLoweringObjectFileELF::PLTRelativeVariantKind
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
Definition: TargetLoweringObjectFileImpl.h:39
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::TargetLoweringObjectFileWasm::InitializeWasm
void InitializeWasm()
Definition: TargetLoweringObjectFileImpl.cpp:2147
llvm::MCSectionWasm
This represents a section on wasm.
Definition: MCSectionWasm.h:26
llvm::TargetLoweringObjectFileWasm::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:2156
llvm::TargetOptions::UseInitArray
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Definition: TargetOptions.h:224
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::TargetLoweringObjectFileELF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1074
scalarConstantToHexString
static std::string scalarConstantToHexString(const Constant *C)
Definition: TargetLoweringObjectFileImpl.cpp:1942
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
llvm::MCObjectFileInfo::MergeableConst8Section
MCSection * MergeableConst8Section
Definition: MCObjectFileInfo.h:184
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:65
llvm::TargetMachine::getFunctionSections
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
Definition: TargetMachine.h:276
llvm::GlobalObject
Definition: GlobalObject.h:28
MCSymbolELF.h
MCContext.h
llvm::MCSectionMachO::ParseSectionSpecifier
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
Definition: MCSectionMachO.cpp:177
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:321
MCSectionMachO.h
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:413
MCSymbol.h
llvm::TargetLoweringObjectFileXCOFF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:2438
llvm::MCStreamer::emitSymbolValue
void emitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition: MCStreamer.cpp:179
llvm::MCObjectFileInfo::isPositionIndependent
bool isPositionIndependent() const
Definition: MCObjectFileInfo.h:420
llvm::MCContext::getGOFFSection
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind)
Definition: MCContext.cpp:619
llvm::GlobalValue::hasPrivateLinkage
bool hasPrivateLinkage() const
Definition: GlobalValue.h:444
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::ELF::SHT_LLVM_LINKER_OPTIONS
@ SHT_LLVM_LINKER_OPTIONS
Definition: ELF.h:935
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition: PseudoProbe.h:26
llvm::SectionKind::getBSS
static SectionKind getBSS()
Definition: SectionKind.h:202
llvm::Comdat::Any
@ Any
The linker may choose any COMDAT.
Definition: Comdat.h:34
llvm::Mangler::getNameWithPrefix
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:114
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:28
llvm::Triple::ppc64
@ ppc64
Definition: Triple.h:69
llvm::TargetLoweringObjectFileELF::getModuleMetadata
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
Definition: TargetLoweringObjectFileImpl.cpp:298
GetObjCImageInfo
static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags, StringRef &Section)
Definition: TargetLoweringObjectFileImpl.cpp:73
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: DiagnosticInfo.h:44
llvm::TargetLoweringObjectFileMachO::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1491
InstrProf.h
llvm::isNoOpWithoutInvoke
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
Definition: EHPersonalities.h:96
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::MCContext::getXCOFFSection
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, Optional< XCOFF::CsectProperties > CsectProp=None, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, Optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=None)
Definition: MCContext.cpp:735
llvm::TargetLoweringObjectFileXCOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2294
llvm::TargetLoweringObjectFile::emitCGProfileMetadata
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const
Emit Call Graph Profile metadata.
Definition: TargetLoweringObjectFile.cpp:151
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:397
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::TargetLoweringObjectFile::Initialize
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFile.cpp:42
llvm::Comdat::SameSize
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:38
llvm::MCSA_Hidden
@ MCSA_Hidden
.hidden (ELF)
Definition: MCDirectives.h:33
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::Triple::lanai
@ lanai
Definition: Triple.h:98
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
isThumb
static bool isThumb(const MCSubtargetInfo &STI)
Definition: ARMAsmPrinter.cpp:470
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition: DiagnosticInfo.h:101
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:219
llvm::GlobalValue::hasGlobalUnnamedAddr
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:196
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::SectionKind::getText
static SectionKind getText()
Definition: SectionKind.h:183
llvm::XCOFF::XTY_SD
@ XTY_SD
Csect definition for initialized storage.
Definition: XCOFF.h:185
llvm::DiagnosticPrinter
Interface for custom diagnostic printing.
Definition: DiagnosticPrinter.h:31
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Comdat
Definition: Comdat.h:31
llvm::TargetLoweringObjectFileXCOFF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition: TargetLoweringObjectFileImpl.cpp:2414
llvm::Triple::getArch
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:307
llvm::MCObjectFileInfo::TLSDataSection
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
Definition: MCObjectFileInfo.h:153
llvm::Type::isFunctionTy
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:219
llvm::MCObjectFileInfo::getTextSection
MCSection * getTextSection() const
Definition: MCObjectFileInfo.h:254
llvm::TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor
MCSection * getSectionForFunctionDescriptor(const Function *F, const TargetMachine &TM) const override
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
Definition: TargetLoweringObjectFileImpl.cpp:2506
MCSectionXCOFF.h
llvm::MCContext::getAssociativeCOFFSection
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
Definition: MCContext.cpp:668
getLinkedToSymbol
static const MCSymbolELF * getLinkedToSymbol(const GlobalObject *GO, const TargetMachine &TM)
Definition: TargetLoweringObjectFileImpl.cpp:544
llvm::Attribute::getValueAsString
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:301
llvm::MCObjectFileInfo::ConstDataSection
MCSection * ConstDataSection
Definition: MCObjectFileInfo.h:204
llvm::MCContext::getWasmSection
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition: MCContext.h:621
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::TargetLoweringObjectFile::getKindForGlobal
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Definition: TargetLoweringObjectFile.cpp:202
getCOFFSectionNameForUniqueGlobal
static StringRef getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
Definition: TargetLoweringObjectFileImpl.cpp:1614
Type.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::TargetLoweringObjectFileELF::emitPersonalityValue
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const override
Definition: TargetLoweringObjectFileImpl.cpp:391
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:46
llvm::wasm::WASM_SEG_FLAG_TLS
@ WASM_SEG_FLAG_TLS
Definition: Wasm.h:362
llvm::SmallString< 64 >
llvm::XCOFF::C_EXT
@ C_EXT
Definition: XCOFF.h:141
llvm::dwarf::DW_EH_PE_udata4
@ DW_EH_PE_udata4
Definition: Dwarf.h:436
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition: TargetLoweringObjectFile.h:66
llvm::TargetLoweringObjectFileCOFF::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
Definition: TargetLoweringObjectFileImpl.cpp:1736
getCOFFSectionFlags
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
Definition: TargetLoweringObjectFileImpl.cpp:1509
llvm::CodeModel::Model
Model
Definition: CodeGen.h:28
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1102
llvm::PointerIntPair::getPointer
PointerTy getPointer() const
Definition: PointerIntPair.h:59
llvm::MachineFunction::getMMI
MachineModuleInfo & getMMI() const
Definition: MachineFunction.h:573
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:70
llvm::SectionKind::isThreadBSSLocal
bool isThreadBSSLocal() const
Definition: SectionKind.h:157
llvm::XCOFF::StorageClass
StorageClass
Definition: XCOFF.h:113
llvm::TargetLoweringObjectFileWasm::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:2164
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:104
llvm::MCAsmInfo::isSectionAtomizableBySymbols
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:90
llvm::Triple::ELF
@ ELF
Definition: Triple.h:235
llvm::TargetLoweringObjectFile::SupportIndirectSymViaGOTPCRel
bool SupportIndirectSymViaGOTPCRel
Definition: TargetLoweringObjectFile.h:48
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::dwarf::DW_EH_PE_udata8
@ DW_EH_PE_udata8
Definition: Dwarf.h:437
llvm::GlobalValue::isWeakForLinker
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:378
llvm::MachO::S_MOD_INIT_FUNC_POINTERS
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition: MachO.h:145
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition: Dwarf.h:443
getEntrySizeForKind
static unsigned getEntrySizeForKind(SectionKind Kind)
Definition: TargetLoweringObjectFileImpl.cpp:562
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:423
llvm::MCObjectFileInfo::UStringSection
MCSection * UStringSection
Definition: MCObjectFileInfo.h:201
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:572
llvm::SectionKind::isMetadata
bool isMetadata() const
Definition: SectionKind.h:119
llvm::TargetLoweringObjectFile::getPersonalityEncoding
unsigned getPersonalityEncoding() const
Definition: TargetLoweringObjectFile.h:166
llvm::XCOFF::XTY_CM
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:188
llvm::Triple::isOSFreeBSD
bool isOSFreeBSD() const
Definition: Triple.h:510
llvm::MCObjectFileInfo::CStringSection
MCSection * CStringSection
Definition: MCObjectFileInfo.h:200
llvm::GlobalVariable::hasImplicitSection
bool hasImplicitSection() const
Check if section name is present.
Definition: GlobalVariable.h:243
llvm::Triple::isArch32Bit
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1340
llvm::XCOFF::XMC_TL
@ XMC_TL
Initialized thread-local variable.
Definition: XCOFF.h:69
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
llvm::ELF::SHT_PREINIT_ARRAY
@ SHT_PREINIT_ARRAY
Definition: ELF.h:923
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DSOLocalEquivalent::getGlobalValue
GlobalValue * getGlobalValue() const
Definition: Constants.h:913
BasicBlockSectionUtils.h
MCSectionGOFF.h
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:985
llvm::TargetLoweringObjectFileWasm::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition: TargetLoweringObjectFileImpl.cpp:2120
I
#define I(x, y, z)
Definition: MD5.cpp:59
StringExtras.h
llvm::TargetLoweringObjectFileMachO::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:1144
llvm::SectionKind::isMergeableCString
bool isMergeableCString() const
Definition: SectionKind.h:130
llvm::XCOFF::C_HIDEXT
@ C_HIDEXT
Definition: XCOFF.h:149
llvm::TargetLoweringObjectFileXCOFF::getTargetSymbol
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
Definition: TargetLoweringObjectFileImpl.cpp:2209
llvm::MCSection::NonUniqueID
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:541
llvm::MBBSectionID::ExceptionSectionID
const static MBBSectionID ExceptionSectionID
Definition: MachineBasicBlock.h:65
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:115
llvm::TargetLoweringObjectFile::getTTypeReference
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: TargetLoweringObjectFile.cpp:408
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::MCSectionCOFF
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
llvm::Type::getArrayNumElements
uint64_t getArrayNumElements() const
Definition: DerivedTypes.h:383
llvm::TargetLoweringObjectFileGOFF::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:2532
llvm::ELF::SHF_ARM_PURECODE
@ SHF_ARM_PURECODE
Definition: ELF.h:1080
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:608
llvm::COFF::IMAGE_SCN_LNK_COMDAT
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:294
llvm::TargetLoweringObjectFile::supportDSOLocalEquivalentLowering
bool supportDSOLocalEquivalentLowering() const
Target supports a native lowering of a dso_local_equivalent constant without needing to replace it wi...
Definition: TargetLoweringObjectFile.h:196
llvm::GlobalValue::isThreadLocal
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition: GlobalValue.h:244
llvm::MachineFunction::getLandingPads
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Definition: MachineFunction.h:1057
PreferPredicateTy::Option
Option
Definition: LoopVectorize.cpp:213
llvm::Function::hasAttribute
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:444
MachineModuleInfo.h
APIntToHexString
static std::string APIntToHexString(const APInt &AI)
Definition: TargetLoweringObjectFileImpl.cpp:1931
llvm::TargetLoweringObjectFileMachO::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit the module flags that specify the garbage collection information.
Definition: TargetLoweringObjectFileImpl.cpp:1168
llvm::SectionKind::getThreadData
static SectionKind getThreadData()
Definition: SectionKind.h:200
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::TargetLoweringObjectFileELF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition: TargetLoweringObjectFileImpl.cpp:965
llvm::TargetLoweringObjectFileELF::lowerDSOLocalEquivalent
const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1094
llvm::Triple::armeb
@ armeb
Definition: Triple.h:51
llvm::COFF::IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_LARGEST
Definition: COFF.h:412
llvm::GlobalObject::hasComdat
bool hasComdat() const
Definition: GlobalObject.h:122
llvm::TargetLoweringObjectFileWasm::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2101
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::TargetLoweringObjectFileCOFF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:1822
llvm::TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol
MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const override
If supported, return the function entry point symbol.
Definition: TargetLoweringObjectFileImpl.cpp:2474
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:54
Mangler.h
Triple.h
llvm::dwarf::DW_EH_PE_datarel
@ DW_EH_PE_datarel
Definition: Dwarf.h:445
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:523
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition: TargetMachine.h:202
llvm::TargetLoweringObjectFile::getMangler
Mangler & getMangler() const
Definition: TargetLoweringObjectFile.h:75
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:988
llvm::MachineModuleInfoELF::getGVStubEntry
StubValueTy & getGVStubEntry(MCSymbol *Sym)
Definition: MachineModuleInfoImpls.h:73
llvm::TargetLoweringObjectFileELF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:1068
llvm::Triple::arm
@ arm
Definition: Triple.h:50
MCAsmInfo.h
DataLayout.h
llvm::Triple::aarch64_be
@ aarch64_be
Definition: Triple.h:53
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Dwarf.h
llvm::TargetLoweringObjectFileELF::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition: TargetLoweringObjectFileImpl.cpp:379
llvm::Triple::ppcle
@ ppcle
Definition: Triple.h:68
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::transform
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:1644
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
llvm::GlobalValue::WeakODRLinkage
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:53
getSelectionForCOFF
static int getSelectionForCOFF(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:1562
llvm::XCOFF::C_WEAKEXT
@ C_WEAKEXT
Definition: XCOFF.h:142
canUsePrivateLabel
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
Definition: TargetLoweringObjectFileImpl.cpp:1479
llvm::Triple::thumb
@ thumb
Definition: Triple.h:81
llvm::MCObjectFileInfo::getDrectveSection
MCSection * getDrectveSection() const
Definition: MCObjectFileInfo.h:406
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:979
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::emitLinkerFlagsForUsedCOFF
void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
Definition: Mangler.cpp:242
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
llvm::MCContext::getCOFFSection
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:628
getSectionPrefixForGlobal
static StringRef getSectionPrefixForGlobal(SectionKind Kind)
Return the section prefix name used by options FunctionsSections and DataSections.
Definition: TargetLoweringObjectFileImpl.cpp:588
getWasmComdat
static const Comdat * getWasmComdat(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:2013
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:273
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:297
llvm::TargetLoweringObjectFileELF::getUniqueSectionForFunction
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:890
llvm::Module::getSourceFileName
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition: Module.h:238
llvm::GlobalValue::CommonLinkage
@ CommonLinkage
Tentative definitions.
Definition: GlobalValue.h:58
llvm::ELF::SHF_STRINGS
@ SHF_STRINGS
Definition: ELF.h:997
llvm::MachineBasicBlock::getSectionID
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
Definition: MachineBasicBlock.h:574
llvm::MCContext::GenericSectionID
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:523
llvm::ELF::SHF_MERGE
@ SHF_MERGE
Definition: ELF.h:994
llvm::SectionKind::isBSSLocal
bool isBSSLocal() const
Definition: SectionKind.h:164
llvm::TargetLoweringObjectFile::PersonalityEncoding
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
Definition: TargetLoweringObjectFile.h:55
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:122
llvm::MachineFunction::getSection
MCSection * getSection() const
Returns the Section this function belongs to.
Definition: MachineFunction.h:577
llvm::APInt::getNullValue
static APInt getNullValue(unsigned numBits)
Get the '0' value.
Definition: APInt.h:574
llvm::MCObjectFileInfo::DataRelROSection
MCSection * DataRelROSection
Definition: MCObjectFileInfo.h:182
llvm::SectionKind::getData
static SectionKind getData()
Definition: SectionKind.h:206
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
selectExplicitSectionGlobal
static MCSection * selectExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID, bool Retain, bool ForceUnique)
Definition: TargetLoweringObjectFileImpl.cpp:732
llvm::TargetLoweringObjectFileMachO::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition: TargetLoweringObjectFileImpl.cpp:1382
llvm::dwarf::DW_EH_PE_absptr
@ DW_EH_PE_absptr
Definition: Dwarf.h:432
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:228
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:588
llvm::ELF::SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition: ELF.h:938
llvm::TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF
TargetLoweringObjectFileGOFF()
Definition: TargetLoweringObjectFileImpl.cpp:2529
llvm::MCStreamer::emitSymbolAttribute
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::MCObjectFileInfo::DataSection
MCSection * DataSection
Section directive for standard data.
Definition: MCObjectFileInfo.h:58
llvm::MBBSectionID::ColdSectionID
const static MBBSectionID ColdSectionID
Definition: MachineBasicBlock.h:64
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::DataLayout::getPrivateGlobalPrefix
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:330
llvm::MCObjectFileInfo::MergeableConst32Section
MCSection * MergeableConst32Section
Definition: MCObjectFileInfo.h:186
llvm::SectionName
Definition: DWARFSection.h:21
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
GlobalVariable.h
llvm::MCSectionMachO
This represents a section on a Mach-O system (used by Mac OS X).
Definition: MCSectionMachO.h:24
llvm::COFF::IMAGE_SCN_CNT_CODE
@ IMAGE_SCN_CNT_CODE
Definition: COFF.h:288
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition: Globals.cpp:172
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:73
Casting.h
DiagnosticInfo.h
Function.h
llvm::TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB
static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2191
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:63
llvm::TargetLoweringObjectFileELF::getSectionForCommandLines
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
Definition: TargetLoweringObjectFileImpl.cpp:1108
llvm::TargetLoweringObjectFileMachO::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:1220
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:116
llvm::TargetMachine::getCodeModel
CodeModel::Model getCodeModel() const
Returns the code model.
Definition: TargetMachine.cpp:74
DP
So we should use XX3Form_Rcr to implement instrinsic Convert DP outs ins xscvdpsp No builtin are required Round &Convert QP DP(dword[1] is set to zero) No builtin are required Round to Quad Precision because you need to assign rounding mode in instruction Provide builtin(set f128:$vT,(int_ppc_vsx_xsrqpi f128:$vB))(set f128 yields< n x< ty > >< result > yields< ty >< result > No builtin are required Load Store load store see def memrix16 in PPCInstrInfo td Load Store Vector load store outs ins lxsdx set load store with conversion from to DP
Definition: README_P9.txt:520
llvm::MCSymbolRefExpr::VK_COFF_IMGREL32
@ VK_COFF_IMGREL32
Definition: MCExpr.h:315
PseudoProbe.h
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:384
llvm::GlobalVariable::getAttributes
AttributeSet getAttributes() const
Return the attribute set for this global.
Definition: GlobalVariable.h:223
llvm::Module::Require
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Module.h:133
llvm::TargetLoweringObjectFileCOFF::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:1587
Wasm.h
llvm::GlobalValue::getBaseObject
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:283
llvm::Triple::systemz
@ systemz
Definition: Triple.h:78
MCValue.h
SectionKind.h
GlobalAlias.h
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:403
llvm::TargetLoweringObjectFile::getSectionForConstant
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const
Given a constant with the SectionKind, return a section that it should be placed in.
Definition: TargetLoweringObjectFile.cpp:375
llvm::XCOFF::XMC_DS
@ XMC_DS
Descriptor csect.
Definition: XCOFF.h:64
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
Selection
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
Definition: AMDGPUISelDAGToDAG.cpp:380
llvm::MCAsmInfo::binutilsIsAtLeast
bool binutilsIsAtLeast(int Major, int Minor) const
Definition: MCAsmInfo.h:821
llvm::getInstrProfSectionName
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
Definition: InstrProf.cpp:175
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
CodeGen.h
llvm::MCAsmInfo::getExceptionHandlingType
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:762
llvm::ELF::SHT_FINI_ARRAY
@ SHT_FINI_ARRAY
Definition: ELF.h:922
llvm::MCObjectFileInfo::DataCoalSection
MCSection * DataCoalSection
Definition: MCObjectFileInfo.h:205
llvm::CodeModel::Large
@ Large
Definition: CodeGen.h:28
llvm::MCSA_Weak
@ MCSA_Weak
.weak
Definition: MCDirectives.h:44
llvm::TargetLoweringObjectFile::LSDAEncoding
unsigned LSDAEncoding
Definition: TargetLoweringObjectFile.h:56
llvm::TargetLoweringObjectFileXCOFF::getStorageClassForGlobal
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:2450
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::MCStreamer::emitULEB128IntValue
void emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:159
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:45
SmallVector.h
llvm::emitLinkerFlagsForGlobalCOFF
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
Definition: Mangler.cpp:206
llvm::TargetLoweringObjectFileCOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1626
llvm::XCOFF::XMC_RW
@ XMC_RW
Read Write Data.
Definition: XCOFF.h:60
llvm::Triple::thumbeb
@ thumbeb
Definition: Triple.h:82
llvm::TargetLoweringObjectFileXCOFF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2443
llvm::MCSectionXCOFF::getQualNameSymbol
MCSymbolXCOFF * getQualNameSymbol() const
Definition: MCSectionXCOFF.h:102
MCStreamer.h
llvm::MCObjectFileInfo::BSSSection
MCSection * BSSSection
Section that is default initialized to zero.
Definition: MCObjectFileInfo.h:61
llvm::MCObjectFileInfo::MergeableConst4Section
MCSection * MergeableConst4Section
Definition: MCObjectFileInfo.h:183
llvm::MCContext::getELFUniqueIDForEntsize
Optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Return the unique ID of the section with the given name, flags and entry size, if it exists.
Definition: MCContext.cpp:611
Characteristics
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:326
llvm::MCObjectFileInfo::TLSBSSSection
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
Definition: MCObjectFileInfo.h:158
llvm::SectionKind::isReadOnlyWithRel
bool isReadOnlyWithRel() const
Definition: SectionKind.h:171
llvm::TargetMachine::getTargetTriple
const Triple & getTargetTriple() const
Definition: TargetMachine.h:123
llvm::MachineModuleInfoELF
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
Definition: MachineModuleInfoImpls.h:63
llvm::TargetLoweringObjectFileELF::getSectionForMachineBasicBlock
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
Definition: TargetLoweringObjectFileImpl.cpp:984
selectWasmSectionForGlobal
static MCSectionWasm * selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID)
Definition: TargetLoweringObjectFileImpl.cpp:2070
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition: GlobalValue.h:534
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:656
llvm::MCStreamer::emitValueToAlignment
virtual void emitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:1197
llvm::Function::getAttribute
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition: Function.h:459
llvm::TargetLoweringObjectFileELF::getTTypeGlobalReference
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...
Definition: TargetLoweringObjectFileImpl.cpp:413
llvm::COFF::IMAGE_SCN_MEM_EXECUTE
@ IMAGE_SCN_MEM_EXECUTE
Definition: COFF.h:320
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:1187
llvm::Triple::getEnvironment
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:325
llvm::TargetLoweringObjectFileWasm::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2127
llvm::SmallVectorImpl< char >
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:271
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:401
DerivedTypes.h
llvm::ELF::SHF_GROUP
@ SHF_GROUP
Definition: ELF.h:1010
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::TargetLoweringObjectFile::TTypeEncoding
unsigned TTypeEncoding
Definition: TargetLoweringObjectFile.h:57
getStaticStructorSection
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
Definition: TargetLoweringObjectFileImpl.cpp:1024
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::COFF::IMAGE_SCN_MEM_16BIT
@ IMAGE_SCN_MEM_16BIT
Definition: COFF.h:297
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::TargetLoweringObjectFileCOFF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
Definition: TargetLoweringObjectFileImpl.cpp:1963
MachO.h
llvm::TargetLoweringObjectFileGOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2537
llvm::TargetLoweringObjectFileCOFF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1709
llvm::MCObjectFileInfo::DataCommonSection
MCSection * DataCommonSection
Definition: MCObjectFileInfo.h:207
llvm::MCContext::getELFNamedSection
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition: MCContext.cpp:518
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
raw_ostream.h
llvm::XCOFF::XMC_UL
@ XMC_UL
Uninitialized thread-local variable.
Definition: XCOFF.h:70
llvm::TargetLoweringObjectFileCOFF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:1886
MachineFunction.h
getELFComdat
static const Comdat * getELFComdat(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:530
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:917
DiagnosticPrinter.h
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
llvm::TargetLoweringObjectFileCOFF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:1893
Priority
Definition: Inliner.cpp:727
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1209
getComdatGVForCOFF
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:1545
MCExpr.h
llvm::TargetLoweringObjectFile::SupportDSOLocalEquivalentLowering
bool SupportDSOLocalEquivalentLowering
Definition: TargetLoweringObjectFile.h:51
llvm::COFF::SectionCharacteristics
SectionCharacteristics
Definition: COFF.h:283
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:174
llvm::wasm::WASM_SEG_FLAG_STRINGS
@ WASM_SEG_FLAG_STRINGS
Definition: Wasm.h:361
llvm::TargetLoweringObjectFile::getTTypeGlobalReference
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...
Definition: TargetLoweringObjectFile.cpp:398
llvm::ELF::SHF_EXCLUDE
@ SHF_EXCLUDE
Definition: ELF.h:1022
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::DSOLocalEquivalent
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:894
llvm::Directive
Definition: DirectiveEmitter.h:100
llvm::DS_Error
@ DS_Error
Definition: DiagnosticInfo.h:45
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::SectionKind::isExecuteOnly
bool isExecuteOnly() const
Definition: SectionKind.h:123
llvm::Triple::mips
@ mips
Definition: Triple.h:62
llvm::TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition: TargetLoweringObjectFileImpl.cpp:2407
llvm::MachineModuleInfo::getObjFileInfo
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
Definition: MachineModuleInfo.h:191
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
llvm::MDOperand
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:744
getWasmSectionFlags
static unsigned getWasmSectionFlags(SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:2026
llvm::COFF::IMAGE_COMDAT_SELECT_ANY
@ IMAGE_COMDAT_SELECT_ANY
Definition: COFF.h:408
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition: COFF.h:322
llvm::XCOFF::XMC_BS
@ XMC_BS
BSS class (uninitialized static internal)
Definition: XCOFF.h:66
llvm::Module::getNamedValue
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition: Module.cpp:113
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
llvm::MachineModuleInfoMachO
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
Definition: MachineModuleInfoImpls.h:28
llvm::TargetLoweringObjectFileCOFF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1900
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:128
MCSectionWasm.h
llvm::TargetMachine::getDataSections
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections.
Definition: TargetMachine.h:270
llvm::MCObjectFileInfo::TextSection
MCSection * TextSection
Section directive for standard text.
Definition: MCObjectFileInfo.h:55
TargetLoweringObjectFileImpl.h