LLVM  9.0.0svn
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"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCCodeView.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCFragment.h"
23 #include "llvm/MC/MCLabel.h"
25 #include "llvm/MC/MCSectionCOFF.h"
26 #include "llvm/MC/MCSectionELF.h"
27 #include "llvm/MC/MCSectionMachO.h"
28 #include "llvm/MC/MCSectionWasm.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/MC/MCSymbolCOFF.h"
32 #include "llvm/MC/MCSymbolELF.h"
33 #include "llvm/MC/MCSymbolMachO.h"
34 #include "llvm/MC/MCSymbolWasm.h"
35 #include "llvm/MC/SectionKind.h"
36 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/Path.h"
41 #include "llvm/Support/Signals.h"
42 #include "llvm/Support/SourceMgr.h"
44 #include <cassert>
45 #include <cstdlib>
46 #include <tuple>
47 #include <utility>
48 
49 using namespace llvm;
50 
51 static cl::opt<char*>
52 AsSecureLogFileName("as-secure-log-file-name",
53  cl::desc("As secure log file name (initialized from "
54  "AS_SECURE_LOG_FILE env variable)"),
55  cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden);
56 
58  const MCObjectFileInfo *mofi, const SourceMgr *mgr,
59  bool DoAutoReset)
60  : SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
61  Symbols(Allocator), UsedNames(Allocator),
62  CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
63  AutoReset(DoAutoReset) {
64  SecureLogFile = AsSecureLogFileName;
65 
66  if (SrcMgr && SrcMgr->getNumBuffers())
67  MainFileName =
68  SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
69 }
70 
72  if (AutoReset)
73  reset();
74 
75  // NOTE: The symbols are all allocated out of a bump pointer allocator,
76  // we don't need to free them here.
77 }
78 
79 //===----------------------------------------------------------------------===//
80 // Module Lifetime Management
81 //===----------------------------------------------------------------------===//
82 
84  // Call the destructors so the fragments are freed
85  COFFAllocator.DestroyAll();
86  ELFAllocator.DestroyAll();
87  MachOAllocator.DestroyAll();
88 
89  MCSubtargetAllocator.DestroyAll();
90  UsedNames.clear();
91  Symbols.clear();
92  Allocator.Reset();
93  Instances.clear();
94  CompilationDir.clear();
95  MainFileName.clear();
96  MCDwarfLineTablesCUMap.clear();
97  SectionsForRanges.clear();
98  MCGenDwarfLabelEntries.clear();
99  DwarfDebugFlags = StringRef();
100  DwarfCompileUnitID = 0;
101  CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
102 
103  CVContext.reset();
104 
105  MachOUniquingMap.clear();
106  ELFUniquingMap.clear();
107  COFFUniquingMap.clear();
108  WasmUniquingMap.clear();
109 
110  NextID.clear();
111  AllowTemporaryLabels = true;
112  DwarfLocSeen = false;
113  GenDwarfForAssembly = false;
114  GenDwarfFileNumber = 0;
115 
116  HadError = false;
117 }
118 
119 //===----------------------------------------------------------------------===//
120 // Symbol Manipulation
121 //===----------------------------------------------------------------------===//
122 
124  SmallString<128> NameSV;
125  StringRef NameRef = Name.toStringRef(NameSV);
126 
127  assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
128 
129  MCSymbol *&Sym = Symbols[NameRef];
130  if (!Sym)
131  Sym = createSymbol(NameRef, false, false);
132 
133  return Sym;
134 }
135 
137  unsigned Idx) {
138  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
139  "$frame_escape_" + Twine(Idx));
140 }
141 
143  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
144  "$parent_frame_offset");
145 }
146 
148  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
149  FuncName);
150 }
151 
152 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
153  bool IsTemporary) {
154  if (MOFI) {
155  switch (MOFI->getObjectFileType()) {
157  return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
159  return new (Name, *this) MCSymbolELF(Name, IsTemporary);
161  return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
163  return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
165  // TODO: Need to implement class MCSymbolXCOFF.
166  break;
167  }
168  }
169  return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
170  IsTemporary);
171 }
172 
173 MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
174  bool CanBeUnnamed) {
175  if (CanBeUnnamed && !UseNamesOnTempLabels)
176  return createSymbolImpl(nullptr, true);
177 
178  // Determine whether this is a user written assembler temporary or normal
179  // label, if used.
180  bool IsTemporary = CanBeUnnamed;
181  if (AllowTemporaryLabels && !IsTemporary)
182  IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
183 
184  SmallString<128> NewName = Name;
185  bool AddSuffix = AlwaysAddSuffix;
186  unsigned &NextUniqueID = NextID[Name];
187  while (true) {
188  if (AddSuffix) {
189  NewName.resize(Name.size());
190  raw_svector_ostream(NewName) << NextUniqueID++;
191  }
192  auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
193  if (NameEntry.second || !NameEntry.first->second) {
194  // Ok, we found a name.
195  // Mark it as used for a non-section symbol.
196  NameEntry.first->second = true;
197  // Have the MCSymbol object itself refer to the copy of the string that is
198  // embedded in the UsedNames entry.
199  return createSymbolImpl(&*NameEntry.first, IsTemporary);
200  }
201  assert(IsTemporary && "Cannot rename non-temporary symbols");
202  AddSuffix = true;
203  }
204  llvm_unreachable("Infinite loop");
205 }
206 
207 MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
208  bool CanBeUnnamed) {
209  SmallString<128> NameSV;
210  raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
211  return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
212 }
213 
215  SmallString<128> NameSV;
216  raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
217  return createSymbol(NameSV, true, false);
218 }
219 
221  return createTempSymbol("tmp", true, CanBeUnnamed);
222 }
223 
224 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
225  MCLabel *&Label = Instances[LocalLabelVal];
226  if (!Label)
227  Label = new (*this) MCLabel(0);
228  return Label->incInstance();
229 }
230 
231 unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
232  MCLabel *&Label = Instances[LocalLabelVal];
233  if (!Label)
234  Label = new (*this) MCLabel(0);
235  return Label->getInstance();
236 }
237 
238 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
239  unsigned Instance) {
240  MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
241  if (!Sym)
242  Sym = createTempSymbol(false);
243  return Sym;
244 }
245 
247  unsigned Instance = NextInstance(LocalLabelVal);
248  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
249 }
250 
252  bool Before) {
253  unsigned Instance = GetInstance(LocalLabelVal);
254  if (!Before)
255  ++Instance;
256  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
257 }
258 
260  SmallString<128> NameSV;
261  StringRef NameRef = Name.toStringRef(NameSV);
262  return Symbols.lookup(NameRef);
263 }
264 
266  StringRef Sym,
267  uint64_t Val) {
268  auto Symbol = getOrCreateSymbol(Sym);
269  Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
270 }
271 
272 //===----------------------------------------------------------------------===//
273 // Section Management
274 //===----------------------------------------------------------------------===//
275 
277  unsigned TypeAndAttributes,
278  unsigned Reserved2, SectionKind Kind,
279  const char *BeginSymName) {
280  // We unique sections by their segment/section pair. The returned section
281  // may not have the same flags as the requested section, if so this should be
282  // diagnosed by the client as an error.
283 
284  // Form the name to look up.
286  Name += Segment;
287  Name.push_back(',');
288  Name += Section;
289 
290  // Do the lookup, if we have a hit, return it.
291  MCSectionMachO *&Entry = MachOUniquingMap[Name];
292  if (Entry)
293  return Entry;
294 
295  MCSymbol *Begin = nullptr;
296  if (BeginSymName)
297  Begin = createTempSymbol(BeginSymName, false);
298 
299  // Otherwise, return a new section.
300  return Entry = new (MachOAllocator.Allocate()) MCSectionMachO(
301  Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
302 }
303 
305  StringRef GroupName;
306  if (const MCSymbol *Group = Section->getGroup())
307  GroupName = Group->getName();
308 
309  unsigned UniqueID = Section->getUniqueID();
310  ELFUniquingMap.erase(
311  ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});
312  auto I = ELFUniquingMap.insert(std::make_pair(
313  ELFSectionKey{Name, GroupName, UniqueID},
314  Section))
315  .first;
316  StringRef CachedName = I->first.SectionName;
317  const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
318 }
319 
320 MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
321  unsigned Flags, SectionKind K,
322  unsigned EntrySize,
323  const MCSymbolELF *Group,
324  unsigned UniqueID,
325  const MCSymbolELF *Associated) {
326  MCSymbolELF *R;
327  MCSymbol *&Sym = Symbols[Section];
328  // A section symbol can not redefine regular symbols. There may be multiple
329  // sections with the same name, in which case the first such section wins.
330  if (Sym && Sym->isDefined() &&
331  (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
332  reportError(SMLoc(), "invalid symbol redefinition");
333  if (Sym && Sym->isUndefined()) {
334  R = cast<MCSymbolELF>(Sym);
335  } else {
336  auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
337  R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
338  if (!Sym)
339  Sym = R;
340  }
343 
344  auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
345  Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
346 
347  auto *F = new MCDataFragment();
348  Ret->getFragmentList().insert(Ret->begin(), F);
349  F->setParent(Ret);
350  R->setFragment(F);
351 
352  return Ret;
353 }
354 
356  unsigned Flags, unsigned EntrySize,
357  const MCSymbolELF *Group,
358  const MCSectionELF *RelInfoSection) {
360  bool Inserted;
361  std::tie(I, Inserted) =
362  RelSecNames.insert(std::make_pair(Name.str(), true));
363 
364  return createELFSectionImpl(
365  I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
366  true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
367 }
368 
370  const Twine &Suffix, unsigned Type,
371  unsigned Flags,
372  unsigned EntrySize) {
373  return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix);
374 }
375 
376 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
377  unsigned Flags, unsigned EntrySize,
378  const Twine &Group, unsigned UniqueID,
379  const MCSymbolELF *Associated) {
380  MCSymbolELF *GroupSym = nullptr;
381  if (!Group.isTriviallyEmpty() && !Group.str().empty())
382  GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
383 
384  return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
385  Associated);
386 }
387 
388 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
389  unsigned Flags, unsigned EntrySize,
390  const MCSymbolELF *GroupSym,
391  unsigned UniqueID,
392  const MCSymbolELF *Associated) {
393  StringRef Group = "";
394  if (GroupSym)
395  Group = GroupSym->getName();
396  // Do the lookup, if we have a hit, return it.
397  auto IterBool = ELFUniquingMap.insert(
398  std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr));
399  auto &Entry = *IterBool.first;
400  if (!IterBool.second)
401  return Entry.second;
402 
403  StringRef CachedName = Entry.first.SectionName;
404 
406  if (Flags & ELF::SHF_ARM_PURECODE)
408  else if (Flags & ELF::SHF_EXECINSTR)
409  Kind = SectionKind::getText();
410  else
411  Kind = SectionKind::getReadOnly();
412 
413  MCSectionELF *Result = createELFSectionImpl(
414  CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
415  Entry.second = Result;
416  return Result;
417 }
418 
420  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
421  SectionKind::getReadOnly(), 4, Group, ~0,
422  nullptr);
423 }
424 
426  unsigned Characteristics,
428  StringRef COMDATSymName, int Selection,
429  unsigned UniqueID,
430  const char *BeginSymName) {
431  MCSymbol *COMDATSymbol = nullptr;
432  if (!COMDATSymName.empty()) {
433  COMDATSymbol = getOrCreateSymbol(COMDATSymName);
434  COMDATSymName = COMDATSymbol->getName();
435  }
436 
437 
438  // Do the lookup, if we have a hit, return it.
439  COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
440  auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
441  auto Iter = IterBool.first;
442  if (!IterBool.second)
443  return Iter->second;
444 
445  MCSymbol *Begin = nullptr;
446  if (BeginSymName)
447  Begin = createTempSymbol(BeginSymName, false);
448 
449  StringRef CachedName = Iter->first.SectionName;
450  MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
451  CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
452 
453  Iter->second = Result;
454  return Result;
455 }
456 
458  unsigned Characteristics,
460  const char *BeginSymName) {
461  return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
462  BeginSymName);
463 }
464 
466  COFFSectionKey T{Section, "", 0, GenericSectionID};
467  auto Iter = COFFUniquingMap.find(T);
468  if (Iter == COFFUniquingMap.end())
469  return nullptr;
470  return Iter->second;
471 }
472 
474  const MCSymbol *KeySym,
475  unsigned UniqueID) {
476  // Return the normal section if we don't have to be associative or unique.
477  if (!KeySym && UniqueID == GenericSectionID)
478  return Sec;
479 
480  // If we have a key symbol, make an associative section with the same name and
481  // kind as the normal section.
482  unsigned Characteristics = Sec->getCharacteristics();
483  if (KeySym) {
484  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
486  Sec->getKind(), KeySym->getName(),
488  }
489 
490  return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(),
491  "", 0, UniqueID);
492 }
493 
495  const Twine &Group, unsigned UniqueID,
496  const char *BeginSymName) {
497  MCSymbolWasm *GroupSym = nullptr;
498  if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
499  GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
500  GroupSym->setComdat(true);
501  }
502 
503  return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName);
504 }
505 
507  const MCSymbolWasm *GroupSym,
508  unsigned UniqueID,
509  const char *BeginSymName) {
510  StringRef Group = "";
511  if (GroupSym)
512  Group = GroupSym->getName();
513  // Do the lookup, if we have a hit, return it.
514  auto IterBool = WasmUniquingMap.insert(
515  std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
516  auto &Entry = *IterBool.first;
517  if (!IterBool.second)
518  return Entry.second;
519 
520  StringRef CachedName = Entry.first.SectionName;
521 
522  MCSymbol *Begin = createSymbol(CachedName, false, false);
523  cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
524 
525  MCSectionWasm *Result = new (WasmAllocator.Allocate())
526  MCSectionWasm(CachedName, Kind, GroupSym, UniqueID, Begin);
527  Entry.second = Result;
528 
529  auto *F = new MCDataFragment();
530  Result->getFragmentList().insert(Result->begin(), F);
531  F->setParent(Result);
532  Begin->setFragment(F);
533 
534  return Result;
535 }
536 
538  return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
539 }
540 
541 void MCContext::addDebugPrefixMapEntry(const std::string &From,
542  const std::string &To) {
543  DebugPrefixMap.insert(std::make_pair(From, To));
544 }
545 
547  const auto &DebugPrefixMap = this->DebugPrefixMap;
548  const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
549  for (const auto &Entry : DebugPrefixMap)
550  if (StringRef(Path).startswith(Entry.first)) {
551  std::string RemappedPath =
552  (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
553  Path.swap(RemappedPath);
554  }
555  };
556 
557  // Remap compilation directory.
558  std::string CompDir = CompilationDir.str();
559  RemapDebugPath(CompDir);
560  CompilationDir = CompDir;
561 
562  // Remap MCDwarfDirs in all compilation units.
563  for (auto &CUIDTablePair : MCDwarfLineTablesCUMap)
564  for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
565  RemapDebugPath(Dir);
566 }
567 
568 //===----------------------------------------------------------------------===//
569 // Dwarf Management
570 //===----------------------------------------------------------------------===//
571 
573  // MCDwarf needs the root file as well as the compilation directory.
574  // If we find a '.file 0' directive that will supersede these values.
576  if (getDwarfVersion() >= 5) {
577  MD5 Hash;
578  MD5::MD5Result Sum;
579  Hash.update(Buffer);
580  Hash.final(Sum);
581  Cksum = Sum;
582  }
583  // Canonicalize the root filename. It cannot be empty, and should not
584  // repeat the compilation dir.
585  // The MCContext ctor initializes MainFileName to the name associated with
586  // the SrcMgr's main file ID, which might be the same as InputFileName (and
587  // possibly include directory components).
588  // Or, MainFileName might have been overridden by a -main-file-name option,
589  // which is supposed to be just a base filename with no directory component.
590  // So, if the InputFileName and MainFileName are not equal, assume
591  // MainFileName is a substitute basename and replace the last component.
592  SmallString<1024> FileNameBuf = InputFileName;
593  if (FileNameBuf.empty() || FileNameBuf == "-")
594  FileNameBuf = "<stdin>";
595  if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
598  }
599  StringRef FileName = FileNameBuf;
600  if (FileName.consume_front(getCompilationDir()))
601  if (llvm::sys::path::is_separator(FileName.front()))
602  FileName = FileName.drop_front();
603  assert(!FileName.empty());
605  /*CUID=*/0, getCompilationDir(), FileName, Cksum, None);
606 }
607 
608 /// getDwarfFile - takes a file name and number to place in the dwarf file and
609 /// directory tables. If the file number has already been allocated it is an
610 /// error and zero is returned and the client reports the error, else the
611 /// allocated file number is returned. The file numbers may be in any order.
613  StringRef FileName,
614  unsigned FileNumber,
615  Optional<MD5::MD5Result> Checksum,
617  unsigned CUID) {
618  MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
619  return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
620  FileNumber);
621 }
622 
623 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
624 /// currently is assigned and false otherwise.
625 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
626  const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
627  if (FileNumber == 0)
628  return getDwarfVersion() >= 5;
629  if (FileNumber >= LineTable.getMCDwarfFiles().size())
630  return false;
631 
632  return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
633 }
634 
635 /// Remove empty sections from SectionsForRanges, to avoid generating
636 /// useless debug info for them.
638  SectionsForRanges.remove_if(
639  [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
640 }
641 
643  if (!CVContext.get())
644  CVContext.reset(new CodeViewContext);
645  return *CVContext.get();
646 }
647 
648 //===----------------------------------------------------------------------===//
649 // Error Reporting
650 //===----------------------------------------------------------------------===//
651 
652 void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
653  HadError = true;
654 
655  // If we have a source manager use it. Otherwise, try using the inline source
656  // manager.
657  // If that fails, use the generic report_fatal_error().
658  if (SrcMgr)
659  SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
660  else if (InlineSrcMgr)
661  InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
662  else
663  report_fatal_error(Msg, false);
664 }
665 
666 void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
667  reportError(Loc, Msg);
668 
669  // If we reached here, we are failing ungracefully. Run the interrupt handlers
670  // to make sure any special cleanups get done, in particular that we remove
671  // files registered with RemoveFileOnSignal.
673  exit(1);
674 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
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:593
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:251
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:474
SectionKind getKind() const
Definition: MCSection.h:105
This represents a section on a Mach-O system (used by Mac OS X).
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:259
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:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:125
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
unsigned getNumBuffers() const
Definition: SourceMgr.h:135
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:497
void push_back(const T &Elt)
Definition: SmallVector.h:211
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:136
void reset()
reset - return object to right after construction state to prepare to process a new module ...
Definition: MCContext.cpp:83
SourceMgr SrcMgr
Definition: Error.cpp:23
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
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:455
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:649
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:453
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
Definition: MCContext.cpp:246
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:142
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:572
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
F(f)
uint16_t getDwarfVersion() const
Definition: MCContext.h:632
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:490
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
Definition: MCContext.cpp:57
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:425
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:473
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:64
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:455
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:247
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:82
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:214
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
Definition: Allocator.h:194
void renameELFSection(MCSectionELF *Section, StringRef Name)
Definition: MCContext.cpp:304
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:620
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:189
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
Definition: MCContext.cpp:637
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:251
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:272
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:523
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:916
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)
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
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:612
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:130
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:276
void RemapDebugPaths()
Definition: MCContext.cpp:546
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:70
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:70
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:666
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getMainFileID() const
Definition: SourceMgr.h:139
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
unsigned getUniqueID() const
Definition: MCSectionELF.h:84
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:359
Streaming machine code generation interface.
Definition: MCStreamer.h:188
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:220
unsigned const MachineRegisterInfo * MRI
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:75
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This represents a section on wasm.
Definition: MCSectionWasm.h:27
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
virtual bool mayHaveInstructions(MCSection &Sec) const
Definition: MCStreamer.h:979
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:652
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
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:369
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:346
Environment getObjectFileType() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
StringRef getSectionName() const
Definition: MCSectionCOFF.h:69
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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:625
void setType(unsigned Type) const
Definition: MCSymbolELF.cpp:94
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:486
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:355
unsigned incInstance()
Increment the current instance of this Directional Local Label.
Definition: MCLabel.h:40
Basic Register Allocator
BlockVerifier::State From
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
Definition: MCContext.cpp:147
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:256
void setBinding(unsigned Binding) const
Definition: MCSymbolELF.cpp:41
MCSymbol * getBeginSymbol()
Definition: MCSection.h:109
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:365
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:219
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:247
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:266
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:265
iterator insert(iterator where, pointer New)
Definition: ilist.h:226
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
unsigned getInstance() const
Get the current instance of this Directional Local Label.
Definition: MCLabel.h:37
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:541
#define I(x, y, z)
Definition: MD5.cpp:58
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:325
Generic base class for all target subtargets.
Definition: MD5.h:41
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:506
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:371
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
Definition: MCContext.cpp:419
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:202
CodeViewContext & getCVContext()
Definition: MCContext.cpp:642
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
Definition: MCLabel.h:23
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:134
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:556
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:388
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:234
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:537
Represents a location in source code.
Definition: SMLoc.h:23
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:149
static SectionKind getReadOnly()
Definition: SectionKind.h:181
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:163
StringRef getSectionName() const
Definition: MCSectionELF.h:70
iterator begin()
Definition: MCSection.h:162
static SectionKind getExecuteOnly()
Definition: SectionKind.h:180
static SectionKind getText()
Definition: SectionKind.h:179
void resize(size_type N)
Definition: SmallVector.h:344
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:537
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:137