LLVM  13.0.0git
MCContext.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
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 #include "llvm/MC/MCContext.h"
10 #include "llvm/ADT/Optional.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/BinaryFormat/COFF.h"
17 #include "llvm/BinaryFormat/ELF.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCCodeView.h"
21 #include "llvm/MC/MCDwarf.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCFragment.h"
24 #include "llvm/MC/MCLabel.h"
26 #include "llvm/MC/MCSectionCOFF.h"
27 #include "llvm/MC/MCSectionELF.h"
28 #include "llvm/MC/MCSectionMachO.h"
29 #include "llvm/MC/MCSectionWasm.h"
30 #include "llvm/MC/MCSectionXCOFF.h"
31 #include "llvm/MC/MCStreamer.h"
32 #include "llvm/MC/MCSymbol.h"
33 #include "llvm/MC/MCSymbolCOFF.h"
34 #include "llvm/MC/MCSymbolELF.h"
35 #include "llvm/MC/MCSymbolMachO.h"
36 #include "llvm/MC/MCSymbolWasm.h"
37 #include "llvm/MC/MCSymbolXCOFF.h"
38 #include "llvm/MC/SectionKind.h"
39 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Path.h"
44 #include "llvm/Support/Signals.h"
45 #include "llvm/Support/SourceMgr.h"
47 #include <cassert>
48 #include <cstdlib>
49 #include <tuple>
50 #include <utility>
51 
52 using namespace llvm;
53 
54 static cl::opt<char*>
55 AsSecureLogFileName("as-secure-log-file-name",
56  cl::desc("As secure log file name (initialized from "
57  "AS_SECURE_LOG_FILE env variable)"),
58  cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden);
59 
60 static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
61  std::vector<const MDNode *> &) {
62  SMD.print(nullptr, errs());
63 }
64 
65 MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
66  const MCRegisterInfo *mri, const MCObjectFileInfo *mofi,
67  const MCSubtargetInfo *msti, const SourceMgr *mgr,
68  MCTargetOptions const *TargetOpts, bool DoAutoReset)
69  : TT(TheTriple), SrcMgr(mgr), InlineSrcMgr(nullptr),
70  DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MOFI(mofi),
71  MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
72  InlineAsmUsedLabelNames(Allocator),
73  CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
74  AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
75  SecureLogFile = AsSecureLogFileName;
76 
77  if (SrcMgr && SrcMgr->getNumBuffers())
78  MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())
80 
81  switch (TheTriple.getObjectFormat()) {
82  case Triple::MachO:
83  Env = IsMachO;
84  break;
85  case Triple::COFF:
86  if (!TheTriple.isOSWindows())
88  "Cannot initialize MC for non-Windows COFF object files.");
89 
90  Env = IsCOFF;
91  break;
92  case Triple::ELF:
93  Env = IsELF;
94  break;
95  case Triple::Wasm:
96  Env = IsWasm;
97  break;
98  case Triple::XCOFF:
99  Env = IsXCOFF;
100  break;
101  case Triple::GOFF:
102  report_fatal_error("Cannot initialize MC for GOFF object file format");
103  break;
105  report_fatal_error("Cannot initialize MC for unknown object file format.");
106  break;
107  }
108 }
109 
111  if (AutoReset)
112  reset();
113 
114  // NOTE: The symbols are all allocated out of a bump pointer allocator,
115  // we don't need to free them here.
116 }
117 
119  if (!InlineSrcMgr)
120  InlineSrcMgr.reset(new SourceMgr());
121 }
122 
123 //===----------------------------------------------------------------------===//
124 // Module Lifetime Management
125 //===----------------------------------------------------------------------===//
126 
128  SrcMgr = nullptr;
129  InlineSrcMgr.reset();
130  LocInfos.clear();
131  DiagHandler = defaultDiagHandler;
132 
133  // Call the destructors so the fragments are freed
134  COFFAllocator.DestroyAll();
135  ELFAllocator.DestroyAll();
136  MachOAllocator.DestroyAll();
137  XCOFFAllocator.DestroyAll();
138  MCInstAllocator.DestroyAll();
139 
140  MCSubtargetAllocator.DestroyAll();
141  InlineAsmUsedLabelNames.clear();
142  UsedNames.clear();
143  Symbols.clear();
144  Allocator.Reset();
145  Instances.clear();
146  CompilationDir.clear();
147  MainFileName.clear();
148  MCDwarfLineTablesCUMap.clear();
149  SectionsForRanges.clear();
150  MCGenDwarfLabelEntries.clear();
151  DwarfDebugFlags = StringRef();
152  DwarfCompileUnitID = 0;
153  CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
154 
155  CVContext.reset();
156 
157  MachOUniquingMap.clear();
158  ELFUniquingMap.clear();
159  COFFUniquingMap.clear();
160  WasmUniquingMap.clear();
161  XCOFFUniquingMap.clear();
162 
163  ELFEntrySizeMap.clear();
164  ELFSeenGenericMergeableSections.clear();
165 
166  NextID.clear();
167  AllowTemporaryLabels = true;
168  DwarfLocSeen = false;
169  GenDwarfForAssembly = false;
170  GenDwarfFileNumber = 0;
171 
172  HadError = false;
173 }
174 
175 //===----------------------------------------------------------------------===//
176 // MCInst Management
177 //===----------------------------------------------------------------------===//
178 
180  return new (MCInstAllocator.Allocate()) MCInst;
181 }
182 
183 //===----------------------------------------------------------------------===//
184 // Symbol Manipulation
185 //===----------------------------------------------------------------------===//
186 
188  SmallString<128> NameSV;
189  StringRef NameRef = Name.toStringRef(NameSV);
190 
191  assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
192 
193  MCSymbol *&Sym = Symbols[NameRef];
194  if (!Sym)
195  Sym = createSymbol(NameRef, false, false);
196 
197  return Sym;
198 }
199 
201  unsigned Idx) {
202  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
203  "$frame_escape_" + Twine(Idx));
204 }
205 
207  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
208  "$parent_frame_offset");
209 }
210 
212  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
213  FuncName);
214 }
215 
216 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
217  bool IsTemporary) {
218  static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
219  "MCSymbol classes must be trivially destructible");
220  static_assert(std::is_trivially_destructible<MCSymbolELF>(),
221  "MCSymbol classes must be trivially destructible");
222  static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
223  "MCSymbol classes must be trivially destructible");
224  static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
225  "MCSymbol classes must be trivially destructible");
226  static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
227  "MCSymbol classes must be trivially destructible");
228 
229  switch (getObjectFileType()) {
230  case MCContext::IsCOFF:
231  return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
232  case MCContext::IsELF:
233  return new (Name, *this) MCSymbolELF(Name, IsTemporary);
234  case MCContext::IsMachO:
235  return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
236  case MCContext::IsWasm:
237  return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
238  case MCContext::IsXCOFF:
239  return createXCOFFSymbolImpl(Name, IsTemporary);
240  }
241  return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
242  IsTemporary);
243 }
244 
245 MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
246  bool CanBeUnnamed) {
247  if (CanBeUnnamed && !UseNamesOnTempLabels)
248  return createSymbolImpl(nullptr, true);
249 
250  // Determine whether this is a user written assembler temporary or normal
251  // label, if used.
252  bool IsTemporary = CanBeUnnamed;
253  if (AllowTemporaryLabels && !IsTemporary)
254  IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
255 
256  SmallString<128> NewName = Name;
257  bool AddSuffix = AlwaysAddSuffix;
258  unsigned &NextUniqueID = NextID[Name];
259  while (true) {
260  if (AddSuffix) {
261  NewName.resize(Name.size());
262  raw_svector_ostream(NewName) << NextUniqueID++;
263  }
264  auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
265  if (NameEntry.second || !NameEntry.first->second) {
266  // Ok, we found a name.
267  // Mark it as used for a non-section symbol.
268  NameEntry.first->second = true;
269  // Have the MCSymbol object itself refer to the copy of the string that is
270  // embedded in the UsedNames entry.
271  return createSymbolImpl(&*NameEntry.first, IsTemporary);
272  }
273  assert(IsTemporary && "Cannot rename non-temporary symbols");
274  AddSuffix = true;
275  }
276  llvm_unreachable("Infinite loop");
277 }
278 
279 MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
280  SmallString<128> NameSV;
281  raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
282  return createSymbol(NameSV, AlwaysAddSuffix, true);
283 }
284 
286  SmallString<128> NameSV;
287  raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
288  return createSymbol(NameSV, true, false);
289 }
290 
292  SmallString<128> NameSV;
293  raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
294  return createSymbol(NameSV, true, false);
295 }
296 
298 
300  return createNamedTempSymbol("tmp");
301 }
302 
303 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
304  MCLabel *&Label = Instances[LocalLabelVal];
305  if (!Label)
306  Label = new (*this) MCLabel(0);
307  return Label->incInstance();
308 }
309 
310 unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
311  MCLabel *&Label = Instances[LocalLabelVal];
312  if (!Label)
313  Label = new (*this) MCLabel(0);
314  return Label->getInstance();
315 }
316 
317 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
318  unsigned Instance) {
319  MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
320  if (!Sym)
321  Sym = createNamedTempSymbol();
322  return Sym;
323 }
324 
326  unsigned Instance = NextInstance(LocalLabelVal);
327  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
328 }
329 
331  bool Before) {
332  unsigned Instance = GetInstance(LocalLabelVal);
333  if (!Before)
334  ++Instance;
335  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
336 }
337 
339  SmallString<128> NameSV;
340  StringRef NameRef = Name.toStringRef(NameSV);
341  return Symbols.lookup(NameRef);
342 }
343 
345  StringRef Sym,
346  uint64_t Val) {
347  auto Symbol = getOrCreateSymbol(Sym);
348  Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
349 }
350 
352  InlineAsmUsedLabelNames[Sym->getName()] = Sym;
353 }
354 
356 MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
357  bool IsTemporary) {
358  if (!Name)
359  return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
360 
361  StringRef OriginalName = Name->first();
362  if (OriginalName.startswith("._Renamed..") ||
363  OriginalName.startswith("_Renamed.."))
364  reportError(SMLoc(), "invalid symbol name from source");
365 
366  if (MAI->isValidUnquotedName(OriginalName))
367  return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
368 
369  // Now we have a name that contains invalid character(s) for XCOFF symbol.
370  // Let's replace with something valid, but save the original name so that
371  // we could still use the original name in the symbol table.
372  SmallString<128> InvalidName(OriginalName);
373 
374  // If it's an entry point symbol, we will keep the '.'
375  // in front for the convention purpose. Otherwise, add "_Renamed.."
376  // as prefix to signal this is an renamed symbol.
377  const bool IsEntryPoint = !InvalidName.empty() && InvalidName[0] == '.';
378  SmallString<128> ValidName =
379  StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
380 
381  // Append the hex values of '_' and invalid characters with "_Renamed..";
382  // at the same time replace invalid characters with '_'.
383  for (size_t I = 0; I < InvalidName.size(); ++I) {
384  if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
385  raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
386  InvalidName[I] = '_';
387  }
388  }
389 
390  // Skip entry point symbol's '.' as we already have a '.' in front of
391  // "_Renamed".
392  if (IsEntryPoint)
393  ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
394  else
395  ValidName.append(InvalidName);
396 
397  auto NameEntry = UsedNames.insert(std::make_pair(ValidName, true));
398  assert((NameEntry.second || !NameEntry.first->second) &&
399  "This name is used somewhere else.");
400  // Mark the name as used for a non-section symbol.
401  NameEntry.first->second = true;
402  // Have the MCSymbol object itself refer to the copy of the string
403  // that is embedded in the UsedNames entry.
404  MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
405  MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
407  return XSym;
408 }
409 
410 //===----------------------------------------------------------------------===//
411 // Section Management
412 //===----------------------------------------------------------------------===//
413 
415  unsigned TypeAndAttributes,
416  unsigned Reserved2, SectionKind Kind,
417  const char *BeginSymName) {
418  // We unique sections by their segment/section pair. The returned section
419  // may not have the same flags as the requested section, if so this should be
420  // diagnosed by the client as an error.
421 
422  // Form the name to look up.
423  assert(Section.size() <= 16 && "section name is too long");
424  assert(!memchr(Section.data(), '\0', Section.size()) &&
425  "section name cannot contain NUL");
426 
427  // Do the lookup, if we have a hit, return it.
428  auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
429  if (!R.second)
430  return R.first->second;
431 
432  MCSymbol *Begin = nullptr;
433  if (BeginSymName)
434  Begin = createTempSymbol(BeginSymName, false);
435 
436  // Otherwise, return a new section.
437  StringRef Name = R.first->first();
438  R.first->second = new (MachOAllocator.Allocate())
439  MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
440  TypeAndAttributes, Reserved2, Kind, Begin);
441  return R.first->second;
442 }
443 
445  StringRef GroupName;
446  if (const MCSymbol *Group = Section->getGroup())
447  GroupName = Group->getName();
448 
449  // This function is only used by .debug*, which should not have the
450  // SHF_LINK_ORDER flag.
451  unsigned UniqueID = Section->getUniqueID();
452  ELFUniquingMap.erase(
453  ELFSectionKey{Section->getName(), GroupName, "", UniqueID});
454  auto I = ELFUniquingMap
455  .insert(std::make_pair(
456  ELFSectionKey{Name, GroupName, "", UniqueID}, Section))
457  .first;
458  StringRef CachedName = I->first.SectionName;
459  const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
460 }
461 
462 MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
463  unsigned Flags, SectionKind K,
464  unsigned EntrySize,
465  const MCSymbolELF *Group,
466  bool Comdat, unsigned UniqueID,
467  const MCSymbolELF *LinkedToSym) {
468  MCSymbolELF *R;
469  MCSymbol *&Sym = Symbols[Section];
470  // A section symbol can not redefine regular symbols. There may be multiple
471  // sections with the same name, in which case the first such section wins.
472  if (Sym && Sym->isDefined() &&
473  (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
474  reportError(SMLoc(), "invalid symbol redefinition");
475  if (Sym && Sym->isUndefined()) {
476  R = cast<MCSymbolELF>(Sym);
477  } else {
478  auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
479  R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
480  if (!Sym)
481  Sym = R;
482  }
483  R->setBinding(ELF::STB_LOCAL);
484  R->setType(ELF::STT_SECTION);
485 
486  auto *Ret = new (ELFAllocator.Allocate())
487  MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
488  R, LinkedToSym);
489 
490  auto *F = new MCDataFragment();
491  Ret->getFragmentList().insert(Ret->begin(), F);
492  F->setParent(Ret);
493  R->setFragment(F);
494 
495  return Ret;
496 }
497 
499  unsigned Flags, unsigned EntrySize,
500  const MCSymbolELF *Group,
501  const MCSectionELF *RelInfoSection) {
503  bool Inserted;
504  std::tie(I, Inserted) =
505  RelSecNames.insert(std::make_pair(Name.str(), true));
506 
507  return createELFSectionImpl(
508  I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
509  true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
510 }
511 
513  const Twine &Suffix, unsigned Type,
514  unsigned Flags,
515  unsigned EntrySize) {
516  return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
517  /*IsComdat=*/true);
518 }
519 
521  unsigned Flags, unsigned EntrySize,
522  const Twine &Group, bool IsComdat,
523  unsigned UniqueID,
524  const MCSymbolELF *LinkedToSym) {
525  MCSymbolELF *GroupSym = nullptr;
526  if (!Group.isTriviallyEmpty() && !Group.str().empty())
527  GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
528 
529  return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
530  UniqueID, LinkedToSym);
531 }
532 
534  unsigned Flags, unsigned EntrySize,
535  const MCSymbolELF *GroupSym,
536  bool IsComdat, unsigned UniqueID,
537  const MCSymbolELF *LinkedToSym) {
538  StringRef Group = "";
539  if (GroupSym)
540  Group = GroupSym->getName();
541  assert(!(LinkedToSym && LinkedToSym->getName().empty()));
542  // Do the lookup, if we have a hit, return it.
543  auto IterBool = ELFUniquingMap.insert(std::make_pair(
544  ELFSectionKey{Section.str(), Group,
545  LinkedToSym ? LinkedToSym->getName() : "", UniqueID},
546  nullptr));
547  auto &Entry = *IterBool.first;
548  if (!IterBool.second)
549  return Entry.second;
550 
551  StringRef CachedName = Entry.first.SectionName;
552 
554  if (Flags & ELF::SHF_ARM_PURECODE)
556  else if (Flags & ELF::SHF_EXECINSTR)
558  else
560 
561  MCSectionELF *Result =
562  createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
563  IsComdat, UniqueID, LinkedToSym);
564  Entry.second = Result;
565 
566  recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
567  Result->getUniqueID(), Result->getEntrySize());
568 
569  return Result;
570 }
571 
573  bool IsComdat) {
574  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
575  SectionKind::getReadOnly(), 4, Group, IsComdat,
576  MCSection::NonUniqueID, nullptr);
577 }
578 
580  unsigned Flags, unsigned UniqueID,
581  unsigned EntrySize) {
582  bool IsMergeable = Flags & ELF::SHF_MERGE;
583  if (IsMergeable && (UniqueID == GenericSectionID))
584  ELFSeenGenericMergeableSections.insert(SectionName);
585 
586  // For mergeable sections or non-mergeable sections with a generic mergeable
587  // section name we enter their Unique ID into the ELFEntrySizeMap so that
588  // compatible globals can be assigned to the same section.
589  if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
590  ELFEntrySizeMap.insert(std::make_pair(
591  ELFEntrySizeKey{SectionName, Flags, EntrySize}, UniqueID));
592  }
593 }
594 
596  return SectionName.startswith(".rodata.str") ||
597  SectionName.startswith(".rodata.cst");
598 }
599 
602  ELFSeenGenericMergeableSections.count(SectionName);
603 }
604 
606  unsigned Flags,
607  unsigned EntrySize) {
608  auto I = ELFEntrySizeMap.find(
609  MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
610  return (I != ELFEntrySizeMap.end()) ? Optional<unsigned>(I->second) : None;
611 }
612 
614  unsigned Characteristics,
616  StringRef COMDATSymName, int Selection,
617  unsigned UniqueID,
618  const char *BeginSymName) {
619  MCSymbol *COMDATSymbol = nullptr;
620  if (!COMDATSymName.empty()) {
621  COMDATSymbol = getOrCreateSymbol(COMDATSymName);
622  COMDATSymName = COMDATSymbol->getName();
623  }
624 
625 
626  // Do the lookup, if we have a hit, return it.
627  COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
628  auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
629  auto Iter = IterBool.first;
630  if (!IterBool.second)
631  return Iter->second;
632 
633  MCSymbol *Begin = nullptr;
634  if (BeginSymName)
635  Begin = createTempSymbol(BeginSymName, false);
636 
637  StringRef CachedName = Iter->first.SectionName;
638  MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
639  CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
640 
641  Iter->second = Result;
642  return Result;
643 }
644 
646  unsigned Characteristics,
648  const char *BeginSymName) {
650  BeginSymName);
651 }
652 
654  const MCSymbol *KeySym,
655  unsigned UniqueID) {
656  // Return the normal section if we don't have to be associative or unique.
657  if (!KeySym && UniqueID == GenericSectionID)
658  return Sec;
659 
660  // If we have a key symbol, make an associative section with the same name and
661  // kind as the normal section.
662  unsigned Characteristics = Sec->getCharacteristics();
663  if (KeySym) {
665  return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
666  KeySym->getName(),
668  }
669 
670  return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
671  UniqueID);
672 }
673 
675  unsigned Flags, const Twine &Group,
676  unsigned UniqueID,
677  const char *BeginSymName) {
678  MCSymbolWasm *GroupSym = nullptr;
679  if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
680  GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
681  GroupSym->setComdat(true);
682  }
683 
684  return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
685 }
686 
688  unsigned Flags,
689  const MCSymbolWasm *GroupSym,
690  unsigned UniqueID,
691  const char *BeginSymName) {
692  StringRef Group = "";
693  if (GroupSym)
694  Group = GroupSym->getName();
695  // Do the lookup, if we have a hit, return it.
696  auto IterBool = WasmUniquingMap.insert(
697  std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
698  auto &Entry = *IterBool.first;
699  if (!IterBool.second)
700  return Entry.second;
701 
702  StringRef CachedName = Entry.first.SectionName;
703 
704  MCSymbol *Begin = createSymbol(CachedName, true, false);
705  Symbols[Begin->getName()] = Begin;
706  cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
707 
708  MCSectionWasm *Result = new (WasmAllocator.Allocate())
709  MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
710  Entry.second = Result;
711 
712  auto *F = new MCDataFragment();
713  Result->getFragmentList().insert(Result->begin(), F);
714  F->setParent(Result);
715  Begin->setFragment(F);
716 
717  return Result;
718 }
719 
722  Optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
723  const char *BeginSymName,
725  bool IsDwarfSec = DwarfSectionSubtypeFlags.hasValue();
726  assert((IsDwarfSec != CsectProp.hasValue()) && "Invalid XCOFF section!");
727 
728  // Do the lookup. If we have a hit, return it.
729  auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
730  IsDwarfSec
731  ? XCOFFSectionKey(Section.str(), DwarfSectionSubtypeFlags.getValue())
732  : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
733  nullptr));
734  auto &Entry = *IterBool.first;
735  if (!IterBool.second) {
736  MCSectionXCOFF *ExistedEntry = Entry.second;
737  if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
738  report_fatal_error("section's multiply symbols policy does not match");
739 
740  return ExistedEntry;
741  }
742 
743  // Otherwise, return a new section.
744  StringRef CachedName = Entry.first.SectionName;
745  MCSymbolXCOFF *QualName = nullptr;
746  // Debug section don't have storage class attribute.
747  if (IsDwarfSec)
748  QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
749  else
750  QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
751  CachedName + "[" +
752  XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
753 
754  MCSymbol *Begin = nullptr;
755  if (BeginSymName)
756  Begin = createTempSymbol(BeginSymName, false);
757 
758  // QualName->getUnqualifiedName() and CachedName are the same except when
759  // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
760  MCSectionXCOFF *Result = nullptr;
761  if (IsDwarfSec)
762  Result = new (XCOFFAllocator.Allocate())
763  MCSectionXCOFF(QualName->getUnqualifiedName(), Kind, QualName,
764  DwarfSectionSubtypeFlags.getValue(), Begin, CachedName,
765  MultiSymbolsAllowed);
766  else
767  Result = new (XCOFFAllocator.Allocate())
768  MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
769  CsectProp->Type, Kind, QualName, Begin, CachedName,
770  MultiSymbolsAllowed);
771 
772  Entry.second = Result;
773 
774  auto *F = new MCDataFragment();
775  Result->getFragmentList().insert(Result->begin(), F);
776  F->setParent(Result);
777 
778  if (Begin)
779  Begin->setFragment(F);
780 
781  return Result;
782 }
783 
785  return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
786 }
787 
788 void MCContext::addDebugPrefixMapEntry(const std::string &From,
789  const std::string &To) {
790  DebugPrefixMap.insert(std::make_pair(From, To));
791 }
792 
794  const auto &DebugPrefixMap = this->DebugPrefixMap;
795  if (DebugPrefixMap.empty())
796  return;
797 
798  const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
799  SmallString<256> P(Path);
800  for (const auto &Entry : DebugPrefixMap) {
801  if (llvm::sys::path::replace_path_prefix(P, Entry.first, Entry.second)) {
802  Path = P.str().str();
803  break;
804  }
805  }
806  };
807 
808  // Remap compilation directory.
809  std::string CompDir = std::string(CompilationDir.str());
810  RemapDebugPath(CompDir);
811  CompilationDir = CompDir;
812 
813  // Remap MCDwarfDirs in all compilation units.
814  for (auto &CUIDTablePair : MCDwarfLineTablesCUMap)
815  for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
816  RemapDebugPath(Dir);
817 }
818 
819 //===----------------------------------------------------------------------===//
820 // Dwarf Management
821 //===----------------------------------------------------------------------===//
822 
824  // MCDwarf needs the root file as well as the compilation directory.
825  // If we find a '.file 0' directive that will supersede these values.
827  if (getDwarfVersion() >= 5) {
828  MD5 Hash;
829  MD5::MD5Result Sum;
830  Hash.update(Buffer);
831  Hash.final(Sum);
832  Cksum = Sum;
833  }
834  // Canonicalize the root filename. It cannot be empty, and should not
835  // repeat the compilation dir.
836  // The MCContext ctor initializes MainFileName to the name associated with
837  // the SrcMgr's main file ID, which might be the same as InputFileName (and
838  // possibly include directory components).
839  // Or, MainFileName might have been overridden by a -main-file-name option,
840  // which is supposed to be just a base filename with no directory component.
841  // So, if the InputFileName and MainFileName are not equal, assume
842  // MainFileName is a substitute basename and replace the last component.
843  SmallString<1024> FileNameBuf = InputFileName;
844  if (FileNameBuf.empty() || FileNameBuf == "-")
845  FileNameBuf = "<stdin>";
846  if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
849  }
850  StringRef FileName = FileNameBuf;
851  if (FileName.consume_front(getCompilationDir()))
852  if (llvm::sys::path::is_separator(FileName.front()))
853  FileName = FileName.drop_front();
854  assert(!FileName.empty());
856  /*CUID=*/0, getCompilationDir(), FileName, Cksum, None);
857 }
858 
859 /// getDwarfFile - takes a file name and number to place in the dwarf file and
860 /// directory tables. If the file number has already been allocated it is an
861 /// error and zero is returned and the client reports the error, else the
862 /// allocated file number is returned. The file numbers may be in any order.
864  StringRef FileName,
865  unsigned FileNumber,
866  Optional<MD5::MD5Result> Checksum,
868  unsigned CUID) {
869  MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
870  return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
871  FileNumber);
872 }
873 
874 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
875 /// currently is assigned and false otherwise.
876 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
877  const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
878  if (FileNumber == 0)
879  return getDwarfVersion() >= 5;
880  if (FileNumber >= LineTable.getMCDwarfFiles().size())
881  return false;
882 
883  return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
884 }
885 
886 /// Remove empty sections from SectionsForRanges, to avoid generating
887 /// useless debug info for them.
889  SectionsForRanges.remove_if(
890  [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
891 }
892 
894  if (!CVContext.get())
895  CVContext.reset(new CodeViewContext);
896  return *CVContext.get();
897 }
898 
899 //===----------------------------------------------------------------------===//
900 // Error Reporting
901 //===----------------------------------------------------------------------===//
902 
904  assert(DiagHandler && "MCContext::DiagHandler is not set");
905  bool UseInlineSrcMgr = false;
906  const SourceMgr *SMP = nullptr;
907  if (SrcMgr) {
908  SMP = SrcMgr;
909  } else if (InlineSrcMgr) {
910  SMP = InlineSrcMgr.get();
911  UseInlineSrcMgr = true;
912  } else
913  llvm_unreachable("Either SourceMgr should be available");
914  DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
915 }
916 
917 void MCContext::reportCommon(
918  SMLoc Loc,
919  std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
920  // * MCContext::SrcMgr is null when the MC layer emits machine code for input
921  // other than assembly file, say, for .c/.cpp/.ll/.bc.
922  // * MCContext::InlineSrcMgr is null when the inline asm is not used.
923  // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
924  // and MCContext::InlineSrcMgr are null.
925  SourceMgr SM;
926  const SourceMgr *SMP = &SM;
927  bool UseInlineSrcMgr = false;
928 
929  // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
930  // For MC-only execution, only SrcMgr is used;
931  // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
932  // inline asm in the IR.
933  if (Loc.isValid()) {
934  if (SrcMgr) {
935  SMP = SrcMgr;
936  } else if (InlineSrcMgr) {
937  SMP = InlineSrcMgr.get();
938  UseInlineSrcMgr = true;
939  } else
940  llvm_unreachable("Either SourceMgr should be available");
941  }
942 
943  SMDiagnostic D;
944  GetMessage(D, SMP);
945  DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
946 }
947 
948 void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
949  HadError = true;
950  reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
951  D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
952  });
953 }
954 
955 void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
956  if (TargetOptions && TargetOptions->MCNoWarn)
957  return;
958  if (TargetOptions && TargetOptions->MCFatalWarnings) {
959  reportError(Loc, Msg);
960  } else {
961  reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
962  D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
963  });
964  }
965 }
966 
967 void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
968  reportError(Loc, Msg);
969 
970  // If we reached here, we are failing ungracefully. Run the interrupt handlers
971  // to make sure any special cleanups get done, in particular that we remove
972  // files registered with RemoveFileOnSignal.
974  exit(1);
975 }
llvm::MCDwarfLineTable::tryGetFile
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:532
MemoryBuffer.h
llvm::wasm::WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:355
llvm::Triple::Wasm
@ Wasm
Definition: Triple.h:238
llvm::MCAsmInfo::isAcceptableChar
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:115
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:289
llvm::MCAsmInfo::getLinkerPrivateGlobalPrefix
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:638
Signals.h
MCDwarf.h
llvm
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::sys::path::replace_path_prefix
bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
Definition: Path.cpp:516
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
llvm::MCSectionXCOFF
Definition: MCSectionXCOFF.h:32
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:98
llvm::SectionKind::getExecuteOnly
static SectionKind getExecuteOnly()
Definition: SectionKind.h:184
Optional.h
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:190
llvm::MCSymbol::SymbolKindUnset
@ SymbolKindUnset
Definition: MCSymbol.h:46
llvm::BumpPtrAllocatorImpl::Reset
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition: Allocator.h:125
llvm::MCContext::getCVContext
CodeViewContext & getCVContext()
Definition: MCContext.cpp:893
llvm::TargetOptions
Definition: TargetOptions.h:119
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::MCContext::getOrCreateParentFrameOffsetSymbol
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:206
llvm::XCOFF::DwarfSectionSubtypeFlags
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:89
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::MCAsmInfo::getPrivateGlobalPrefix
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:631
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
MCSectionELF.h
llvm::MCSection::getBeginSymbol
MCSymbol * getBeginSymbol()
Definition: MCSection.h:120
Path.h
llvm::MCContext::setGenDwarfRootFile
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:823
ErrorHandling.h
llvm::MCSymbolXCOFF::getUnqualifiedName
static StringRef getUnqualifiedName(StringRef Name)
Definition: MCSymbolXCOFF.h:27
MCSectionCOFF.h
MCFragment.h
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1133
llvm::MCSymbol::isUndefined
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:251
llvm::StringRef::consume_front
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:683
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
COFF.h
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
MCObjectFileInfo.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::Twine::isTriviallyEmpty
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
Definition: Twine.h:400
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:242
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:519
llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:411
llvm::Optional< unsigned >
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::Triple::XCOFF
@ XCOFF
Definition: Triple.h:239
llvm::MCSymbolXCOFF::setSymbolTableName
void setSymbolTableName(StringRef STN)
Definition: MCSymbolXCOFF.h:59
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::MCContext::IsMachO
@ IsMachO
Definition: MCContext.h:77
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::ELF::STT_SECTION
@ STT_SECTION
Definition: ELF.h:1148
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::sys::RunInterruptHandlers
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::MCContext::createNamedTempSymbol
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:299
llvm::MCContext::diagnose
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:903
llvm::MCContext::lookupSymbol
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:338
llvm::MCContext::isELFImplicitMergeableSectionNamePrefix
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:595
llvm::MCContext::getDwarfFile
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:863
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:180
llvm::MCContext::setSymbolValue
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:344
llvm::MCContext::getOrCreateLSDASymbol
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
Definition: MCContext.cpp:211
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:414
llvm::MCSymbolELF
Definition: MCSymbolELF.h:14
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:286
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:454
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
XCOFF.h
llvm::SectionKind::getReadOnly
static SectionKind getReadOnly()
Definition: SectionKind.h:185
CommandLine.h
llvm::MCContext::IsWasm
@ IsWasm
Definition: MCContext.h:77
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:88
llvm::MCContext::IsXCOFF
@ IsXCOFF
Definition: MCContext.h:77
llvm::MCContext::getOrCreateSymbol
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:187
llvm::MCSectionXCOFF::isMultiSymbolsAllowed
bool isMultiSymbolsAllowed() const
Definition: MCSectionXCOFF.h:110
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:235
ELF.h
llvm::MCContext::isELFGenericMergeableSection
bool isELFGenericMergeableSection(StringRef Name)
Definition: MCContext.cpp:600
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:261
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
SmallString.h
llvm::MCSectionWasm
This represents a section on wasm.
Definition: MCSectionWasm.h:26
MCSymbolWasm.h
Twine.h
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:276
MCSymbolELF.h
MCContext.h
llvm::CodeViewContext
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:137
llvm::SrcMgr
SourceMgr SrcMgr
Definition: Error.cpp:24
MCSectionMachO.h
llvm::MCContext::createMCInst
MCInst * createMCInst()
Create and return a new MC instruction.
Definition: MCContext.cpp:179
MCSymbol.h
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:251
defaultDiagHandler
static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &, std::vector< const MDNode * > &)
Definition: MCContext.cpp:60
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:536
llvm::MCSymbolWasm::setComdat
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:77
llvm::MCContext::getObjectFileType
Environment getObjectFileType() const
Definition: MCContext.h:405
llvm::MCContext::getDwarfVersion
uint16_t getDwarfVersion() const
Definition: MCContext.h:784
llvm::MCSymbolCOFF
Definition: MCSymbolCOFF.h:17
llvm::MCDwarfLineTable
Definition: MCDwarf.h:308
llvm::MCStreamer::emitAssignment
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:1027
llvm::StringMap::clear
void clear()
Definition: StringMap.h:333
llvm::Triple::getObjectFormat
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Definition: Triple.h:337
llvm::report_fatal_error
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::MCContext::getCompilationDir
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:653
llvm::MCContext::getXCOFFSection
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, Optional< XCOFF::CsectProperties > CsectProp=None, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, Optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=None)
Definition: MCContext.cpp:720
llvm::AMDGPU::ElfNote::SectionName
const char SectionName[]
Definition: AMDGPUPTNote.h:24
llvm::SourceMgr::getMainFileID
unsigned getMainFileID() const
Definition: SourceMgr.h:129
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:606
llvm::MCContext::registerInlineAsmLabel
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:351
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:197
StringMap.h
llvm::SectionKind::getText
static SectionKind getText()
Definition: SectionKind.h:183
llvm::Comdat
Definition: Comdat.h:31
llvm::XCOFF::getMappingClassString
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:18
llvm::Triple::GOFF
@ GOFF
Definition: Triple.h:236
llvm::MCContext::reportFatalError
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:967
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:653
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
SourceMgr.h
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::SmallString< 128 >
llvm::SourceMgr::getMemoryBuffer
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:122
llvm::Twine::str
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
llvm::MemoryBuffer::getBufferIdentifier
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:75
llvm::MCContext::MCContext
MCContext(const Triple &TheTriple, const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const MCSubtargetInfo *MSTI, const SourceMgr *Mgr=nullptr, MCTargetOptions const *TargetOpts=nullptr, bool DoAutoReset=true)
Definition: MCContext.cpp:65
llvm::MCContext::RemapDebugPaths
void RemapDebugPaths()
Definition: MCContext.cpp:793
llvm::SmallString::append
void append(StringRef RHS)
Append from a StringRef.
Definition: SmallString.h:67
llvm::MCSectionCOFF::getCharacteristics
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:66
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::Triple::ELF
@ ELF
Definition: Triple.h:235
llvm::SMDiagnostic::print
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Definition: SourceMgr.cpp:473
llvm::SMLoc::isValid
bool isValid() const
Definition: SMLoc.h:29
llvm::MCContext::getMCDwarfLineTable
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:684
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::MCContext::IsELF
@ IsELF
Definition: MCContext.h:77
llvm::SourceMgr::DK_Warning
@ DK_Warning
Definition: SourceMgr.h:35
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
llvm::MD5
Definition: MD5.h:41
MCSymbolXCOFF.h
llvm::StringRef::front
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:164
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::StringMap::lookup
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:234
llvm::MCContext::createLinkerPrivateTempSymbol
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:291
llvm::MCAsmInfo::isValidUnquotedName
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:119
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::MCSection::NonUniqueID
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
llvm::MCContext::createELFGroupSection
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:572
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCSectionCOFF
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
AsSecureLogFileName
static cl::opt< char * > AsSecureLogFileName("as-secure-log-file-name", cl::desc("As secure log file name (initialized from " "AS_SECURE_LOG_FILE env variable)"), cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden)
llvm::COFF::IMAGE_SCN_LNK_COMDAT
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:294
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:948
MCSymbolMachO.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::MCDwarfLineTable::getMCDwarfFiles
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:368
llvm::MCTargetOptions
Definition: MCTargetOptions.h:36
llvm::MCContext::getOrCreateFrameAllocSymbol
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
Definition: MCContext.cpp:200
llvm::MCContext::recordELFMergeableSectionInfo
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
Definition: MCContext.cpp:579
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:99
llvm::MCContext::initInlineSourceManager
void initInlineSourceManager()
Definition: MCContext.cpp:118
llvm::MCDwarfLoc
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:76
DiagHandler
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
Definition: TextStub.cpp:1095
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCSymbolXCOFF::getUnqualifiedName
StringRef getUnqualifiedName() const
Definition: MCSymbolXCOFF.h:47
llvm::MCContext::isValidDwarfFileNumber
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
Definition: MCContext.cpp:876
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
llvm::MCContext::setMCLineTableRootFile
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Definition: MCContext.h:710
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
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:613
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:297
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::MCContext::IsCOFF
@ IsCOFF
Definition: MCContext.h:77
llvm::MCContext::getDirectionalLocalSymbol
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Definition: MCContext.cpp:330
llvm::MCLabel
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
Definition: MCLabel.h:23
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:115
llvm::Triple::isOSWindows
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:547
llvm::MD5::MD5Result
Definition: MD5.h:55
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:254
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
MCCodeView.h
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:654
llvm::ELF::SHT_GROUP
@ SHT_GROUP
Definition: ELF.h:919
llvm::SectionName
Definition: DWARFSection.h:21
llvm::MCSectionMachO
This represents a section on a Mach-O system (used by Mac OS X).
Definition: MCSectionMachO.h:24
llvm::ELF::SHF_ARM_PURECODE
@ SHF_ARM_PURECODE
Definition: ELF.h:1075
Casting.h
llvm::Triple::MachO
@ MachO
Definition: Triple.h:237
llvm::MCContext::renameELFSection
void renameELFSection(MCSectionELF *Section, StringRef Name)
Definition: MCContext.cpp:444
MCSymbolCOFF.h
llvm::SourceMgr::DK_Error
@ DK_Error
Definition: SourceMgr.h:34
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:986
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:259
llvm::SourceMgr::GetMessage
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
Definition: SourceMgr.cpp:262
SectionKind.h
llvm::MCContext::getWasmSection
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:613
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
Selection
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
Definition: AMDGPUISelDAGToDAG.cpp:376
llvm::MCSection::getKind
SectionKind getKind() const
Definition: MCSection.h:116
llvm::XCOFF::CsectProperties::Type
SymbolType Type
Definition: XCOFF.h:413
llvm::sys::path::is_separator
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Definition: Path.cpp:599
llvm::ELF::SHF_MERGE
@ SHF_MERGE
Definition: ELF.h:989
llvm::Triple::COFF
@ COFF
Definition: Triple.h:234
llvm::XCOFF::CsectProperties::MappingClass
StorageMappingClass MappingClass
Definition: XCOFF.h:412
SmallVector.h
llvm::MCSymbolXCOFF
Definition: MCSymbolXCOFF.h:20
llvm::MCSymbol::setFragment
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:267
exit
declare void exit(i32) noreturn nounwind This compiles into
Definition: README.txt:1072
llvm::MCContext::getMainFileName
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:667
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
MCStreamer.h
llvm::MCContext::getELFUniqueIDForEntsize
Optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Definition: MCContext.cpp:605
llvm::MCSymbol::isInSection
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:246
Characteristics
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:325
llvm::MCContext::addDebugPrefixMapEntry
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:788
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:647
llvm::MCStreamer::mayHaveInstructions
virtual bool mayHaveInstructions(MCSection &Sec) const
Definition: MCStreamer.h:1079
llvm::MCContext::getSubtargetCopy
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:784
llvm::sys::path::remove_filename
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition: Path.cpp:472
llvm::MCContext::reset
void reset()
reset - return object to right after construction state to prepare to process a new module
Definition: MCContext.cpp:127
llvm::MCContext::createELFRelSection
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:498
llvm::MCContext::createDirectionalLocalSymbol
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
Definition: MCContext.cpp:325
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::MCSymbolMachO
Definition: MCSymbolMachO.h:15
llvm::cl::desc
Definition: CommandLine.h:414
llvm::MCContext::getELFNamedSection
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition: MCContext.cpp:512
llvm::MCContext::~MCContext
~MCContext()
Definition: MCContext.cpp:110
raw_ostream.h
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCObjectFileInfo
Definition: MCObjectFileInfo.h:26
MCLabel.h
llvm::SourceMgr::getNumBuffers
unsigned getNumBuffers() const
Definition: SourceMgr.h:127
llvm::MCContext::finalizeDwarfSections
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:888
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:165
MCSectionWasm.h
llvm::MCContext::reportWarning
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:955
llvm::raw_ostream::write_hex
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
Definition: raw_ostream.cpp:140
llvm::Triple::UnknownObjectFormat
@ UnknownObjectFormat
Definition: Triple.h:232