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