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  !TM.getTargetTriple().isOSSolaris())
683  Flags |= ELF::SHF_GNU_RETAIN;
684  return NextUniqueID++;
685  }
686 
687  // If two symbols with differing sizes end up in the same mergeable section
688  // that section can be assigned an incorrect entry size. To avoid this we
689  // usually put symbols of the same size into distinct mergeable sections with
690  // the same name. Doing so relies on the ",unique ," assembly feature. This
691  // feature is not avalible until bintuils version 2.35
692  // (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
693  const bool SupportsUnique = Ctx.getAsmInfo()->useIntegratedAssembler() ||
694  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35);
695  if (!SupportsUnique) {
696  Flags &= ~ELF::SHF_MERGE;
697  EntrySize = 0;
699  }
700 
701  const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
702  const bool SeenSectionNameBefore =
704  // If this is the first ocurrence of this section name, treat it as the
705  // generic section
706  if (!SymbolMergeable && !SeenSectionNameBefore)
708 
709  // Symbols must be placed into sections with compatible entry sizes. Generate
710  // unique sections for symbols that have not been assigned to compatible
711  // sections.
712  const auto PreviousID =
713  Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
714  if (PreviousID)
715  return *PreviousID;
716 
717  // If the user has specified the same section name as would be created
718  // implicitly for this symbol e.g. .rodata.str1.1, then we don't need
719  // to unique the section as the entry size for this symbol will be
720  // compatible with implicitly created sections.
721  SmallString<128> ImplicitSectionNameStem =
722  getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false);
723  if (SymbolMergeable &&
725  SectionName.startswith(ImplicitSectionNameStem))
727 
728  // We have seen this section name before, but with different flags or entity
729  // size. Create a new unique ID.
730  return NextUniqueID++;
731 }
732 
734  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
735  MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
736  bool Retain, bool ForceUnique) {
738 
739  // Check if '#pragma clang section' name is applicable.
740  // Note that pragma directive overrides -ffunction-section, -fdata-section
741  // and so section name is exactly as user specified and not uniqued.
742  const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
743  if (GV && GV->hasImplicitSection()) {
744  auto Attrs = GV->getAttributes();
745  if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) {
746  SectionName = Attrs.getAttribute("bss-section").getValueAsString();
747  } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) {
748  SectionName = Attrs.getAttribute("rodata-section").getValueAsString();
749  } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) {
750  SectionName = Attrs.getAttribute("relro-section").getValueAsString();
751  } else if (Attrs.hasAttribute("data-section") && Kind.isData()) {
752  SectionName = Attrs.getAttribute("data-section").getValueAsString();
753  }
754  }
755  const Function *F = dyn_cast<Function>(GO);
756  if (F && F->hasFnAttribute("implicit-section-name")) {
757  SectionName = F->getFnAttribute("implicit-section-name").getValueAsString();
758  }
759 
760  // Infer section flags from the section name if we can.
762 
763  StringRef Group = "";
764  bool IsComdat = false;
765  unsigned Flags = getELFSectionFlags(Kind);
766  if (const Comdat *C = getELFComdat(GO)) {
767  Group = C->getName();
768  IsComdat = C->getSelectionKind() == Comdat::Any;
769  Flags |= ELF::SHF_GROUP;
770  }
771 
772  unsigned EntrySize = getEntrySizeForKind(Kind);
773  const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize(
774  GO, SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
775  Retain, ForceUnique);
776 
777  const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
779  SectionName, getELFSectionType(SectionName, Kind), Flags, EntrySize,
780  Group, IsComdat, UniqueID, LinkedToSym);
781  // Make sure that we did not get some other section with incompatible sh_link.
782  // This should not be possible due to UniqueID code above.
783  assert(Section->getLinkedToSymbol() == LinkedToSym &&
784  "Associated symbol mismatch between sections");
785 
786  if (!(Ctx.getAsmInfo()->useIntegratedAssembler() ||
787  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35))) {
788  // If we are using GNU as before 2.35, then this symbol might have
789  // been placed in an incompatible mergeable section. Emit an error if this
790  // is the case to avoid creating broken output.
791  if ((Section->getFlags() & ELF::SHF_MERGE) &&
792  (Section->getEntrySize() != getEntrySizeForKind(Kind)))
793  GO->getContext().diagnose(LoweringDiagnosticInfo(
794  "Symbol '" + GO->getName() + "' from module '" +
795  (GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
796  "' required a section with entry-size=" +
797  Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
798  SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
799  ": Explicit assignment by pragma or attribute of an incompatible "
800  "symbol to this section?"));
801  }
802 
803  return Section;
804 }
805 
807  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
809  NextUniqueID, Used.count(GO),
810  /* ForceUnique = */false);
811 }
812 
814  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
815  const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
816  unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
817 
818  StringRef Group = "";
819  bool IsComdat = false;
820  if (const Comdat *C = getELFComdat(GO)) {
821  Flags |= ELF::SHF_GROUP;
822  Group = C->getName();
823  IsComdat = C->getSelectionKind() == Comdat::Any;
824  }
825 
826  // Get the section entry size based on the kind.
827  unsigned EntrySize = getEntrySizeForKind(Kind);
828 
829  bool UniqueSectionName = false;
830  unsigned UniqueID = MCContext::GenericSectionID;
831  if (EmitUniqueSection) {
832  if (TM.getUniqueSectionNames()) {
833  UniqueSectionName = true;
834  } else {
835  UniqueID = *NextUniqueID;
836  (*NextUniqueID)++;
837  }
838  }
840  GO, Kind, Mang, TM, EntrySize, UniqueSectionName);
841 
842  // Use 0 as the unique ID for execute-only text.
843  if (Kind.isExecuteOnly())
844  UniqueID = 0;
845  return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags,
846  EntrySize, Group, IsComdat, UniqueID,
847  AssociatedSymbol);
848 }
849 
851  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
852  const TargetMachine &TM, bool Retain, bool EmitUniqueSection,
853  unsigned Flags, unsigned *NextUniqueID) {
854  const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
855  if (LinkedToSym) {
856  EmitUniqueSection = true;
857  Flags |= ELF::SHF_LINK_ORDER;
858  }
859  if (Retain &&
861  Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
862  !TM.getTargetTriple().isOSSolaris()) {
863  EmitUniqueSection = true;
864  Flags |= ELF::SHF_GNU_RETAIN;
865  }
866 
868  Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
869  NextUniqueID, LinkedToSym);
870  assert(Section->getLinkedToSymbol() == LinkedToSym);
871  return Section;
872 }
873 
875  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
876  unsigned Flags = getELFSectionFlags(Kind);
877 
878  // If we have -ffunction-section or -fdata-section then we should emit the
879  // global value to a uniqued section specifically for it.
880  bool EmitUniqueSection = false;
881  if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
882  if (Kind.isText())
883  EmitUniqueSection = TM.getFunctionSections();
884  else
885  EmitUniqueSection = TM.getDataSections();
886  }
887  EmitUniqueSection |= GO->hasComdat();
889  Used.count(GO), EmitUniqueSection, Flags,
890  &NextUniqueID);
891 }
892 
894  const Function &F, const TargetMachine &TM) const {
896  unsigned Flags = getELFSectionFlags(Kind);
897  // If the function's section names is pre-determined via pragma or a
898  // section attribute, call selectExplicitSectionGlobal.
899  if (F.hasSection() || F.hasFnAttribute("implicit-section-name"))
901  &F, Kind, TM, getContext(), getMangler(), NextUniqueID,
902  Used.count(&F), /* ForceUnique = */true);
903  else
905  getContext(), &F, Kind, getMangler(), TM, Used.count(&F),
906  /*EmitUniqueSection=*/true, Flags, &NextUniqueID);
907 }
908 
910  const Function &F, const TargetMachine &TM) const {
911  // If the function can be removed, produce a unique section so that
912  // the table doesn't prevent the removal.
913  const Comdat *C = F.getComdat();
914  bool EmitUniqueSection = TM.getFunctionSections() || C;
915  if (!EmitUniqueSection)
916  return ReadOnlySection;
917 
919  getMangler(), TM, EmitUniqueSection,
920  ELF::SHF_ALLOC, &NextUniqueID,
921  /* AssociatedSymbol */ nullptr);
922 }
923 
925  const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
926  // If neither COMDAT nor function sections, use the monolithic LSDA section.
927  // Re-use this path if LSDASection is null as in the Arm EHABI.
928  if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
929  return LSDASection;
930 
931  const auto *LSDA = cast<MCSectionELF>(LSDASection);
932  unsigned Flags = LSDA->getFlags();
933  const MCSymbolELF *LinkedToSym = nullptr;
934  StringRef Group;
935  bool IsComdat = false;
936  if (const Comdat *C = getELFComdat(&F)) {
937  Flags |= ELF::SHF_GROUP;
938  Group = C->getName();
939  IsComdat = C->getSelectionKind() == Comdat::Any;
940  }
941  // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
942  // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
943  if (TM.getFunctionSections() &&
944  (getContext().getAsmInfo()->useIntegratedAssembler() &&
945  getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
946  Flags |= ELF::SHF_LINK_ORDER;
947  LinkedToSym = cast<MCSymbolELF>(&FnSym);
948  }
949 
950  // Append the function name as the suffix like GCC, assuming
951  // -funique-section-names applies to .gcc_except_table sections.
952  return getContext().getELFSection(
953  (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
954  : LSDA->getName()),
955  LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
956  LinkedToSym);
957 }
958 
960  bool UsesLabelDifference, const Function &F) const {
961  // We can always create relative relocations, so use another section
962  // that can be marked non-executable.
963  return false;
964 }
965 
966 /// Given a mergeable constant with the specified size and relocation
967 /// information, return a section that it should be placed in.
969  const DataLayout &DL, SectionKind Kind, const Constant *C,
970  Align &Alignment) const {
971  if (Kind.isMergeableConst4() && MergeableConst4Section)
972  return MergeableConst4Section;
973  if (Kind.isMergeableConst8() && MergeableConst8Section)
974  return MergeableConst8Section;
975  if (Kind.isMergeableConst16() && MergeableConst16Section)
977  if (Kind.isMergeableConst32() && MergeableConst32Section)
979  if (Kind.isReadOnly())
980  return ReadOnlySection;
981 
982  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
983  return DataRelROSection;
984 }
985 
986 /// Returns a unique section for the given machine basic block.
988  const Function &F, const MachineBasicBlock &MBB,
989  const TargetMachine &TM) const {
990  assert(MBB.isBeginSection() && "Basic block does not start a section!");
991  unsigned UniqueID = MCContext::GenericSectionID;
992 
993  // For cold sections use the .text.split. prefix along with the parent
994  // function name. All cold blocks for the same function go to the same
995  // section. Similarly all exception blocks are grouped by symbol name
996  // under the .text.eh prefix. For regular sections, we either use a unique
997  // name, or a unique ID for the section.
1001  Name += MBB.getParent()->getName();
1003  Name += ".text.eh.";
1004  Name += MBB.getParent()->getName();
1005  } else {
1006  Name += MBB.getParent()->getSection()->getName();
1008  if (!Name.endswith("."))
1009  Name += ".";
1010  Name += MBB.getSymbol()->getName();
1011  } else {
1012  UniqueID = NextUniqueID++;
1013  }
1014  }
1015 
1016  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
1017  std::string GroupName;
1018  if (F.hasComdat()) {
1019  Flags |= ELF::SHF_GROUP;
1020  GroupName = F.getComdat()->getName().str();
1021  }
1023  0 /* Entry Size */, GroupName,
1024  F.hasComdat(), UniqueID, nullptr);
1025 }
1026 
1027 static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
1028  bool IsCtor, unsigned Priority,
1029  const MCSymbol *KeySym) {
1030  std::string Name;
1031  unsigned Type;
1032  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
1033  StringRef Comdat = KeySym ? KeySym->getName() : "";
1034 
1035  if (KeySym)
1036  Flags |= ELF::SHF_GROUP;
1037 
1038  if (UseInitArray) {
1039  if (IsCtor) {
1041  Name = ".init_array";
1042  } else {
1044  Name = ".fini_array";
1045  }
1046  if (Priority != 65535) {
1047  Name += '.';
1048  Name += utostr(Priority);
1049  }
1050  } else {
1051  // The default scheme is .ctor / .dtor, so we have to invert the priority
1052  // numbering.
1053  if (IsCtor)
1054  Name = ".ctors";
1055  else
1056  Name = ".dtors";
1057  if (Priority != 65535)
1058  raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1060  }
1061 
1062  return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
1063 }
1064 
1066  unsigned Priority, const MCSymbol *KeySym) const {
1067  return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
1068  KeySym);
1069 }
1070 
1072  unsigned Priority, const MCSymbol *KeySym) const {
1073  return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
1074  KeySym);
1075 }
1076 
1078  const GlobalValue *LHS, const GlobalValue *RHS,
1079  const TargetMachine &TM) const {
1080  // We may only use a PLT-relative relocation to refer to unnamed_addr
1081  // functions.
1082  if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
1083  return nullptr;
1084 
1085  // Basic sanity checks.
1086  if (LHS->getType()->getPointerAddressSpace() != 0 ||
1087  RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
1088  RHS->isThreadLocal())
1089  return nullptr;
1090 
1091  return MCBinaryExpr::createSub(
1093  getContext()),
1095 }
1096 
1098  const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const {
1100 
1101  const auto *GV = Equiv->getGlobalValue();
1102 
1103  // A PLT entry is not needed for dso_local globals.
1104  if (GV->isDSOLocal() || GV->isImplicitDSOLocal())
1106 
1108  getContext());
1109 }
1110 
1112  // Use ".GCC.command.line" since this feature is to support clang's
1113  // -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1114  // same name.
1115  return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
1117 }
1118 
1119 void
1121  UseInitArray = UseInitArray_;
1122  MCContext &Ctx = getContext();
1123  if (!UseInitArray) {
1126 
1129  return;
1130  }
1131 
1136 }
1137 
1138 //===----------------------------------------------------------------------===//
1139 // MachO
1140 //===----------------------------------------------------------------------===//
1141 
1145 }
1146 
1148  const TargetMachine &TM) {
1150  if (TM.getRelocationModel() == Reloc::Static) {
1151  StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0,
1153  StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0,
1155  } else {
1156  StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func",
1159  StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func",
1162  }
1163 
1167  TTypeEncoding =
1169 }
1170 
1172  Module &M) const {
1173  // Emit the linker options if present.
1174  if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1175  for (const auto *Option : LinkerOptions->operands()) {
1176  SmallVector<std::string, 4> StrOptions;
1177  for (const auto &Piece : cast<MDNode>(Option)->operands())
1178  StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1179  Streamer.emitLinkerOptions(StrOptions);
1180  }
1181  }
1182 
1183  unsigned VersionVal = 0;
1184  unsigned ImageInfoFlags = 0;
1185  StringRef SectionVal;
1186 
1187  GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1188 
1189  // The section is mandatory. If we don't have it, then we don't have GC info.
1190  if (SectionVal.empty())
1191  return;
1192 
1193  StringRef Segment, Section;
1194  unsigned TAA = 0, StubSize = 0;
1195  bool TAAParsed;
1197  SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1198  // If invalid, report the error with report_fatal_error.
1199  report_fatal_error("Invalid section specifier '" + Section +
1200  "': " + toString(std::move(E)) + ".");
1201  }
1202 
1203  // Get the section.
1205  Segment, Section, TAA, StubSize, SectionKind::getData());
1206  Streamer.SwitchSection(S);
1207  Streamer.emitLabel(getContext().
1208  getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1209  Streamer.emitInt32(VersionVal);
1210  Streamer.emitInt32(ImageInfoFlags);
1211  Streamer.AddBlankLine();
1212 }
1213 
1214 static void checkMachOComdat(const GlobalValue *GV) {
1215  const Comdat *C = GV->getComdat();
1216  if (!C)
1217  return;
1218 
1219  report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
1220  "' cannot be lowered.");
1221 }
1222 
1224  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1225 
1227 
1228  const Function *F = dyn_cast<Function>(GO);
1229  if (F && F->hasFnAttribute("implicit-section-name")) {
1230  SectionName = F->getFnAttribute("implicit-section-name").getValueAsString();
1231  }
1232 
1233  // Parse the section specifier and create it if valid.
1234  StringRef Segment, Section;
1235  unsigned TAA = 0, StubSize = 0;
1236  bool TAAParsed;
1237 
1238  checkMachOComdat(GO);
1239 
1241  SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1242  // If invalid, report the error with report_fatal_error.
1243  report_fatal_error("Global variable '" + GO->getName() +
1244  "' has an invalid section specifier '" +
1245  GO->getSection() + "': " + toString(std::move(E)) + ".");
1246  }
1247 
1248  // Get the section.
1249  MCSectionMachO *S =
1250  getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1251 
1252  // If TAA wasn't set by ParseSectionSpecifier() above,
1253  // use the value returned by getMachOSection() as a default.
1254  if (!TAAParsed)
1255  TAA = S->getTypeAndAttributes();
1256 
1257  // Okay, now that we got the section, verify that the TAA & StubSize agree.
1258  // If the user declared multiple globals with different section flags, we need
1259  // to reject it here.
1260  if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1261  // If invalid, report the error with report_fatal_error.
1262  report_fatal_error("Global variable '" + GO->getName() +
1263  "' section type or attributes does not match previous"
1264  " section specifier");
1265  }
1266 
1267  return S;
1268 }
1269 
1271  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1272  checkMachOComdat(GO);
1273 
1274  // Handle thread local data.
1275  if (Kind.isThreadBSS()) return TLSBSSSection;
1276  if (Kind.isThreadData()) return TLSDataSection;
1277 
1278  if (Kind.isText())
1279  return GO->isWeakForLinker() ? TextCoalSection : TextSection;
1280 
1281  // If this is weak/linkonce, put this in a coalescable section, either in text
1282  // or data depending on if it is writable.
1283  if (GO->isWeakForLinker()) {
1284  if (Kind.isReadOnly())
1285  return ConstTextCoalSection;
1286  if (Kind.isReadOnlyWithRel())
1287  return ConstDataCoalSection;
1288  return DataCoalSection;
1289  }
1290 
1291  // FIXME: Alignment check should be handled by section classifier.
1292  if (Kind.isMergeable1ByteCString() &&
1294  cast<GlobalVariable>(GO)) < Align(32))
1295  return CStringSection;
1296 
1297  // Do not put 16-bit arrays in the UString section if they have an
1298  // externally visible label, this runs into issues with certain linker
1299  // versions.
1300  if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1302  cast<GlobalVariable>(GO)) < Align(32))
1303  return UStringSection;
1304 
1305  // With MachO only variables whose corresponding symbol starts with 'l' or
1306  // 'L' can be merged, so we only try merging GVs with private linkage.
1307  if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1308  if (Kind.isMergeableConst4())
1309  return FourByteConstantSection;
1310  if (Kind.isMergeableConst8())
1311  return EightByteConstantSection;
1312  if (Kind.isMergeableConst16())
1314  }
1315 
1316  // Otherwise, if it is readonly, but not something we can specially optimize,
1317  // just drop it in .const.
1318  if (Kind.isReadOnly())
1319  return ReadOnlySection;
1320 
1321  // If this is marked const, put it into a const section. But if the dynamic
1322  // linker needs to write to it, put it in the data segment.
1323  if (Kind.isReadOnlyWithRel())
1324  return ConstDataSection;
1325 
1326  // Put zero initialized globals with strong external linkage in the
1327  // DATA, __common section with the .zerofill directive.
1328  if (Kind.isBSSExtern())
1329  return DataCommonSection;
1330 
1331  // Put zero initialized globals with local linkage in __DATA,__bss directive
1332  // with the .zerofill directive (aka .lcomm).
1333  if (Kind.isBSSLocal())
1334  return DataBSSSection;
1335 
1336  // Otherwise, just drop the variable in the normal data section.
1337  return DataSection;
1338 }
1339 
1341  const DataLayout &DL, SectionKind Kind, const Constant *C,
1342  Align &Alignment) const {
1343  // If this constant requires a relocation, we have to put it in the data
1344  // segment, not in the text segment.
1345  if (Kind.isData() || Kind.isReadOnlyWithRel())
1346  return ConstDataSection;
1347 
1348  if (Kind.isMergeableConst4())
1349  return FourByteConstantSection;
1350  if (Kind.isMergeableConst8())
1351  return EightByteConstantSection;
1352  if (Kind.isMergeableConst16())
1354  return ReadOnlySection; // .const
1355 }
1356 
1358  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
1359  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1360  // The mach-o version of this method defaults to returning a stub reference.
1361 
1362  if (Encoding & DW_EH_PE_indirect) {
1363  MachineModuleInfoMachO &MachOMMI =
1365 
1366  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1367 
1368  // Add information about the stub reference to MachOMMI so that the stub
1369  // gets emitted by the asmprinter.
1370  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1371  if (!StubSym.getPointer()) {
1372  MCSymbol *Sym = TM.getSymbol(GV);
1373  StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1374  }
1375 
1378  Encoding & ~DW_EH_PE_indirect, Streamer);
1379  }
1380 
1382  MMI, Streamer);
1383 }
1384 
1386  const GlobalValue *GV, const TargetMachine &TM,
1387  MachineModuleInfo *MMI) const {
1388  // The mach-o version of this method defaults to returning a stub reference.
1389  MachineModuleInfoMachO &MachOMMI =
1391 
1392  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
1393 
1394  // Add information about the stub reference to MachOMMI so that the stub
1395  // gets emitted by the asmprinter.
1396  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1397  if (!StubSym.getPointer()) {
1398  MCSymbol *Sym = TM.getSymbol(GV);
1399  StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1400  }
1401 
1402  return SSym;
1403 }
1404 
1406  const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
1407  int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
1408  // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1409  // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1410  // through a non_lazy_ptr stub instead. One advantage is that it allows the
1411  // computation of deltas to final external symbols. Example:
1412  //
1413  // _extgotequiv:
1414  // .long _extfoo
1415  //
1416  // _delta:
1417  // .long _extgotequiv-_delta
1418  //
1419  // is transformed to:
1420  //
1421  // _delta:
1422  // .long L_extfoo$non_lazy_ptr-(_delta+0)
1423  //
1424  // .section __IMPORT,__pointers,non_lazy_symbol_pointers
1425  // L_extfoo$non_lazy_ptr:
1426  // .indirect_symbol _extfoo
1427  // .long 0
1428  //
1429  // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1430  // may point to both local (same translation unit) and global (other
1431  // translation units) symbols. Example:
1432  //
1433  // .section __DATA,__pointers,non_lazy_symbol_pointers
1434  // L1:
1435  // .indirect_symbol _myGlobal
1436  // .long 0
1437  // L2:
1438  // .indirect_symbol _myLocal
1439  // .long _myLocal
1440  //
1441  // If the symbol is local, instead of the symbol's index, the assembler
1442  // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1443  // Then the linker will notice the constant in the table and will look at the
1444  // content of the symbol.
1445  MachineModuleInfoMachO &MachOMMI =
1447  MCContext &Ctx = getContext();
1448 
1449  // The offset must consider the original displacement from the base symbol
1450  // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1451  Offset = -MV.getConstant();
1452  const MCSymbol *BaseSym = &MV.getSymB()->getSymbol();
1453 
1454  // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1455  // non_lazy_ptr stubs.
1457  StringRef Suffix = "$non_lazy_ptr";
1459  Name += Sym->getName();
1460  Name += Suffix;
1461  MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1462 
1463  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1464 
1465  if (!StubSym.getPointer())
1466  StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1467  !GV->hasLocalLinkage());
1468 
1469  const MCExpr *BSymExpr =
1471  const MCExpr *LHS =
1473 
1474  if (!Offset)
1475  return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1476 
1477  const MCExpr *RHS =
1479  return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1480 }
1481 
1482 static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
1483  const MCSection &Section) {
1484  if (!AsmInfo.isSectionAtomizableBySymbols(Section))
1485  return true;
1486 
1487  // FIXME: we should be able to use private labels for sections that can't be
1488  // dead-stripped (there's no issue with blocking atomization there), but `ld
1489  // -r` sometimes drops the no_dead_strip attribute from sections so for safety
1490  // we don't allow it.
1491  return false;
1492 }
1493 
1495  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1496  const TargetMachine &TM) const {
1497  bool CannotUsePrivateLabel = true;
1498  if (auto *GO = GV->getAliaseeObject()) {
1500  const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
1501  CannotUsePrivateLabel =
1502  !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
1503  }
1504  getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1505 }
1506 
1507 //===----------------------------------------------------------------------===//
1508 // COFF
1509 //===----------------------------------------------------------------------===//
1510 
1511 static unsigned
1513  unsigned Flags = 0;
1514  bool isThumb = TM.getTargetTriple().getArch() == Triple::thumb;
1515 
1516  if (K.isMetadata())
1517  Flags |=
1519  else if (K.isText())
1520  Flags |=
1525  else if (K.isBSS())
1526  Flags |=
1530  else if (K.isThreadLocal())
1531  Flags |=
1535  else if (K.isReadOnly() || K.isReadOnlyWithRel())
1536  Flags |=
1539  else if (K.isWriteable())
1540  Flags |=
1544 
1545  return Flags;
1546 }
1547 
1548 static const GlobalValue *getComdatGVForCOFF(const GlobalValue *GV) {
1549  const Comdat *C = GV->getComdat();
1550  assert(C && "expected GV to have a Comdat!");
1551 
1552  StringRef ComdatGVName = C->getName();
1553  const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1554  if (!ComdatGV)
1555  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1556  "' does not exist.");
1557 
1558  if (ComdatGV->getComdat() != C)
1559  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1560  "' is not a key for its COMDAT.");
1561 
1562  return ComdatGV;
1563 }
1564 
1565 static int getSelectionForCOFF(const GlobalValue *GV) {
1566  if (const Comdat *C = GV->getComdat()) {
1567  const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
1568  if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1569  ComdatKey = GA->getAliaseeObject();
1570  if (ComdatKey == GV) {
1571  switch (C->getSelectionKind()) {
1572  case Comdat::Any:
1574  case Comdat::ExactMatch:
1576  case Comdat::Largest:
1578  case Comdat::NoDeduplicate:
1580  case Comdat::SameSize:
1582  }
1583  } else {
1585  }
1586  }
1587  return 0;
1588 }
1589 
1591  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1592  int Selection = 0;
1594  StringRef Name = GO->getSection();
1595  StringRef COMDATSymName = "";
1596  if (GO->hasComdat()) {
1598  const GlobalValue *ComdatGV;
1600  ComdatGV = getComdatGVForCOFF(GO);
1601  else
1602  ComdatGV = GO;
1603 
1604  if (!ComdatGV->hasPrivateLinkage()) {
1605  MCSymbol *Sym = TM.getSymbol(ComdatGV);
1606  COMDATSymName = Sym->getName();
1608  } else {
1609  Selection = 0;
1610  }
1611  }
1612 
1613  return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
1614  Selection);
1615 }
1616 
1618  if (Kind.isText())
1619  return ".text";
1620  if (Kind.isBSS())
1621  return ".bss";
1622  if (Kind.isThreadLocal())
1623  return ".tls$";
1624  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1625  return ".rdata";
1626  return ".data";
1627 }
1628 
1630  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1631  // If we have -ffunction-sections then we should emit the global value to a
1632  // uniqued section specifically for it.
1633  bool EmitUniquedSection;
1634  if (Kind.isText())
1635  EmitUniquedSection = TM.getFunctionSections();
1636  else
1637  EmitUniquedSection = TM.getDataSections();
1638 
1639  if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1641 
1643 
1645  int Selection = getSelectionForCOFF(GO);
1646  if (!Selection)
1648  const GlobalValue *ComdatGV;
1649  if (GO->hasComdat())
1650  ComdatGV = getComdatGVForCOFF(GO);
1651  else
1652  ComdatGV = GO;
1653 
1654  unsigned UniqueID = MCContext::GenericSectionID;
1655  if (EmitUniquedSection)
1656  UniqueID = NextUniqueID++;
1657 
1658  if (!ComdatGV->hasPrivateLinkage()) {
1659  MCSymbol *Sym = TM.getSymbol(ComdatGV);
1660  StringRef COMDATSymName = Sym->getName();
1661 
1662  if (const auto *F = dyn_cast<Function>(GO))
1663  if (Optional<StringRef> Prefix = F->getSectionPrefix())
1664  raw_svector_ostream(Name) << '$' << *Prefix;
1665 
1666  // Append "$symbol" to the section name *before* IR-level mangling is
1667  // applied when targetting mingw. This is what GCC does, and the ld.bfd
1668  // COFF linker will not properly handle comdats otherwise.
1669  if (getContext().getTargetTriple().isWindowsGNUEnvironment())
1670  raw_svector_ostream(Name) << '$' << ComdatGV->getName();
1671 
1673  COMDATSymName, Selection, UniqueID);
1674  } else {
1675  SmallString<256> TmpData;
1676  getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
1677  return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
1678  Selection, UniqueID);
1679  }
1680  }
1681 
1682  if (Kind.isText())
1683  return TextSection;
1684 
1685  if (Kind.isThreadLocal())
1686  return TLSDataSection;
1687 
1688  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1689  return ReadOnlySection;
1690 
1691  // Note: we claim that common symbols are put in BSSSection, but they are
1692  // really emitted with the magic .comm directive, which creates a symbol table
1693  // entry but not a section.
1694  if (Kind.isBSS() || Kind.isCommon())
1695  return BSSSection;
1696 
1697  return DataSection;
1698 }
1699 
1701  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
1702  const TargetMachine &TM) const {
1703  bool CannotUsePrivateLabel = false;
1704  if (GV->hasPrivateLinkage() &&
1705  ((isa<Function>(GV) && TM.getFunctionSections()) ||
1706  (isa<GlobalVariable>(GV) && TM.getDataSections())))
1707  CannotUsePrivateLabel = true;
1708 
1709  getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1710 }
1711 
1713  const Function &F, const TargetMachine &TM) const {
1714  // If the function can be removed, produce a unique section so that
1715  // the table doesn't prevent the removal.
1716  const Comdat *C = F.getComdat();
1717  bool EmitUniqueSection = TM.getFunctionSections() || C;
1718  if (!EmitUniqueSection)
1719  return ReadOnlySection;
1720 
1721  // FIXME: we should produce a symbol for F instead.
1722  if (F.hasPrivateLinkage())
1723  return ReadOnlySection;
1724 
1725  MCSymbol *Sym = TM.getSymbol(&F);
1726  StringRef COMDATSymName = Sym->getName();
1727 
1732  unsigned UniqueID = NextUniqueID++;
1733 
1734  return getContext().getCOFFSection(
1735  SecName, Characteristics, Kind, COMDATSymName,
1737 }
1738 
1740  Module &M) const {
1741  emitLinkerDirectives(Streamer, M);
1742 
1743  unsigned Version = 0;
1744  unsigned Flags = 0;
1746 
1747  GetObjCImageInfo(M, Version, Flags, Section);
1748  if (!Section.empty()) {
1749  auto &C = getContext();
1750  auto *S = C.getCOFFSection(Section,
1754  Streamer.SwitchSection(S);
1755  Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1756  Streamer.emitInt32(Version);
1757  Streamer.emitInt32(Flags);
1758  Streamer.AddBlankLine();
1759  }
1760 
1761  emitCGProfileMetadata(Streamer, M);
1762 }
1763 
1764 void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
1765  MCStreamer &Streamer, Module &M) const {
1766  if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1767  // Emit the linker options to the linker .drectve section. According to the
1768  // spec, this section is a space-separated string containing flags for
1769  // linker.
1770  MCSection *Sec = getDrectveSection();
1771  Streamer.SwitchSection(Sec);
1772  for (const auto *Option : LinkerOptions->operands()) {
1773  for (const auto &Piece : cast<MDNode>(Option)->operands()) {
1774  // Lead with a space for consistency with our dllexport implementation.
1775  std::string Directive(" ");
1776  Directive.append(std::string(cast<MDString>(Piece)->getString()));
1777  Streamer.emitBytes(Directive);
1778  }
1779  }
1780  }
1781 
1782  // Emit /EXPORT: flags for each exported global as necessary.
1783  std::string Flags;
1784  for (const GlobalValue &GV : M.global_values()) {
1785  raw_string_ostream OS(Flags);
1786  emitLinkerFlagsForGlobalCOFF(OS, &GV, getContext().getTargetTriple(),
1787  getMangler());
1788  OS.flush();
1789  if (!Flags.empty()) {
1790  Streamer.SwitchSection(getDrectveSection());
1791  Streamer.emitBytes(Flags);
1792  }
1793  Flags.clear();
1794  }
1795 
1796  // Emit /INCLUDE: flags for each used global as necessary.
1797  if (const auto *LU = M.getNamedGlobal("llvm.used")) {
1798  assert(LU->hasInitializer() && "expected llvm.used to have an initializer");
1799  assert(isa<ArrayType>(LU->getValueType()) &&
1800  "expected llvm.used to be an array type");
1801  if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
1802  for (const Value *Op : A->operands()) {
1803  const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
1804  // Global symbols with internal or private linkage are not visible to
1805  // the linker, and thus would cause an error when the linker tried to
1806  // preserve the symbol due to the `/include:` directive.
1807  if (GV->hasLocalLinkage())
1808  continue;
1809 
1810  raw_string_ostream OS(Flags);
1811  emitLinkerFlagsForUsedCOFF(OS, GV, getContext().getTargetTriple(),
1812  getMangler());
1813  OS.flush();
1814 
1815  if (!Flags.empty()) {
1816  Streamer.SwitchSection(getDrectveSection());
1817  Streamer.emitBytes(Flags);
1818  }
1819  Flags.clear();
1820  }
1821  }
1822  }
1823 }
1824 
1826  const TargetMachine &TM) {
1828  this->TM = &TM;
1829  const Triple &T = TM.getTargetTriple();
1830  if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1839  } else {
1848  }
1849 }
1850 
1852  const Triple &T, bool IsCtor,
1853  unsigned Priority,
1854  const MCSymbol *KeySym,
1855  MCSectionCOFF *Default) {
1856  if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1857  // If the priority is the default, use .CRT$XCU, possibly associative.
1858  if (Priority == 65535)
1859  return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
1860 
1861  // Otherwise, we need to compute a new section name. Low priorities should
1862  // run earlier. The linker will sort sections ASCII-betically, and we need a
1863  // string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
1864  // make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
1865  // low priorities need to sort before 'L', since the CRT uses that
1866  // internally, so we use ".CRT$XCA00001" for them.
1869  OS << ".CRT$X" << (IsCtor ? "C" : "T") <<
1870  (Priority < 200 ? 'A' : 'T') << format("%05u", Priority);
1871  MCSectionCOFF *Sec = Ctx.getCOFFSection(
1874  return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
1875  }
1876 
1877  std::string Name = IsCtor ? ".ctors" : ".dtors";
1878  if (Priority != 65535)
1879  raw_string_ostream(Name) << format(".%05u", 65535 - Priority);
1880 
1881  return Ctx.getAssociativeCOFFSection(
1886  KeySym, 0);
1887 }
1888 
1890  unsigned Priority, const MCSymbol *KeySym) const {
1892  getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
1893  cast<MCSectionCOFF>(StaticCtorSection));
1894 }
1895 
1897  unsigned Priority, const MCSymbol *KeySym) const {
1899  getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
1900  cast<MCSectionCOFF>(StaticDtorSection));
1901 }
1902 
1904  const GlobalValue *LHS, const GlobalValue *RHS,
1905  const TargetMachine &TM) const {
1906  const Triple &T = TM.getTargetTriple();
1907  if (T.isOSCygMing())
1908  return nullptr;
1909 
1910  // Our symbols should exist in address space zero, cowardly no-op if
1911  // otherwise.
1912  if (LHS->getType()->getPointerAddressSpace() != 0 ||
1913  RHS->getType()->getPointerAddressSpace() != 0)
1914  return nullptr;
1915 
1916  // Both ptrtoint instructions must wrap global objects:
1917  // - Only global variables are eligible for image relative relocations.
1918  // - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
1919  // We expect __ImageBase to be a global variable without a section, externally
1920  // defined.
1921  //
1922  // It should look something like this: @__ImageBase = external constant i8
1923  if (!isa<GlobalObject>(LHS) || !isa<GlobalVariable>(RHS) ||
1924  LHS->isThreadLocal() || RHS->isThreadLocal() ||
1925  RHS->getName() != "__ImageBase" || !RHS->hasExternalLinkage() ||
1926  cast<GlobalVariable>(RHS)->hasInitializer() || RHS->hasSection())
1927  return nullptr;
1928 
1929  return MCSymbolRefExpr::create(TM.getSymbol(LHS),
1931  getContext());
1932 }
1933 
1934 static std::string APIntToHexString(const APInt &AI) {
1935  unsigned Width = (AI.getBitWidth() / 8) * 2;
1936  std::string HexString = toString(AI, 16, /*Signed=*/false);
1937  llvm::transform(HexString, HexString.begin(), tolower);
1938  unsigned Size = HexString.size();
1939  assert(Width >= Size && "hex string is too large!");
1940  HexString.insert(HexString.begin(), Width - Size, '0');
1941 
1942  return HexString;
1943 }
1944 
1945 static std::string scalarConstantToHexString(const Constant *C) {
1946  Type *Ty = C->getType();
1947  if (isa<UndefValue>(C)) {
1949  } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
1950  return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
1951  } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
1952  return APIntToHexString(CI->getValue());
1953  } else {
1954  unsigned NumElements;
1955  if (auto *VTy = dyn_cast<VectorType>(Ty))
1956  NumElements = cast<FixedVectorType>(VTy)->getNumElements();
1957  else
1958  NumElements = Ty->getArrayNumElements();
1959  std::string HexString;
1960  for (int I = NumElements - 1, E = -1; I != E; --I)
1961  HexString += scalarConstantToHexString(C->getAggregateElement(I));
1962  return HexString;
1963  }
1964 }
1965 
1967  const DataLayout &DL, SectionKind Kind, const Constant *C,
1968  Align &Alignment) const {
1969  if (Kind.isMergeableConst() && C &&
1970  getContext().getAsmInfo()->hasCOFFComdatConstants()) {
1971  // This creates comdat sections with the given symbol name, but unless
1972  // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
1973  // will be created with a null storage class, which makes GNU binutils
1974  // error out.
1978  std::string COMDATSymName;
1979  if (Kind.isMergeableConst4()) {
1980  if (Alignment <= 4) {
1981  COMDATSymName = "__real@" + scalarConstantToHexString(C);
1982  Alignment = Align(4);
1983  }
1984  } else if (Kind.isMergeableConst8()) {
1985  if (Alignment <= 8) {
1986  COMDATSymName = "__real@" + scalarConstantToHexString(C);
1987  Alignment = Align(8);
1988  }
1989  } else if (Kind.isMergeableConst16()) {
1990  // FIXME: These may not be appropriate for non-x86 architectures.
1991  if (Alignment <= 16) {
1992  COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
1993  Alignment = Align(16);
1994  }
1995  } else if (Kind.isMergeableConst32()) {
1996  if (Alignment <= 32) {
1997  COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
1998  Alignment = Align(32);
1999  }
2000  }
2001 
2002  if (!COMDATSymName.empty())
2003  return getContext().getCOFFSection(".rdata", Characteristics, Kind,
2004  COMDATSymName,
2006  }
2007 
2009  Alignment);
2010 }
2011 
2012 //===----------------------------------------------------------------------===//
2013 // Wasm
2014 //===----------------------------------------------------------------------===//
2015 
2016 static const Comdat *getWasmComdat(const GlobalValue *GV) {
2017  const Comdat *C = GV->getComdat();
2018  if (!C)
2019  return nullptr;
2020 
2021  if (C->getSelectionKind() != Comdat::Any)
2022  report_fatal_error("WebAssembly COMDATs only support "
2023  "SelectionKind::Any, '" + C->getName() + "' cannot be "
2024  "lowered.");
2025 
2026  return C;
2027 }
2028 
2029 static unsigned getWasmSectionFlags(SectionKind K) {
2030  unsigned Flags = 0;
2031 
2032  if (K.isThreadLocal())
2033  Flags |= wasm::WASM_SEG_FLAG_TLS;
2034 
2035  if (K.isMergeableCString())
2036  Flags |= wasm::WASM_SEG_FLAG_STRINGS;
2037 
2038  // TODO(sbc): Add suport for K.isMergeableConst()
2039 
2040  return Flags;
2041 }
2042 
2044  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2045  // We don't support explict section names for functions in the wasm object
2046  // format. Each function has to be in its own unique section.
2047  if (isa<Function>(GO)) {
2048  return SelectSectionForGlobal(GO, Kind, TM);
2049  }
2050 
2051  StringRef Name = GO->getSection();
2052 
2053  // Certain data sections we treat as named custom sections rather than
2054  // segments within the data section.
2055  // This could be avoided if all data segements (the wasm sense) were
2056  // represented as their own sections (in the llvm sense).
2057  // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2058  if (Name == ".llvmcmd" || Name == ".llvmbc")
2060 
2061  StringRef Group = "";
2062  if (const Comdat *C = getWasmComdat(GO)) {
2063  Group = C->getName();
2064  }
2065 
2066  unsigned Flags = getWasmSectionFlags(Kind);
2068  Name, Kind, Flags, Group, MCContext::GenericSectionID);
2069 
2070  return Section;
2071 }
2072 
2074  MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
2075  const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID) {
2076  StringRef Group = "";
2077  if (const Comdat *C = getWasmComdat(GO)) {
2078  Group = C->getName();
2079  }
2080 
2081  bool UniqueSectionNames = TM.getUniqueSectionNames();
2083 
2084  if (const auto *F = dyn_cast<Function>(GO)) {
2085  const auto &OptionalPrefix = F->getSectionPrefix();
2086  if (OptionalPrefix)
2087  raw_svector_ostream(Name) << '.' << *OptionalPrefix;
2088  }
2089 
2090  if (EmitUniqueSection && UniqueSectionNames) {
2091  Name.push_back('.');
2092  TM.getNameWithPrefix(Name, GO, Mang, true);
2093  }
2094  unsigned UniqueID = MCContext::GenericSectionID;
2095  if (EmitUniqueSection && !UniqueSectionNames) {
2096  UniqueID = *NextUniqueID;
2097  (*NextUniqueID)++;
2098  }
2099 
2100  unsigned Flags = getWasmSectionFlags(Kind);
2101  return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2102 }
2103 
2105  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2106 
2107  if (Kind.isCommon())
2108  report_fatal_error("mergable sections not supported yet on wasm");
2109 
2110  // If we have -ffunction-section or -fdata-section then we should emit the
2111  // global value to a uniqued section specifically for it.
2112  bool EmitUniqueSection = false;
2113  if (Kind.isText())
2114  EmitUniqueSection = TM.getFunctionSections();
2115  else
2116  EmitUniqueSection = TM.getDataSections();
2117  EmitUniqueSection |= GO->hasComdat();
2118 
2120  EmitUniqueSection, &NextUniqueID);
2121 }
2122 
2124  bool UsesLabelDifference, const Function &F) const {
2125  // We can always create relative relocations, so use another section
2126  // that can be marked non-executable.
2127  return false;
2128 }
2129 
2131  const GlobalValue *LHS, const GlobalValue *RHS,
2132  const TargetMachine &TM) const {
2133  // We may only use a PLT-relative relocation to refer to unnamed_addr
2134  // functions.
2135  if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
2136  return nullptr;
2137 
2138  // Basic sanity checks.
2139  if (LHS->getType()->getPointerAddressSpace() != 0 ||
2140  RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
2141  RHS->isThreadLocal())
2142  return nullptr;
2143 
2144  return MCBinaryExpr::createSub(
2146  getContext()),
2148 }
2149 
2152  getContext().getWasmSection(".init_array", SectionKind::getData());
2153 
2154  // We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2155  // .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2157 }
2158 
2160  unsigned Priority, const MCSymbol *KeySym) const {
2161  return Priority == UINT16_MAX ?
2163  getContext().getWasmSection(".init_array." + utostr(Priority),
2165 }
2166 
2168  unsigned Priority, const MCSymbol *KeySym) const {
2169  llvm_unreachable("@llvm.global_dtors should have been lowered already");
2170  return nullptr;
2171 }
2172 
2173 //===----------------------------------------------------------------------===//
2174 // XCOFF
2175 //===----------------------------------------------------------------------===//
2177  const MachineFunction *MF) {
2178  if (!MF->getLandingPads().empty())
2179  return true;
2180 
2181  const Function &F = MF->getFunction();
2182  if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2183  return false;
2184 
2185  const GlobalValue *Per =
2186  dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2187  assert(Per && "Personality routine is not a GlobalValue type.");
2189  return false;
2190 
2191  return true;
2192 }
2193 
2195  const MachineFunction *MF) {
2196  const Function &F = MF->getFunction();
2197  if (!F.hasStackProtectorFnAttr())
2198  return false;
2199  // FIXME: check presence of canary word
2200  // There are cases that the stack protectors are not really inserted even if
2201  // the attributes are on.
2202  return true;
2203 }
2204 
2205 MCSymbol *
2207  return MF->getMMI().getContext().getOrCreateSymbol(
2208  "__ehinfo." + Twine(MF->getFunctionNumber()));
2209 }
2210 
2211 MCSymbol *
2213  const TargetMachine &TM) const {
2214  // We always use a qualname symbol for a GV that represents
2215  // a declaration, a function descriptor, or a common symbol.
2216  // If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2217  // also return a qualname so that a label symbol could be avoided.
2218  // It is inherently ambiguous when the GO represents the address of a
2219  // function, as the GO could either represent a function descriptor or a
2220  // function entry point. We choose to always return a function descriptor
2221  // here.
2222  if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2223  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2224  if (GVar->hasAttribute("toc-data"))
2225  return cast<MCSectionXCOFF>(
2227  ->getQualNameSymbol();
2228 
2229  if (GO->isDeclarationForLinker())
2230  return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
2231  ->getQualNameSymbol();
2232 
2233  SectionKind GOKind = getKindForGlobal(GO, TM);
2234  if (GOKind.isText())
2235  return cast<MCSectionXCOFF>(
2236  getSectionForFunctionDescriptor(cast<Function>(GO), TM))
2237  ->getQualNameSymbol();
2238  if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2239  GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2240  return cast<MCSectionXCOFF>(SectionForGlobal(GO, GOKind, TM))
2241  ->getQualNameSymbol();
2242  }
2243 
2244  // For all other cases, fall back to getSymbol to return the unqualified name.
2245  return nullptr;
2246 }
2247 
2249  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2250  if (!GO->hasSection())
2251  report_fatal_error("#pragma clang section is not yet supported");
2252 
2254 
2255  // Handle the XCOFF::TD case first, then deal with the rest.
2256  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2257  if (GVar->hasAttribute("toc-data"))
2258  return getContext().getXCOFFSection(
2259  SectionName, Kind,
2261  /* MultiSymbolsAllowed*/ true);
2262 
2263  XCOFF::StorageMappingClass MappingClass;
2264  if (Kind.isText())
2265  MappingClass = XCOFF::XMC_PR;
2266  else if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS())
2267  MappingClass = XCOFF::XMC_RW;
2268  else if (Kind.isReadOnly())
2269  MappingClass = XCOFF::XMC_RO;
2270  else
2271  report_fatal_error("XCOFF other section types not yet implemented.");
2272 
2273  return getContext().getXCOFFSection(
2275  /* MultiSymbolsAllowed*/ true);
2276 }
2277 
2279  const GlobalObject *GO, const TargetMachine &TM) const {
2281  "Tried to get ER section for a defined global.");
2282 
2284  getNameWithPrefix(Name, GO, TM);
2285 
2287  isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA;
2288  if (GO->isThreadLocal())
2289  SMC = XCOFF::XMC_UL;
2290 
2291  // Externals go into a csect of type ER.
2292  return getContext().getXCOFFSection(
2295 }
2296 
2298  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2299  // Handle the XCOFF::TD case first, then deal with the rest.
2300  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2301  if (GVar->hasAttribute("toc-data")) {
2303  getNameWithPrefix(Name, GO, TM);
2304  return getContext().getXCOFFSection(
2306  /* MultiSymbolsAllowed*/ true);
2307  }
2308 
2309  // Common symbols go into a csect with matching name which will get mapped
2310  // into the .bss section.
2311  // Zero-initialized local TLS symbols go into a csect with matching name which
2312  // will get mapped into the .tbss section.
2313  if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2315  getNameWithPrefix(Name, GO, TM);
2316  XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ? XCOFF::XMC_BS
2317  : Kind.isCommon() ? XCOFF::XMC_RW
2318  : XCOFF::XMC_UL;
2319  return getContext().getXCOFFSection(
2321  }
2322 
2323  if (Kind.isMergeableCString()) {
2324  Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
2325  cast<GlobalVariable>(GO));
2326 
2327  unsigned EntrySize = getEntrySizeForKind(Kind);
2328  std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
2330  Name = SizeSpec + utostr(Alignment.value());
2331 
2332  if (TM.getDataSections())
2333  getNameWithPrefix(Name, GO, TM);
2334 
2335  return getContext().getXCOFFSection(
2337  /* MultiSymbolsAllowed*/ !TM.getDataSections());
2338  }
2339 
2340  if (Kind.isText()) {
2341  if (TM.getFunctionSections()) {
2342  return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM))
2343  ->getRepresentedCsect();
2344  }
2345  return TextSection;
2346  }
2347 
2348  // TODO: We may put Kind.isReadOnlyWithRel() under option control, because
2349  // user may want to have read-only data with relocations placed into a
2350  // read-only section by the compiler.
2351  // For BSS kind, zero initialized data must be emitted to the .data section
2352  // because external linkage control sections that get mapped to the .bss
2353  // section will be linked as tentative defintions, which is only appropriate
2354  // for SectionKind::Common.
2355  if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2356  if (TM.getDataSections()) {
2358  getNameWithPrefix(Name, GO, TM);
2359  return getContext().getXCOFFSection(
2362  }
2363  return DataSection;
2364  }
2365 
2366  if (Kind.isReadOnly()) {
2367  if (TM.getDataSections()) {
2369  getNameWithPrefix(Name, GO, TM);
2370  return getContext().getXCOFFSection(
2373  }
2374  return ReadOnlySection;
2375  }
2376 
2377  // External/weak TLS data and initialized local TLS data are not eligible
2378  // to be put into common csect. If data sections are enabled, thread
2379  // data are emitted into separate sections. Otherwise, thread data
2380  // are emitted into the .tdata section.
2381  if (Kind.isThreadLocal()) {
2382  if (TM.getDataSections()) {
2384  getNameWithPrefix(Name, GO, TM);
2385  return getContext().getXCOFFSection(
2387  }
2388  return TLSDataSection;
2389  }
2390 
2391  report_fatal_error("XCOFF other section types not yet implemented.");
2392 }
2393 
2395  const Function &F, const TargetMachine &TM) const {
2396  assert (!F.getComdat() && "Comdat not supported on XCOFF.");
2397 
2398  if (!TM.getFunctionSections())
2399  return ReadOnlySection;
2400 
2401  // If the function can be removed, produce a unique section so that
2402  // the table doesn't prevent the removal.
2403  SmallString<128> NameStr(".rodata.jmp..");
2404  getNameWithPrefix(NameStr, &F, TM);
2405  return getContext().getXCOFFSection(
2406  NameStr, SectionKind::getReadOnly(),
2408 }
2409 
2411  bool UsesLabelDifference, const Function &F) const {
2412  return false;
2413 }
2414 
2415 /// Given a mergeable constant with the specified size and relocation
2416 /// information, return a section that it should be placed in.
2418  const DataLayout &DL, SectionKind Kind, const Constant *C,
2419  Align &Alignment) const {
2420  // TODO: Enable emiting constant pool to unique sections when we support it.
2421  if (Alignment > Align(16))
2422  report_fatal_error("Alignments greater than 16 not yet supported.");
2423 
2424  if (Alignment == Align(8)) {
2425  assert(ReadOnly8Section && "Section should always be initialized.");
2426  return ReadOnly8Section;
2427  }
2428 
2429  if (Alignment == Align(16)) {
2430  assert(ReadOnly16Section && "Section should always be initialized.");
2431  return ReadOnly16Section;
2432  }
2433 
2434  return ReadOnlySection;
2435 }
2436 
2438  const TargetMachine &TgtM) {
2440  TTypeEncoding =
2444  PersonalityEncoding = 0;
2445  LSDAEncoding = 0;
2447 }
2448 
2450  unsigned Priority, const MCSymbol *KeySym) const {
2451  report_fatal_error("no static constructor section on AIX");
2452 }
2453 
2455  unsigned Priority, const MCSymbol *KeySym) const {
2456  report_fatal_error("no static destructor section on AIX");
2457 }
2458 
2460  const GlobalValue *LHS, const GlobalValue *RHS,
2461  const TargetMachine &TM) const {
2462  /* Not implemented yet, but don't crash, return nullptr. */
2463  return nullptr;
2464 }
2465 
2468  assert(!isa<GlobalIFunc>(GV) && "GlobalIFunc is not supported on AIX.");
2469 
2470  switch (GV->getLinkage()) {
2473  return XCOFF::C_HIDEXT;
2477  return XCOFF::C_EXT;
2483  return XCOFF::C_WEAKEXT;
2486  "There is no mapping that implements AppendingLinkage for XCOFF.");
2487  }
2488  llvm_unreachable("Unknown linkage type!");
2489 }
2490 
2492  const GlobalValue *Func, const TargetMachine &TM) const {
2493  assert((isa<Function>(Func) ||
2494  (isa<GlobalAlias>(Func) &&
2495  isa_and_nonnull<Function>(
2496  cast<GlobalAlias>(Func)->getAliaseeObject()))) &&
2497  "Func must be a function or an alias which has a function as base "
2498  "object.");
2499 
2500  SmallString<128> NameStr;
2501  NameStr.push_back('.');
2502  getNameWithPrefix(NameStr, Func, TM);
2503 
2504  // When -function-sections is enabled and explicit section is not specified,
2505  // it's not necessary to emit function entry point label any more. We will use
2506  // function entry point csect instead. And for function delcarations, the
2507  // undefined symbols gets treated as csect with XTY_ER property.
2508  if (((TM.getFunctionSections() && !Func->hasSection()) ||
2509  Func->isDeclaration()) &&
2510  isa<Function>(Func)) {
2511  return getContext()
2512  .getXCOFFSection(
2513  NameStr, SectionKind::getText(),
2514  XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclaration()
2515  ? XCOFF::XTY_ER
2516  : XCOFF::XTY_SD))
2517  ->getQualNameSymbol();
2518  }
2519 
2520  return getContext().getOrCreateSymbol(NameStr);
2521 }
2522 
2524  const Function *F, const TargetMachine &TM) const {
2525  SmallString<128> NameStr;
2526  getNameWithPrefix(NameStr, F, TM);
2527  return getContext().getXCOFFSection(
2528  NameStr, SectionKind::getData(),
2530 }
2531 
2533  const MCSymbol *Sym, const TargetMachine &TM) const {
2534  // Use TE storage-mapping class when large code model is enabled so that
2535  // the chance of needing -bbigtoc is decreased.
2536  return getContext().getXCOFFSection(
2537  cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
2540  XCOFF::XTY_SD));
2541 }
2542 
2543 //===----------------------------------------------------------------------===//
2544 // GOFF
2545 //===----------------------------------------------------------------------===//
2548 
2550  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2551  return SelectSectionForGlobal(GO, Kind, TM);
2552 }
2553 
2555  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2556  auto *Symbol = TM.getSymbol(GO);
2557  if (Kind.isBSS())
2558  return getContext().getGOFFSection(Symbol->getName(),
2560 
2562 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::ELF::SHF_GROUP
@ SHF_GROUP
Definition: ELF.h:1016
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:65
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:924
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:427
llvm::DK_Lowering
@ DK_Lowering
Definition: DiagnosticInfo.h:61
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
This file implements support for optimizing divisions by a constant.
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:1851
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:216
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:813
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1421
llvm::SectionKind::getMetadata
static SectionKind getMetadata()
Definition: SectionKind.h:182
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition: GlobalValue.h:455
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
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:874
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:1405
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:972
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:434
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:269
llvm::ELF::SHT_LLVM_LINKER_OPTIONS
@ SHT_LLVM_LINKER_OPTIONS
Definition: ELF.h:941
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:2532
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::ELF::SHF_TLS
@ SHF_TLS
Definition: ELF.h:1019
getELFSectionType
static unsigned getELFSectionType(StringRef Name, SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:481
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:467
T
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:62
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:1065
llvm::MCStreamer::emitELFSize
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition: MCStreamer.cpp:1180
StringRef.h
llvm::ELF::SHF_STRINGS
@ SHF_STRINGS
Definition: ELF.h:1003
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::ELF::SHF_GNU_RETAIN
@ SHF_GNU_RETAIN
Definition: ELF.h:1025
llvm::MCStreamer::emitInt64
void emitInt64(uint64_t Value)
Definition: MCStreamer.h:708
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:625
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:1030
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:806
llvm::CodeModel::Medium
@ Medium
Definition: CodeGen.h:28
MCSectionELF.h
llvm::Comdat::NoDeduplicate
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:37
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::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:705
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:1270
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:2043
ErrorHandling.h
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:734
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::ELF::SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition: ELF.h:944
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:1142
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:605
checkMachOComdat
static void checkMachOComdat(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:1214
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:1120
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:2394
llvm::TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2206
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:1410
Module.h
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:707
llvm::XCOFF::XMC_TC
@ XMC_TC
General TOC item.
Definition: XCOFF.h:62
llvm::TargetMachine::getUniqueSectionNames
bool getUniqueSectionNames() const
Definition: TargetMachine.h:266
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
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:363
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::ELF::SHT_INIT_ARRAY
@ SHT_INIT_ARRAY
Definition: ELF.h:927
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:483
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:62
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:2278
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:1357
llvm::TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock
static bool ShouldEmitEHBlock(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2176
Format.h
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:235
getELFKindForNamedSection
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:438
llvm::ELF::SHF_ARM_PURECODE
@ SHF_ARM_PURECODE
Definition: ELF.h:1086
llvm::Triple::mips64
@ mips64
Definition: Triple.h:64
llvm::APInt::getZero
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:177
llvm::TargetLoweringObjectFileELF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:909
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:997
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:59
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:44
llvm::TargetLoweringObjectFileCOFF::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1700
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::MCObjectFileInfo::ReadOnly8Section
MCSection * ReadOnly8Section
Definition: MCObjectFileInfo.h:228
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:2437
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:2449
getELFSectionFlags
static unsigned getELFSectionFlags(SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:503
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
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:1340
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:959
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:2248
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::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
llvm::ELF::SHF_EXCLUDE
@ SHF_EXCLUDE
Definition: ELF.h:1028
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::TargetLoweringObjectFileWasm::InitializeWasm
void InitializeWasm()
Definition: TargetLoweringObjectFileImpl.cpp:2150
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:2159
llvm::TargetOptions::UseInitArray
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Definition: TargetOptions.h:246
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:1077
scalarConstantToHexString
static std::string scalarConstantToHexString(const Constant *C)
Definition: TargetLoweringObjectFileImpl.cpp:1945
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:281
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:415
MCSymbol.h
llvm::TargetLoweringObjectFileXCOFF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition: TargetLoweringObjectFileImpl.cpp:2454
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:181
llvm::MCObjectFileInfo::isPositionIndependent
bool isPositionIndependent() const
Definition: MCObjectFileInfo.h:424
llvm::MCContext::getGOFFSection
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind)
Definition: MCContext.cpp:619
llvm::GlobalValue::hasPrivateLinkage
bool hasPrivateLinkage() const
Definition: GlobalValue.h:450
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::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:119
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:45
llvm::TargetLoweringObjectFileMachO::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1494
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:2297
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:398
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:103
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:209
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:2417
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:310
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:208
llvm::MCObjectFileInfo::getTextSection
MCSection * getTextSection() const
Definition: MCObjectFileInfo.h:258
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:2523
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::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:1617
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:379
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:67
llvm::TargetLoweringObjectFileCOFF::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
Definition: TargetLoweringObjectFileImpl.cpp:1739
getCOFFSectionFlags
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
Definition: TargetLoweringObjectFileImpl.cpp:1512
llvm::CodeModel::Model
Model
Definition: CodeGen.h:28
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1137
llvm::PointerIntPair::getPointer
PointerTy getPointer() const
Definition: PointerIntPair.h:59
llvm::MachineFunction::getMMI
MachineModuleInfo & getMMI() const
Definition: MachineFunction.h:581
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:2167
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:238
llvm::TargetLoweringObjectFile::SupportIndirectSymViaGOTPCRel
bool SupportIndirectSymViaGOTPCRel
Definition: TargetLoweringObjectFile.h:49
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:381
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
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition: ELF.h:922
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:578
llvm::SectionKind::isMetadata
bool isMetadata() const
Definition: SectionKind.h:119
llvm::TargetLoweringObjectFile::getPersonalityEncoding
unsigned getPersonalityEncoding() const
Definition: TargetLoweringObjectFile.h:167
llvm::XCOFF::XTY_CM
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:188
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:916
llvm::Triple::isOSFreeBSD
bool isOSFreeBSD() const
Definition: Triple.h:511
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:1370
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
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
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:994
BasicBlockSectionUtils.h
MCSectionGOFF.h
llvm::TargetLoweringObjectFileWasm::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition: TargetLoweringObjectFileImpl.cpp:2123
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:1147
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:2212
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:542
llvm::MBBSectionID::ExceptionSectionID
const static MBBSectionID ExceptionSectionID
Definition: MachineBasicBlock.h:65
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:120
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:79
llvm::MCSectionCOFF
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
llvm::Type::getArrayNumElements
uint64_t getArrayNumElements() const
Definition: DerivedTypes.h:384
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:2549
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:451
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:609
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:197
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:1065
PreferPredicateTy::Option
Option
Definition: LoopVectorize.cpp:212
MachineModuleInfo.h
APIntToHexString
static std::string APIntToHexString(const APInt &AI)
Definition: TargetLoweringObjectFileImpl.cpp:1934
llvm::TargetLoweringObjectFileMachO::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit the module flags that specify the garbage collection information.
Definition: TargetLoweringObjectFileImpl.cpp:1171
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:906
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:968
llvm::TargetLoweringObjectFileELF::lowerDSOLocalEquivalent
const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1097
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:2104
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::MachineFunction
Definition: MachineFunction.h:234
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:1825
llvm::TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol
MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const override
If supported, return the function entry point symbol.
Definition: TargetLoweringObjectFileImpl.cpp:2491
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:524
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition: TargetMachine.h:207
llvm::TargetLoweringObjectFile::getMangler
Mangler & getMangler() const
Definition: TargetLoweringObjectFile.h:76
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:1071
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:134
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:1648
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:1565
llvm::XCOFF::C_WEAKEXT
@ C_WEAKEXT
Definition: XCOFF.h:142
canUsePrivateLabel
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
Definition: TargetLoweringObjectFileImpl.cpp:1482
llvm::Triple::thumb
@ thumb
Definition: Triple.h:81
llvm::MCObjectFileInfo::getDrectveSection
MCSection * getDrectveSection() const
Definition: MCObjectFileInfo.h:410
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:990
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:247
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
llvm::GlobalValue::getAliaseeObject
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:316
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:2016
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:286
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
llvm::TargetLoweringObjectFileELF::getUniqueSectionForFunction
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:893
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::MachineBasicBlock::getSectionID
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
Definition: MachineBasicBlock.h:574
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:56
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:585
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:733
llvm::TargetLoweringObjectFileMachO::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition: TargetLoweringObjectFileImpl.cpp:1385
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:596
llvm::TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF
TargetLoweringObjectFileGOFF()
Definition: TargetLoweringObjectFileImpl.cpp:2546
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:324
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::ELF::SHF_MERGE
@ SHF_MERGE
Definition: ELF.h:1000
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:333
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:2194
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:1111
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:1223
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:385
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:1590
Wasm.h
llvm::Triple::systemz
@ systemz
Definition: Triple.h:78
MCValue.h
SectionKind.h
GlobalAlias.h
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:413
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:108
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::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:57
llvm::TargetLoweringObjectFileXCOFF::getStorageClassForGlobal
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:2467
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:161
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:211
llvm::TargetLoweringObjectFileCOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1629
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:2459
llvm::MCSectionXCOFF::getQualNameSymbol
MCSymbolXCOFF * getQualNameSymbol() const
Definition: MCSectionXCOFF.h:102
llvm::MCObjectFileInfo::ReadOnly16Section
MCSection * ReadOnly16Section
Definition: MCObjectFileInfo.h:229
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:128
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:987
selectWasmSectionForGlobal
static MCSectionWasm * selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID)
Definition: TargetLoweringObjectFileImpl.cpp:2073
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition: GlobalValue.h:540
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
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:1199
llvm::ELF::SHT_FINI_ARRAY
@ SHT_FINI_ARRAY
Definition: ELF.h:928
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:1189
llvm::Triple::getEnvironment
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
Definition: Triple.h:327
llvm::TargetLoweringObjectFileWasm::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2130
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::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::ELF::SHF_LINK_ORDER
@ SHF_LINK_ORDER
Definition: ELF.h:1009
llvm::TargetLoweringObjectFile::TTypeEncoding
unsigned TTypeEncoding
Definition: TargetLoweringObjectFile.h:58
getStaticStructorSection
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
Definition: TargetLoweringObjectFileImpl.cpp:1027
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:991
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:1966
MachO.h
llvm::TargetLoweringObjectFileGOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:2554
llvm::TargetLoweringObjectFileCOFF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:1712
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:1889
MachineFunction.h
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:923
getELFComdat
static const Comdat * getELFComdat(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:530
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:1896
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:1212
getComdatGVForCOFF
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
Definition: TargetLoweringObjectFileImpl.cpp:1548
llvm::ELF::SHT_PREINIT_ARRAY
@ SHT_PREINIT_ARRAY
Definition: ELF.h:929
MCExpr.h
llvm::TargetLoweringObjectFile::SupportDSOLocalEquivalentLowering
bool SupportDSOLocalEquivalentLowering
Definition: TargetLoweringObjectFile.h:52
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:378
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::Value
LLVM Value Representation.
Definition: Value.h:74
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:46
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:2410
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:753
getWasmSectionFlags
static unsigned getWasmSectionFlags(SectionKind K)
Definition: TargetLoweringObjectFileImpl.cpp:2029
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:1903
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:166
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:275
llvm::MCObjectFileInfo::TextSection
MCSection * TextSection
Section directive for standard text.
Definition: MCObjectFileInfo.h:55
TargetLoweringObjectFileImpl.h