LLVM  3.7.0
TargetLoweringObjectFileImpl.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/TargetLoweringObjectFileImpl.cpp - Object File Info --===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/Triple.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/IR/GlobalVariable.h"
25 #include "llvm/IR/Mangler.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/MC/MCContext.h"
28 #include "llvm/MC/MCExpr.h"
29 #include "llvm/MC/MCSectionCOFF.h"
30 #include "llvm/MC/MCSectionELF.h"
31 #include "llvm/MC/MCSectionMachO.h"
32 #include "llvm/MC/MCStreamer.h"
33 #include "llvm/MC/MCSymbolELF.h"
34 #include "llvm/MC/MCValue.h"
35 #include "llvm/Support/Dwarf.h"
36 #include "llvm/Support/ELF.h"
42 using namespace llvm;
43 using namespace dwarf;
44 
45 //===----------------------------------------------------------------------===//
46 // ELF
47 //===----------------------------------------------------------------------===//
48 
50  const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
51  MachineModuleInfo *MMI) const {
52  unsigned Encoding = getPersonalityEncoding();
53  if ((Encoding & 0x80) == dwarf::DW_EH_PE_indirect)
54  return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
55  TM.getSymbol(GV, Mang)->getName());
56  if ((Encoding & 0x70) == dwarf::DW_EH_PE_absptr)
57  return TM.getSymbol(GV, Mang);
58  report_fatal_error("We do not support this DWARF encoding yet!");
59 }
60 
62  const TargetMachine &TM,
63  const MCSymbol *Sym) const {
64  SmallString<64> NameData("DW.ref.");
65  NameData += Sym->getName();
67  cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
68  Streamer.EmitSymbolAttribute(Label, MCSA_Hidden);
69  Streamer.EmitSymbolAttribute(Label, MCSA_Weak);
70  StringRef Prefix = ".data.";
71  NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end());
73  MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS,
74  Flags, 0, Label->getName());
75  unsigned Size = TM.getDataLayout()->getPointerSize();
76  Streamer.SwitchSection(Sec);
79  const MCExpr *E = MCConstantExpr::create(Size, getContext());
80  Streamer.emitELFSize(Label, E);
81  Streamer.EmitLabel(Label);
82 
83  Streamer.EmitSymbolValue(Sym, Size);
84 }
85 
87  const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
88  const TargetMachine &TM, MachineModuleInfo *MMI,
89  MCStreamer &Streamer) const {
90 
91  if (Encoding & dwarf::DW_EH_PE_indirect) {
93 
94  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM);
95 
96  // Add information about the stub reference to ELFMMI so that the stub
97  // gets emitted by the asmprinter.
98  MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
99  if (!StubSym.getPointer()) {
100  MCSymbol *Sym = TM.getSymbol(GV, Mang);
102  }
103 
105  getTTypeReference(MCSymbolRefExpr::create(SSym, getContext()),
106  Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
107  }
108 
110  getTTypeGlobalReference(GV, Encoding, Mang, TM, MMI, Streamer);
111 }
112 
113 static SectionKind
115  // N.B.: The defaults used in here are no the same ones used in MC.
116  // We follow gcc, MC follows gas. For example, given ".section .eh_frame",
117  // both gas and MC will produce a section with no flags. Given
118  // section(".eh_frame") gcc will produce:
119  //
120  // .section .eh_frame,"a",@progbits
121  if (Name.empty() || Name[0] != '.') return K;
122 
123  // Some lame default implementation based on some magic section names.
124  if (Name == ".bss" ||
125  Name.startswith(".bss.") ||
126  Name.startswith(".gnu.linkonce.b.") ||
127  Name.startswith(".llvm.linkonce.b.") ||
128  Name == ".sbss" ||
129  Name.startswith(".sbss.") ||
130  Name.startswith(".gnu.linkonce.sb.") ||
131  Name.startswith(".llvm.linkonce.sb."))
132  return SectionKind::getBSS();
133 
134  if (Name == ".tdata" ||
135  Name.startswith(".tdata.") ||
136  Name.startswith(".gnu.linkonce.td.") ||
137  Name.startswith(".llvm.linkonce.td."))
139 
140  if (Name == ".tbss" ||
141  Name.startswith(".tbss.") ||
142  Name.startswith(".gnu.linkonce.tb.") ||
143  Name.startswith(".llvm.linkonce.tb."))
144  return SectionKind::getThreadBSS();
145 
146  return K;
147 }
148 
149 
151 
152  if (Name == ".init_array")
153  return ELF::SHT_INIT_ARRAY;
154 
155  if (Name == ".fini_array")
156  return ELF::SHT_FINI_ARRAY;
157 
158  if (Name == ".preinit_array")
159  return ELF::SHT_PREINIT_ARRAY;
160 
161  if (K.isBSS() || K.isThreadBSS())
162  return ELF::SHT_NOBITS;
163 
164  return ELF::SHT_PROGBITS;
165 }
166 
167 static unsigned getELFSectionFlags(SectionKind K) {
168  unsigned Flags = 0;
169 
170  if (!K.isMetadata())
171  Flags |= ELF::SHF_ALLOC;
172 
173  if (K.isText())
174  Flags |= ELF::SHF_EXECINSTR;
175 
176  if (K.isWriteable())
177  Flags |= ELF::SHF_WRITE;
178 
179  if (K.isThreadLocal())
180  Flags |= ELF::SHF_TLS;
181 
182  if (K.isMergeableCString() || K.isMergeableConst())
183  Flags |= ELF::SHF_MERGE;
184 
185  if (K.isMergeableCString())
186  Flags |= ELF::SHF_STRINGS;
187 
188  return Flags;
189 }
190 
191 static const Comdat *getELFComdat(const GlobalValue *GV) {
192  const Comdat *C = GV->getComdat();
193  if (!C)
194  return nullptr;
195 
196  if (C->getSelectionKind() != Comdat::Any)
197  report_fatal_error("ELF COMDATs only support SelectionKind::Any, '" +
198  C->getName() + "' cannot be lowered.");
199 
200  return C;
201 }
202 
204  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
205  const TargetMachine &TM) const {
206  StringRef SectionName = GV->getSection();
207 
208  // Infer section flags from the section name if we can.
209  Kind = getELFKindForNamedSection(SectionName, Kind);
210 
211  StringRef Group = "";
212  unsigned Flags = getELFSectionFlags(Kind);
213  if (const Comdat *C = getELFComdat(GV)) {
214  Group = C->getName();
215  Flags |= ELF::SHF_GROUP;
216  }
217  return getContext().getELFSection(SectionName,
218  getELFSectionType(SectionName, Kind), Flags,
219  /*EntrySize=*/0, Group);
220 }
221 
222 /// Return the section prefix name used by options FunctionsSections and
223 /// DataSections.
225  if (Kind.isText())
226  return ".text";
227  if (Kind.isReadOnly())
228  return ".rodata";
229  if (Kind.isBSS())
230  return ".bss";
231  if (Kind.isThreadData())
232  return ".tdata";
233  if (Kind.isThreadBSS())
234  return ".tbss";
235  if (Kind.isDataNoRel())
236  return ".data";
237  if (Kind.isDataRelLocal())
238  return ".data.rel.local";
239  if (Kind.isDataRel())
240  return ".data.rel";
241  if (Kind.isReadOnlyWithRelLocal())
242  return ".data.rel.ro.local";
243  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
244  return ".data.rel.ro";
245 }
246 
247 static MCSectionELF *
249  SectionKind Kind, Mangler &Mang,
250  const TargetMachine &TM, bool EmitUniqueSection,
251  unsigned Flags, unsigned *NextUniqueID) {
252  unsigned EntrySize = 0;
253  if (Kind.isMergeableCString()) {
254  if (Kind.isMergeable2ByteCString()) {
255  EntrySize = 2;
256  } else if (Kind.isMergeable4ByteCString()) {
257  EntrySize = 4;
258  } else {
259  EntrySize = 1;
260  assert(Kind.isMergeable1ByteCString() && "unknown string width");
261  }
262  } else if (Kind.isMergeableConst()) {
263  if (Kind.isMergeableConst4()) {
264  EntrySize = 4;
265  } else if (Kind.isMergeableConst8()) {
266  EntrySize = 8;
267  } else {
268  assert(Kind.isMergeableConst16() && "unknown data width");
269  EntrySize = 16;
270  }
271  }
272 
273  StringRef Group = "";
274  if (const Comdat *C = getELFComdat(GV)) {
275  Flags |= ELF::SHF_GROUP;
276  Group = C->getName();
277  }
278 
281  if (Kind.isMergeableCString()) {
282  // We also need alignment here.
283  // FIXME: this is getting the alignment of the character, not the
284  // alignment of the global!
285  unsigned Align =
286  TM.getDataLayout()->getPreferredAlignment(cast<GlobalVariable>(GV));
287 
288  std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
289  Name = SizeSpec + utostr(Align);
290  } else if (Kind.isMergeableConst()) {
291  Name = ".rodata.cst";
292  Name += utostr(EntrySize);
293  } else {
294  Name = getSectionPrefixForGlobal(Kind);
295  }
296 
297  if (EmitUniqueSection && UniqueSectionNames) {
298  Name.push_back('.');
299  TM.getNameWithPrefix(Name, GV, Mang, true);
300  }
301  unsigned UniqueID = ~0;
302  if (EmitUniqueSection && !UniqueSectionNames) {
303  UniqueID = *NextUniqueID;
304  (*NextUniqueID)++;
305  }
306  return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags,
307  EntrySize, Group, UniqueID);
308 }
309 
311  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
312  const TargetMachine &TM) const {
313  unsigned Flags = getELFSectionFlags(Kind);
314 
315  // If we have -ffunction-section or -fdata-section then we should emit the
316  // global value to a uniqued section specifically for it.
317  bool EmitUniqueSection = false;
318  if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) {
319  if (Kind.isText())
320  EmitUniqueSection = TM.getFunctionSections();
321  else
322  EmitUniqueSection = TM.getDataSections();
323  }
324  EmitUniqueSection |= GV->hasComdat();
325 
326  return selectELFSectionForGlobal(getContext(), GV, Kind, Mang, TM,
327  EmitUniqueSection, Flags, &NextUniqueID);
328 }
329 
331  const Function &F, Mangler &Mang, const TargetMachine &TM) const {
332  // If the function can be removed, produce a unique section so that
333  // the table doesn't prevent the removal.
334  const Comdat *C = F.getComdat();
335  bool EmitUniqueSection = TM.getFunctionSections() || C;
336  if (!EmitUniqueSection)
337  return ReadOnlySection;
338 
339  return selectELFSectionForGlobal(getContext(), &F, SectionKind::getReadOnly(),
340  Mang, TM, EmitUniqueSection, ELF::SHF_ALLOC,
341  &NextUniqueID);
342 }
343 
345  bool UsesLabelDifference, const Function &F) const {
346  // We can always create relative relocations, so use another section
347  // that can be marked non-executable.
348  return false;
349 }
350 
351 /// Given a mergeable constant with the specified size and relocation
352 /// information, return a section that it should be placed in.
353 MCSection *
355  const Constant *C) const {
356  if (Kind.isMergeableConst4() && MergeableConst4Section)
357  return MergeableConst4Section;
358  if (Kind.isMergeableConst8() && MergeableConst8Section)
359  return MergeableConst8Section;
360  if (Kind.isMergeableConst16() && MergeableConst16Section)
361  return MergeableConst16Section;
362  if (Kind.isReadOnly())
363  return ReadOnlySection;
364 
365  if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
366  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
367  return DataRelROSection;
368 }
369 
370 static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
371  bool IsCtor, unsigned Priority,
372  const MCSymbol *KeySym) {
373  std::string Name;
374  unsigned Type;
375  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
376  StringRef COMDAT = KeySym ? KeySym->getName() : "";
377 
378  if (KeySym)
379  Flags |= ELF::SHF_GROUP;
380 
381  if (UseInitArray) {
382  if (IsCtor) {
383  Type = ELF::SHT_INIT_ARRAY;
384  Name = ".init_array";
385  } else {
386  Type = ELF::SHT_FINI_ARRAY;
387  Name = ".fini_array";
388  }
389  if (Priority != 65535) {
390  Name += '.';
391  Name += utostr(Priority);
392  }
393  } else {
394  // The default scheme is .ctor / .dtor, so we have to invert the priority
395  // numbering.
396  if (IsCtor)
397  Name = ".ctors";
398  else
399  Name = ".dtors";
400  if (Priority != 65535) {
401  Name += '.';
402  Name += utostr(65535 - Priority);
403  }
404  Type = ELF::SHT_PROGBITS;
405  }
406 
407  return Ctx.getELFSection(Name, Type, Flags, 0, COMDAT);
408 }
409 
411  unsigned Priority, const MCSymbol *KeySym) const {
412  return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
413  KeySym);
414 }
415 
417  unsigned Priority, const MCSymbol *KeySym) const {
418  return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
419  KeySym);
420 }
421 
422 void
424  UseInitArray = UseInitArray_;
425  if (!UseInitArray)
426  return;
427 
428  StaticCtorSection = getContext().getELFSection(
430  StaticDtorSection = getContext().getELFSection(
432 }
433 
434 //===----------------------------------------------------------------------===//
435 // MachO
436 //===----------------------------------------------------------------------===//
437 
441 }
442 
443 /// emitModuleFlags - Perform code emission for module flags.
447  Mangler &Mang, const TargetMachine &TM) const {
448  unsigned VersionVal = 0;
449  unsigned ImageInfoFlags = 0;
450  MDNode *LinkerOptions = nullptr;
451  StringRef SectionVal;
452 
454  i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) {
455  const Module::ModuleFlagEntry &MFE = *i;
456 
457  // Ignore flags with 'Require' behavior.
458  if (MFE.Behavior == Module::Require)
459  continue;
460 
461  StringRef Key = MFE.Key->getString();
462  Metadata *Val = MFE.Val;
463 
464  if (Key == "Objective-C Image Info Version") {
465  VersionVal = mdconst::extract<ConstantInt>(Val)->getZExtValue();
466  } else if (Key == "Objective-C Garbage Collection" ||
467  Key == "Objective-C GC Only" ||
468  Key == "Objective-C Is Simulated" ||
469  Key == "Objective-C Image Swift Version") {
470  ImageInfoFlags |= mdconst::extract<ConstantInt>(Val)->getZExtValue();
471  } else if (Key == "Objective-C Image Info Section") {
472  SectionVal = cast<MDString>(Val)->getString();
473  } else if (Key == "Linker Options") {
474  LinkerOptions = cast<MDNode>(Val);
475  }
476  }
477 
478  // Emit the linker options if present.
479  if (LinkerOptions) {
480  for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
481  MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
482  SmallVector<std::string, 4> StrOptions;
483 
484  // Convert to strings.
485  for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
486  MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
487  StrOptions.push_back(MDOption->getString());
488  }
489 
490  Streamer.EmitLinkerOptions(StrOptions);
491  }
492  }
493 
494  // The section is mandatory. If we don't have it, then we don't have GC info.
495  if (SectionVal.empty()) return;
496 
497  StringRef Segment, Section;
498  unsigned TAA = 0, StubSize = 0;
499  bool TAAParsed;
500  std::string ErrorCode =
501  MCSectionMachO::ParseSectionSpecifier(SectionVal, Segment, Section,
502  TAA, TAAParsed, StubSize);
503  if (!ErrorCode.empty())
504  // If invalid, report the error with report_fatal_error.
505  report_fatal_error("Invalid section specifier '" + Section + "': " +
506  ErrorCode + ".");
507 
508  // Get the section.
510  Segment, Section, TAA, StubSize, SectionKind::getDataNoRel());
511  Streamer.SwitchSection(S);
512  Streamer.EmitLabel(getContext().
513  getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
514  Streamer.EmitIntValue(VersionVal, 4);
515  Streamer.EmitIntValue(ImageInfoFlags, 4);
516  Streamer.AddBlankLine();
517 }
518 
519 static void checkMachOComdat(const GlobalValue *GV) {
520  const Comdat *C = GV->getComdat();
521  if (!C)
522  return;
523 
524  report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() +
525  "' cannot be lowered.");
526 }
527 
529  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
530  const TargetMachine &TM) const {
531  // Parse the section specifier and create it if valid.
532  StringRef Segment, Section;
533  unsigned TAA = 0, StubSize = 0;
534  bool TAAParsed;
535 
536  checkMachOComdat(GV);
537 
538  std::string ErrorCode =
540  TAA, TAAParsed, StubSize);
541  if (!ErrorCode.empty()) {
542  // If invalid, report the error with report_fatal_error.
543  report_fatal_error("Global variable '" + GV->getName() +
544  "' has an invalid section specifier '" +
545  GV->getSection() + "': " + ErrorCode + ".");
546  }
547 
548  // Get the section.
549  MCSectionMachO *S =
550  getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
551 
552  // If TAA wasn't set by ParseSectionSpecifier() above,
553  // use the value returned by getMachOSection() as a default.
554  if (!TAAParsed)
555  TAA = S->getTypeAndAttributes();
556 
557  // Okay, now that we got the section, verify that the TAA & StubSize agree.
558  // If the user declared multiple globals with different section flags, we need
559  // to reject it here.
560  if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
561  // If invalid, report the error with report_fatal_error.
562  report_fatal_error("Global variable '" + GV->getName() +
563  "' section type or attributes does not match previous"
564  " section specifier");
565  }
566 
567  return S;
568 }
569 
571  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
572  const TargetMachine &TM) const {
573  checkMachOComdat(GV);
574 
575  // Handle thread local data.
576  if (Kind.isThreadBSS()) return TLSBSSSection;
577  if (Kind.isThreadData()) return TLSDataSection;
578 
579  if (Kind.isText())
581 
582  // If this is weak/linkonce, put this in a coalescable section, either in text
583  // or data depending on if it is writable.
584  if (GV->isWeakForLinker()) {
585  if (Kind.isReadOnly())
586  return ConstTextCoalSection;
587  return DataCoalSection;
588  }
589 
590  // FIXME: Alignment check should be handled by section classifier.
591  if (Kind.isMergeable1ByteCString() &&
592  TM.getDataLayout()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32)
593  return CStringSection;
594 
595  // Do not put 16-bit arrays in the UString section if they have an
596  // externally visible label, this runs into issues with certain linker
597  // versions.
598  if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() &&
599  TM.getDataLayout()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32)
600  return UStringSection;
601 
602  // With MachO only variables whose corresponding symbol starts with 'l' or
603  // 'L' can be merged, so we only try merging GVs with private linkage.
604  if (GV->hasPrivateLinkage() && Kind.isMergeableConst()) {
605  if (Kind.isMergeableConst4())
607  if (Kind.isMergeableConst8())
609  if (Kind.isMergeableConst16())
611  }
612 
613  // Otherwise, if it is readonly, but not something we can specially optimize,
614  // just drop it in .const.
615  if (Kind.isReadOnly())
616  return ReadOnlySection;
617 
618  // If this is marked const, put it into a const section. But if the dynamic
619  // linker needs to write to it, put it in the data segment.
620  if (Kind.isReadOnlyWithRel())
621  return ConstDataSection;
622 
623  // Put zero initialized globals with strong external linkage in the
624  // DATA, __common section with the .zerofill directive.
625  if (Kind.isBSSExtern())
626  return DataCommonSection;
627 
628  // Put zero initialized globals with local linkage in __DATA,__bss directive
629  // with the .zerofill directive (aka .lcomm).
630  if (Kind.isBSSLocal())
631  return DataBSSSection;
632 
633  // Otherwise, just drop the variable in the normal data section.
634  return DataSection;
635 }
636 
637 MCSection *
639  const Constant *C) const {
640  // If this constant requires a relocation, we have to put it in the data
641  // segment, not in the text segment.
642  if (Kind.isDataRel() || Kind.isReadOnlyWithRel())
643  return ConstDataSection;
644 
645  if (Kind.isMergeableConst4())
647  if (Kind.isMergeableConst8())
649  if (Kind.isMergeableConst16())
651  return ReadOnlySection; // .const
652 }
653 
655  const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
656  const TargetMachine &TM, MachineModuleInfo *MMI,
657  MCStreamer &Streamer) const {
658  // The mach-o version of this method defaults to returning a stub reference.
659 
660  if (Encoding & DW_EH_PE_indirect) {
661  MachineModuleInfoMachO &MachOMMI =
663 
664  MCSymbol *SSym =
665  getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
666 
667  // Add information about the stub reference to MachOMMI so that the stub
668  // gets emitted by the asmprinter.
670  GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
671  MachOMMI.getGVStubEntry(SSym);
672  if (!StubSym.getPointer()) {
673  MCSymbol *Sym = TM.getSymbol(GV, Mang);
675  }
676 
679  Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
680  }
681 
682  return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, Mang,
683  TM, MMI, Streamer);
684 }
685 
687  const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
688  MachineModuleInfo *MMI) const {
689  // The mach-o version of this method defaults to returning a stub reference.
690  MachineModuleInfoMachO &MachOMMI =
692 
693  MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
694 
695  // Add information about the stub reference to MachOMMI so that the stub
696  // gets emitted by the asmprinter.
697  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
698  if (!StubSym.getPointer()) {
699  MCSymbol *Sym = TM.getSymbol(GV, Mang);
701  }
702 
703  return SSym;
704 }
705 
707  const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
708  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
709  // Although MachO 32-bit targets do not explictly have a GOTPCREL relocation
710  // as 64-bit do, we replace the GOT equivalent by accessing the final symbol
711  // through a non_lazy_ptr stub instead. One advantage is that it allows the
712  // computation of deltas to final external symbols. Example:
713  //
714  // _extgotequiv:
715  // .long _extfoo
716  //
717  // _delta:
718  // .long _extgotequiv-_delta
719  //
720  // is transformed to:
721  //
722  // _delta:
723  // .long L_extfoo$non_lazy_ptr-(_delta+0)
724  //
725  // .section __IMPORT,__pointers,non_lazy_symbol_pointers
726  // L_extfoo$non_lazy_ptr:
727  // .indirect_symbol _extfoo
728  // .long 0
729  //
730  MachineModuleInfoMachO &MachOMMI =
732  MCContext &Ctx = getContext();
733 
734  // The offset must consider the original displacement from the base symbol
735  // since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
736  Offset = -MV.getConstant();
737  const MCSymbol *BaseSym = &MV.getSymB()->getSymbol();
738 
739  // Access the final symbol via sym$non_lazy_ptr and generate the appropriated
740  // non_lazy_ptr stubs.
742  StringRef Suffix = "$non_lazy_ptr";
743  Name += DL->getPrivateGlobalPrefix();
744  Name += Sym->getName();
745  Name += Suffix;
746  MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
747 
748  MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
749  if (!StubSym.getPointer())
750  StubSym = MachineModuleInfoImpl::
751  StubValueTy(const_cast<MCSymbol *>(Sym), true /* access indirectly */);
752 
753  const MCExpr *BSymExpr =
755  const MCExpr *LHS =
757 
758  if (!Offset)
759  return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
760 
761  const MCExpr *RHS =
762  MCBinaryExpr::createAdd(BSymExpr, MCConstantExpr::create(Offset, Ctx), Ctx);
763  return MCBinaryExpr::createSub(LHS, RHS, Ctx);
764 }
765 
766 //===----------------------------------------------------------------------===//
767 // COFF
768 //===----------------------------------------------------------------------===//
769 
770 static unsigned
772  unsigned Flags = 0;
773 
774  if (K.isMetadata())
775  Flags |=
777  else if (K.isText())
778  Flags |=
782  else if (K.isBSS())
783  Flags |=
787  else if (K.isThreadLocal())
788  Flags |=
792  else if (K.isReadOnly() || K.isReadOnlyWithRel())
793  Flags |=
796  else if (K.isWriteable())
797  Flags |=
801 
802  return Flags;
803 }
804 
805 static const GlobalValue *getComdatGVForCOFF(const GlobalValue *GV) {
806  const Comdat *C = GV->getComdat();
807  assert(C && "expected GV to have a Comdat!");
808 
809  StringRef ComdatGVName = C->getName();
810  const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
811  if (!ComdatGV)
812  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
813  "' does not exist.");
814 
815  if (ComdatGV->getComdat() != C)
816  report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
817  "' is not a key for its COMDAT.");
818 
819  return ComdatGV;
820 }
821 
822 static int getSelectionForCOFF(const GlobalValue *GV) {
823  if (const Comdat *C = GV->getComdat()) {
824  const GlobalValue *ComdatKey = getComdatGVForCOFF(GV);
825  if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
826  ComdatKey = GA->getBaseObject();
827  if (ComdatKey == GV) {
828  switch (C->getSelectionKind()) {
829  case Comdat::Any:
831  case Comdat::ExactMatch:
833  case Comdat::Largest:
837  case Comdat::SameSize:
839  }
840  } else {
842  }
843  }
844  return 0;
845 }
846 
848  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
849  const TargetMachine &TM) const {
850  int Selection = 0;
851  unsigned Characteristics = getCOFFSectionFlags(Kind);
852  StringRef Name = GV->getSection();
853  StringRef COMDATSymName = "";
854  if (GV->hasComdat()) {
855  Selection = getSelectionForCOFF(GV);
856  const GlobalValue *ComdatGV;
857  if (Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE)
858  ComdatGV = getComdatGVForCOFF(GV);
859  else
860  ComdatGV = GV;
861 
862  if (!ComdatGV->hasPrivateLinkage()) {
863  MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang);
864  COMDATSymName = Sym->getName();
865  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
866  } else {
867  Selection = 0;
868  }
869  }
870  return getContext().getCOFFSection(Name,
871  Characteristics,
872  Kind,
873  COMDATSymName,
874  Selection);
875 }
876 
878  if (Kind.isText())
879  return ".text";
880  if (Kind.isBSS())
881  return ".bss";
882  if (Kind.isThreadLocal())
883  return ".tls$";
884  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
885  return ".rdata";
886  return ".data";
887 }
888 
890  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
891  const TargetMachine &TM) const {
892  // If we have -ffunction-sections then we should emit the global value to a
893  // uniqued section specifically for it.
894  bool EmitUniquedSection;
895  if (Kind.isText())
896  EmitUniquedSection = TM.getFunctionSections();
897  else
898  EmitUniquedSection = TM.getDataSections();
899 
900  if ((EmitUniquedSection && !Kind.isCommon()) || GV->hasComdat()) {
901  const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
902  unsigned Characteristics = getCOFFSectionFlags(Kind);
903 
904  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
905  int Selection = getSelectionForCOFF(GV);
906  if (!Selection)
908  const GlobalValue *ComdatGV;
909  if (GV->hasComdat())
910  ComdatGV = getComdatGVForCOFF(GV);
911  else
912  ComdatGV = GV;
913 
914  if (!ComdatGV->hasPrivateLinkage()) {
915  MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang);
916  StringRef COMDATSymName = Sym->getName();
917  return getContext().getCOFFSection(Name, Characteristics, Kind,
918  COMDATSymName, Selection);
919  } else {
920  SmallString<256> TmpData;
921  getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true, Mang, TM);
922  return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
923  Selection);
924  }
925  }
926 
927  if (Kind.isText())
928  return TextSection;
929 
930  if (Kind.isThreadLocal())
931  return TLSDataSection;
932 
933  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
934  return ReadOnlySection;
935 
936  // Note: we claim that common symbols are put in BSSSection, but they are
937  // really emitted with the magic .comm directive, which creates a symbol table
938  // entry but not a section.
939  if (Kind.isBSS() || Kind.isCommon())
940  return BSSSection;
941 
942  return DataSection;
943 }
944 
946  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
947  bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const {
948  if (GV->hasPrivateLinkage() &&
949  ((isa<Function>(GV) && TM.getFunctionSections()) ||
950  (isa<GlobalVariable>(GV) && TM.getDataSections())))
951  CannotUsePrivateLabel = true;
952 
953  Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
954 }
955 
957  const Function &F, Mangler &Mang, const TargetMachine &TM) const {
958  // If the function can be removed, produce a unique section so that
959  // the table doesn't prevent the removal.
960  const Comdat *C = F.getComdat();
961  bool EmitUniqueSection = TM.getFunctionSections() || C;
962  if (!EmitUniqueSection)
963  return ReadOnlySection;
964 
965  // FIXME: we should produce a symbol for F instead.
966  if (F.hasPrivateLinkage())
967  return ReadOnlySection;
968 
969  MCSymbol *Sym = TM.getSymbol(&F, Mang);
970  StringRef COMDATSymName = Sym->getName();
971 
973  const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
974  unsigned Characteristics = getCOFFSectionFlags(Kind);
975  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
976 
977  return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
979 }
980 
984  Mangler &Mang, const TargetMachine &TM) const {
985  MDNode *LinkerOptions = nullptr;
986 
987  // Look for the "Linker Options" flag, since it's the only one we support.
989  i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) {
990  const Module::ModuleFlagEntry &MFE = *i;
991  StringRef Key = MFE.Key->getString();
992  Metadata *Val = MFE.Val;
993  if (Key == "Linker Options") {
994  LinkerOptions = cast<MDNode>(Val);
995  break;
996  }
997  }
998  if (!LinkerOptions)
999  return;
1000 
1001  // Emit the linker options to the linker .drectve section. According to the
1002  // spec, this section is a space-separated string containing flags for linker.
1003  MCSection *Sec = getDrectveSection();
1004  Streamer.SwitchSection(Sec);
1005  for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
1006  MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
1007  for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
1008  MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
1009  // Lead with a space for consistency with our dllexport implementation.
1010  std::string Directive(" ");
1011  Directive.append(MDOption->getString());
1012  Streamer.EmitBytes(Directive);
1013  }
1014  }
1015 }
1016 
1018  unsigned Priority, const MCSymbol *KeySym) const {
1020  cast<MCSectionCOFF>(StaticCtorSection), KeySym);
1021 }
1022 
1024  unsigned Priority, const MCSymbol *KeySym) const {
1026  cast<MCSectionCOFF>(StaticDtorSection), KeySym);
1027 }
1028 
1030  raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const {
1031  if (!GV->hasDLLExportStorageClass() || GV->isDeclaration())
1032  return;
1033 
1034  const Triple &TT = getTargetTriple();
1035 
1037  OS << " /EXPORT:";
1038  else
1039  OS << " -export:";
1040 
1042  std::string Flag;
1043  raw_string_ostream FlagOS(Flag);
1044  Mang.getNameWithPrefix(FlagOS, GV, false);
1045  FlagOS.flush();
1046  if (Flag[0] == DL->getGlobalPrefix())
1047  OS << Flag.substr(1);
1048  else
1049  OS << Flag;
1050  } else {
1051  Mang.getNameWithPrefix(OS, GV, false);
1052  }
1053 
1054  if (!GV->getValueType()->isFunctionTy()) {
1056  OS << ",DATA";
1057  else
1058  OS << ",data";
1059  }
1060 }
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
StubValueTy & getHiddenGVStubEntry(MCSymbol *Sym)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
void push_back(const T &Elt)
Definition: SmallVector.h:222
bool isMergeableConst() const
Definition: SectionKind.h:152
MCSectionMachO - This represents a section on a Mach-O system (used by Mac OS X). ...
MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const override
Given a constant with the SectionKind, return a section that it should be placed in.
const MCSymbol & getSymbol() const
Definition: MCExpr.h:328
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, 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...
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
cl::opt< bool > UniqueSectionNames("unique-section-names", cl::desc("Give unique names to every section"), cl::init(true))
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
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:115
.type _foo, STT_OBJECT # aka
Definition: MCDirectives.h:25
This represents an "assembler immediate".
Definition: MCValue.h:44
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:266
MCSection * SixteenByteConstantSection
bool isBSSExtern() const
Definition: SectionKind.h:177
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:311
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:942
MCSection * TextSection
Section directive for standard text.
void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const override
iterator end() const
Definition: ArrayRef.h:123
MCSection * ConstTextCoalSection
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:681
Type * getValueType() const
Definition: GlobalValue.h:187
static void checkMachOComdat(const GlobalValue *GV)
bool isMergeable2ByteCString() const
Definition: SectionKind.h:149
MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const override
bool isBSS() const
Definition: SectionKind.h:175
const char * getPrivateGlobalPrefix() const
Definition: DataLayout.h:281
bool isReadOnlyWithRel() const
Definition: SectionKind.h:191
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:38
Metadata node.
Definition: Metadata.h:740
static StringRef getString(const MDString *S)
F(f)
const char * getSection() const
Definition: Globals.cpp:106
const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
bool isMergeableCString() const
Definition: SectionKind.h:144
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
char getGlobalPrefix() const
Definition: DataLayout.h:267
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition: MCStreamer.cpp:674
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Module.h:171
ModFlagBehavior Behavior
Definition: Module.h:196
bool hasDLLExportStorageClass() const
Definition: GlobalValue.h:170
static SectionKind getBSS()
Definition: SectionKind.h:223
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
Definition: DataLayout.cpp:575
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
The linker may choose any COMDAT.
Definition: Comdat.h:34
static unsigned getCOFFSectionFlags(SectionKind K)
MCSection * EightByteConstantSection
StringRef getName() const
Definition: Comdat.cpp:25
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO and COFF.
bool hasPrivateLinkage() const
Definition: GlobalValue.h:279
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
bool isWriteable() const
Definition: SectionKind.h:160
Context object for machine code objects.
Definition: MCContext.h:48
bool isMergeable4ByteCString() const
Definition: SectionKind.h:150
MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const override
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:514
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:271
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:93
unsigned getStubSize() const
MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const override
Given a constant with the SectionKind, return a section that it should be placed in.
static SectionKind getThreadData()
Definition: SectionKind.h:222
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:446
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, Mangler &Mang, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
const Triple & getTargetTriple() const
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:79
MCSection * DataSection
Section directive for standard data.
bool isMergeableConst16() const
Definition: SectionKind.h:158
iterator begin() const
Definition: StringRef.h:90
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:97
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:254
bool isDataNoRel() const
Definition: SectionKind.h:189
.hidden (ELF)
Definition: MCDirectives.h:31
bool isMetadata() const
Definition: SectionKind.h:136
No other Module may specify this COMDAT.
Definition: Comdat.h:37
Streaming machine code generation interface.
Definition: MCStreamer.h:157
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
bool isWindowsGNUEnvironment() const
Definition: Triple.h:448
PointerIntPair - This class implements a pair of a pointer and small integer.
bool isText() const
Definition: SectionKind.h:137
const Comdat * getComdat() const
Definition: GlobalObject.h:61
This is an important base class in LLVM.
Definition: Constant.h:41
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:701
bool hasHiddenVisibility() const
Definition: GlobalValue.h:141
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isThreadData() const
Definition: SectionKind.h:169
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
bool isMergeable1ByteCString() const
Definition: SectionKind.h:148
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:688
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
iterator begin() const
Definition: ArrayRef.h:122
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
MCSection * getDrectveSection() const
SelectionKind getSelectionKind() const
Definition: Comdat.h:42
Ty & getObjFileInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:35
bool isBSSLocal() const
Definition: SectionKind.h:176
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
bool isThreadBSS() const
Definition: SectionKind.h:168
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:52
StubValueTy & getGVStubEntry(MCSymbol *Sym)
static const char * getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
StubValueTy & getGVStubEntry(MCSymbol *Sym)
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
MCSymbol * getSymbol(const GlobalValue *GV, Mangler &Mang) const
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
bool isThreadLocal() const
Definition: SectionKind.h:164
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:761
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections...
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
StringRef getString() const
Definition: Metadata.cpp:375
bool hasExternalLinkage() const
Definition: GlobalValue.h:260
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:936
PointerTy getPointer() const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:215
Comdat * getComdat()
Definition: Globals.cpp:116
static SectionKind getThreadBSS()
Definition: SectionKind.h:221
bool isFunctionTy() const
isFunctionTy - True if this is an instance of FunctionType.
Definition: Type.h:205
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:203
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI) const override
const DataLayout * getDataLayout() const
Deprecated in 3.7, will be removed in 3.8.
static SectionKind getDataNoRel()
Definition: SectionKind.h:229
Module.h This file contains the declarations for the Module class.
static const Comdat * getELFComdat(const GlobalValue *GV)
The linker will choose the largest COMDAT.
Definition: Comdat.h:36
bool getUniqueSectionNames() const
bool isMergeableConst8() const
Definition: SectionKind.h:157
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
static StringRef getSectionPrefixForGlobal(SectionKind Kind)
Return the section prefix name used by options FunctionsSections and DataSections.
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:481
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, 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...
MCSection * FourByteConstantSection
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler &Mang, const TargetMachine &TM) const override
Emit the module flags that specify the garbage collection information.
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
virtual void EmitLinkerOptions(ArrayRef< std::string > Kind)
Emit the given list Options of strings as linker options into the output.
Definition: MCStreamer.h:382
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:128
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
Definition: MCContext.cpp:428
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:108
bool isWindowsCygwinEnvironment() const
Definition: Triple.h:444
static int getSelectionForCOFF(const GlobalValue *GV)
bool hasComdat() const
Definition: GlobalValue.h:133
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:268
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler &Mang, const TargetMachine &TM) const override
Emit Obj-C garbage collection and linker options.
MCSectionELF - This represents a section on linux, lots of unix variants and some bare metal systems...
Definition: MCSectionELF.h:30
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets...
bool isCommon() const
Definition: SectionKind.h:179
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:383
bool hasLocalLinkage() const
Definition: GlobalValue.h:280
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
int64_t getConstant() const
Definition: MCValue.h:50
const ARM::ArchExtKind Kind
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465
unsigned getTypeAndAttributes() const
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:365
bool isMergeableConst4() const
Definition: SectionKind.h:156
bool isKnownWindowsMSVCEnvironment() const
Definition: Triple.h:436
iterator end() const
Definition: StringRef.h:92
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
Primary interface to the complete machine description for the target machine.
MCSection * BSSSection
Section that is default initialized to zero.
bool isReadOnlyWithRelLocal() const
Definition: SectionKind.h:195
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
A single uniqued string.
Definition: Metadata.h:508
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
static unsigned getELFSectionFlags(SectionKind K)
bool isDataRel() const
Definition: SectionKind.h:181
void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const override
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:593
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const override
Root of the metadata hierarchy.
Definition: Metadata.h:45
static SectionKind getReadOnly()
Definition: SectionKind.h:208
static unsigned getELFSectionType(StringRef Name, SectionKind K)
bool isDataRelLocal() const
Definition: SectionKind.h:185
MachineModuleInfoImpl - This class can be derived from and used by targets to hold private target-spe...
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:88
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150
bool isReadOnly() const
Definition: SectionKind.h:139
MachineModuleInfo - This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110