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