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/Signals.h"
41 #include "llvm/Support/SourceMgr.h"
43 #include <cassert>
44 #include <cstdlib>
45 #include <tuple>
46 #include <utility>
47 
48 using namespace llvm;
49 
50 static cl::opt<char*>
51 AsSecureLogFileName("as-secure-log-file-name",
52  cl::desc("As secure log file name (initialized from "
53  "AS_SECURE_LOG_FILE env variable)"),
54  cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden);
55 
57  const MCObjectFileInfo *mofi, const SourceMgr *mgr,
58  bool DoAutoReset)
59  : SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
60  Symbols(Allocator), UsedNames(Allocator),
61  CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
62  AutoReset(DoAutoReset) {
63  SecureLogFile = AsSecureLogFileName;
64 
65  if (SrcMgr && SrcMgr->getNumBuffers())
66  MainFileName =
67  SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
68 }
69 
71  if (AutoReset)
72  reset();
73 
74  // NOTE: The symbols are all allocated out of a bump pointer allocator,
75  // we don't need to free them here.
76 }
77 
78 //===----------------------------------------------------------------------===//
79 // Module Lifetime Management
80 //===----------------------------------------------------------------------===//
81 
83  // Call the destructors so the fragments are freed
84  COFFAllocator.DestroyAll();
85  ELFAllocator.DestroyAll();
86  MachOAllocator.DestroyAll();
87 
88  MCSubtargetAllocator.DestroyAll();
89  UsedNames.clear();
90  Symbols.clear();
91  Allocator.Reset();
92  Instances.clear();
93  CompilationDir.clear();
94  MainFileName.clear();
95  MCDwarfLineTablesCUMap.clear();
96  SectionsForRanges.clear();
97  MCGenDwarfLabelEntries.clear();
98  DwarfDebugFlags = StringRef();
99  DwarfCompileUnitID = 0;
100  CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
101 
102  CVContext.reset();
103 
104  MachOUniquingMap.clear();
105  ELFUniquingMap.clear();
106  COFFUniquingMap.clear();
107  WasmUniquingMap.clear();
108 
109  NextID.clear();
110  AllowTemporaryLabels = true;
111  DwarfLocSeen = false;
112  GenDwarfForAssembly = false;
113  GenDwarfFileNumber = 0;
114 
115  HadError = false;
116 }
117 
118 //===----------------------------------------------------------------------===//
119 // Symbol Manipulation
120 //===----------------------------------------------------------------------===//
121 
123  SmallString<128> NameSV;
124  StringRef NameRef = Name.toStringRef(NameSV);
125 
126  assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
127 
128  MCSymbol *&Sym = Symbols[NameRef];
129  if (!Sym)
130  Sym = createSymbol(NameRef, false, false);
131 
132  return Sym;
133 }
134 
136  unsigned Idx) {
137  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
138  "$frame_escape_" + Twine(Idx));
139 }
140 
142  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
143  "$parent_frame_offset");
144 }
145 
147  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
148  FuncName);
149 }
150 
151 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
152  bool IsTemporary) {
153  if (MOFI) {
154  switch (MOFI->getObjectFileType()) {
156  return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
158  return new (Name, *this) MCSymbolELF(Name, IsTemporary);
160  return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
162  return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
163  }
164  }
165  return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
166  IsTemporary);
167 }
168 
169 MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
170  bool CanBeUnnamed) {
171  if (CanBeUnnamed && !UseNamesOnTempLabels)
172  return createSymbolImpl(nullptr, true);
173 
174  // Determine whether this is a user written assembler temporary or normal
175  // label, if used.
176  bool IsTemporary = CanBeUnnamed;
177  if (AllowTemporaryLabels && !IsTemporary)
178  IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
179 
180  SmallString<128> NewName = Name;
181  bool AddSuffix = AlwaysAddSuffix;
182  unsigned &NextUniqueID = NextID[Name];
183  while (true) {
184  if (AddSuffix) {
185  NewName.resize(Name.size());
186  raw_svector_ostream(NewName) << NextUniqueID++;
187  }
188  auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
189  if (NameEntry.second || !NameEntry.first->second) {
190  // Ok, we found a name.
191  // Mark it as used for a non-section symbol.
192  NameEntry.first->second = true;
193  // Have the MCSymbol object itself refer to the copy of the string that is
194  // embedded in the UsedNames entry.
195  return createSymbolImpl(&*NameEntry.first, IsTemporary);
196  }
197  assert(IsTemporary && "Cannot rename non-temporary symbols");
198  AddSuffix = true;
199  }
200  llvm_unreachable("Infinite loop");
201 }
202 
203 MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
204  bool CanBeUnnamed) {
205  SmallString<128> NameSV;
206  raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
207  return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
208 }
209 
211  SmallString<128> NameSV;
212  raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
213  return createSymbol(NameSV, true, false);
214 }
215 
217  return createTempSymbol("tmp", true, CanBeUnnamed);
218 }
219 
220 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
221  MCLabel *&Label = Instances[LocalLabelVal];
222  if (!Label)
223  Label = new (*this) MCLabel(0);
224  return Label->incInstance();
225 }
226 
227 unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
228  MCLabel *&Label = Instances[LocalLabelVal];
229  if (!Label)
230  Label = new (*this) MCLabel(0);
231  return Label->getInstance();
232 }
233 
234 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
235  unsigned Instance) {
236  MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
237  if (!Sym)
238  Sym = createTempSymbol(false);
239  return Sym;
240 }
241 
243  unsigned Instance = NextInstance(LocalLabelVal);
244  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
245 }
246 
248  bool Before) {
249  unsigned Instance = GetInstance(LocalLabelVal);
250  if (!Before)
251  ++Instance;
252  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
253 }
254 
256  SmallString<128> NameSV;
257  StringRef NameRef = Name.toStringRef(NameSV);
258  return Symbols.lookup(NameRef);
259 }
260 
262  StringRef Sym,
263  uint64_t Val) {
264  auto Symbol = getOrCreateSymbol(Sym);
265  Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
266 }
267 
268 //===----------------------------------------------------------------------===//
269 // Section Management
270 //===----------------------------------------------------------------------===//
271 
273  unsigned TypeAndAttributes,
274  unsigned Reserved2, SectionKind Kind,
275  const char *BeginSymName) {
276  // We unique sections by their segment/section pair. The returned section
277  // may not have the same flags as the requested section, if so this should be
278  // diagnosed by the client as an error.
279 
280  // Form the name to look up.
282  Name += Segment;
283  Name.push_back(',');
284  Name += Section;
285 
286  // Do the lookup, if we have a hit, return it.
287  MCSectionMachO *&Entry = MachOUniquingMap[Name];
288  if (Entry)
289  return Entry;
290 
291  MCSymbol *Begin = nullptr;
292  if (BeginSymName)
293  Begin = createTempSymbol(BeginSymName, false);
294 
295  // Otherwise, return a new section.
296  return Entry = new (MachOAllocator.Allocate()) MCSectionMachO(
297  Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
298 }
299 
301  StringRef GroupName;
302  if (const MCSymbol *Group = Section->getGroup())
303  GroupName = Group->getName();
304 
305  unsigned UniqueID = Section->getUniqueID();
306  ELFUniquingMap.erase(
307  ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});
308  auto I = ELFUniquingMap.insert(std::make_pair(
309  ELFSectionKey{Name, GroupName, UniqueID},
310  Section))
311  .first;
312  StringRef CachedName = I->first.SectionName;
313  const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
314 }
315 
316 MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
317  unsigned Flags, SectionKind K,
318  unsigned EntrySize,
319  const MCSymbolELF *Group,
320  unsigned UniqueID,
321  const MCSymbolELF *Associated) {
322  MCSymbolELF *R;
323  MCSymbol *&Sym = Symbols[Section];
324  // A section symbol can not redefine regular symbols. There may be multiple
325  // sections with the same name, in which case the first such section wins.
326  if (Sym && Sym->isDefined() &&
327  (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
328  reportError(SMLoc(), "invalid symbol redefinition");
329  if (Sym && Sym->isUndefined()) {
330  R = cast<MCSymbolELF>(Sym);
331  } else {
332  auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
333  R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
334  if (!Sym)
335  Sym = R;
336  }
339 
340  auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
341  Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
342 
343  auto *F = new MCDataFragment();
344  Ret->getFragmentList().insert(Ret->begin(), F);
345  F->setParent(Ret);
346  R->setFragment(F);
347 
348  return Ret;
349 }
350 
352  unsigned Flags, unsigned EntrySize,
353  const MCSymbolELF *Group,
354  const MCSectionELF *RelInfoSection) {
356  bool Inserted;
357  std::tie(I, Inserted) =
358  RelSecNames.insert(std::make_pair(Name.str(), true));
359 
360  return createELFSectionImpl(
361  I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
362  true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
363 }
364 
366  const Twine &Suffix, unsigned Type,
367  unsigned Flags,
368  unsigned EntrySize) {
369  return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix);
370 }
371 
372 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
373  unsigned Flags, unsigned EntrySize,
374  const Twine &Group, unsigned UniqueID,
375  const MCSymbolELF *Associated) {
376  MCSymbolELF *GroupSym = nullptr;
377  if (!Group.isTriviallyEmpty() && !Group.str().empty())
378  GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
379 
380  return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
381  Associated);
382 }
383 
384 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
385  unsigned Flags, unsigned EntrySize,
386  const MCSymbolELF *GroupSym,
387  unsigned UniqueID,
388  const MCSymbolELF *Associated) {
389  StringRef Group = "";
390  if (GroupSym)
391  Group = GroupSym->getName();
392  // Do the lookup, if we have a hit, return it.
393  auto IterBool = ELFUniquingMap.insert(
394  std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr));
395  auto &Entry = *IterBool.first;
396  if (!IterBool.second)
397  return Entry.second;
398 
399  StringRef CachedName = Entry.first.SectionName;
400 
402  if (Flags & ELF::SHF_ARM_PURECODE)
404  else if (Flags & ELF::SHF_EXECINSTR)
405  Kind = SectionKind::getText();
406  else
407  Kind = SectionKind::getReadOnly();
408 
409  MCSectionELF *Result = createELFSectionImpl(
410  CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
411  Entry.second = Result;
412  return Result;
413 }
414 
416  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
417  SectionKind::getReadOnly(), 4, Group, ~0,
418  nullptr);
419 }
420 
422  unsigned Characteristics,
424  StringRef COMDATSymName, int Selection,
425  unsigned UniqueID,
426  const char *BeginSymName) {
427  MCSymbol *COMDATSymbol = nullptr;
428  if (!COMDATSymName.empty()) {
429  COMDATSymbol = getOrCreateSymbol(COMDATSymName);
430  COMDATSymName = COMDATSymbol->getName();
431  }
432 
433 
434  // Do the lookup, if we have a hit, return it.
435  COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
436  auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
437  auto Iter = IterBool.first;
438  if (!IterBool.second)
439  return Iter->second;
440 
441  MCSymbol *Begin = nullptr;
442  if (BeginSymName)
443  Begin = createTempSymbol(BeginSymName, false);
444 
445  StringRef CachedName = Iter->first.SectionName;
446  MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
447  CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
448 
449  Iter->second = Result;
450  return Result;
451 }
452 
454  unsigned Characteristics,
456  const char *BeginSymName) {
457  return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
458  BeginSymName);
459 }
460 
462  COFFSectionKey T{Section, "", 0, GenericSectionID};
463  auto Iter = COFFUniquingMap.find(T);
464  if (Iter == COFFUniquingMap.end())
465  return nullptr;
466  return Iter->second;
467 }
468 
470  const MCSymbol *KeySym,
471  unsigned UniqueID) {
472  // Return the normal section if we don't have to be associative or unique.
473  if (!KeySym && UniqueID == GenericSectionID)
474  return Sec;
475 
476  // If we have a key symbol, make an associative section with the same name and
477  // kind as the normal section.
478  unsigned Characteristics = Sec->getCharacteristics();
479  if (KeySym) {
480  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
482  Sec->getKind(), KeySym->getName(),
484  }
485 
486  return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(),
487  "", 0, UniqueID);
488 }
489 
491  const Twine &Group, unsigned UniqueID,
492  const char *BeginSymName) {
493  MCSymbolWasm *GroupSym = nullptr;
494  if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
495  GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
496  GroupSym->setComdat(true);
497  }
498 
499  return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName);
500 }
501 
503  const MCSymbolWasm *GroupSym,
504  unsigned UniqueID,
505  const char *BeginSymName) {
506  StringRef Group = "";
507  if (GroupSym)
508  Group = GroupSym->getName();
509  // Do the lookup, if we have a hit, return it.
510  auto IterBool = WasmUniquingMap.insert(
511  std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
512  auto &Entry = *IterBool.first;
513  if (!IterBool.second)
514  return Entry.second;
515 
516  StringRef CachedName = Entry.first.SectionName;
517 
518  MCSymbol *Begin = createSymbol(CachedName, false, false);
519  cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
520 
521  MCSectionWasm *Result = new (WasmAllocator.Allocate())
522  MCSectionWasm(CachedName, Kind, GroupSym, UniqueID, Begin);
523  Entry.second = Result;
524 
525  auto *F = new MCDataFragment();
526  Result->getFragmentList().insert(Result->begin(), F);
527  F->setParent(Result);
528  Begin->setFragment(F);
529 
530  return Result;
531 }
532 
534  return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
535 }
536 
537 void MCContext::addDebugPrefixMapEntry(const std::string &From,
538  const std::string &To) {
539  DebugPrefixMap.insert(std::make_pair(From, To));
540 }
541 
543  const auto &DebugPrefixMap = this->DebugPrefixMap;
544  const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
545  for (const auto &Entry : DebugPrefixMap)
546  if (StringRef(Path).startswith(Entry.first)) {
547  std::string RemappedPath =
548  (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
549  Path.swap(RemappedPath);
550  }
551  };
552 
553  // Remap compilation directory.
554  std::string CompDir = CompilationDir.str();
555  RemapDebugPath(CompDir);
556  CompilationDir = CompDir;
557 
558  // Remap MCDwarfDirs in all compilation units.
559  for (auto &CUIDTablePair : MCDwarfLineTablesCUMap)
560  for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
561  RemapDebugPath(Dir);
562 }
563 
564 //===----------------------------------------------------------------------===//
565 // Dwarf Management
566 //===----------------------------------------------------------------------===//
567 
568 /// getDwarfFile - takes a file name and number to place in the dwarf file and
569 /// directory tables. If the file number has already been allocated it is an
570 /// error and zero is returned and the client reports the error, else the
571 /// allocated file number is returned. The file numbers may be in any order.
573  StringRef FileName,
574  unsigned FileNumber,
575  MD5::MD5Result *Checksum,
577  unsigned CUID) {
578  MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
579  return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
580 }
581 
582 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
583 /// currently is assigned and false otherwise.
584 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
585  const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
586  if (FileNumber == 0)
587  return getDwarfVersion() >= 5 && LineTable.hasRootFile();
588  if (FileNumber >= LineTable.getMCDwarfFiles().size())
589  return false;
590 
591  return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
592 }
593 
594 /// Remove empty sections from SectionsForRanges, to avoid generating
595 /// useless debug info for them.
597  SectionsForRanges.remove_if(
598  [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
599 }
600 
602  if (!CVContext.get())
603  CVContext.reset(new CodeViewContext);
604  return *CVContext.get();
605 }
606 
607 //===----------------------------------------------------------------------===//
608 // Error Reporting
609 //===----------------------------------------------------------------------===//
610 
611 void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
612  HadError = true;
613 
614  // If we have a source manager use it. Otherwise, try using the inline source
615  // manager.
616  // If that fails, use the generic report_fatal_error().
617  if (SrcMgr)
618  SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
619  else if (InlineSrcMgr)
620  InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
621  else
622  report_fatal_error(Msg, false);
623 }
624 
625 void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
626  reportError(Loc, Msg);
627 
628  // If we reached here, we are failing ungracefully. Run the interrupt handlers
629  // to make sure any special cleanups get done, in particular that we remove
630  // files registered with RemoveFileOnSignal.
632  exit(1);
633 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
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:247
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:255
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
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:135
void reset()
reset - return object to right after construction state to prepare to process a new module ...
Definition: MCContext.cpp:82
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
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:242
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:141
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
F(f)
uint16_t getDwarfVersion() const
Definition: MCContext.h:627
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:56
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:421
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:469
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:55
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:79
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:210
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:300
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
Definition: MCContext.cpp:596
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:911
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
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:272
void RemapDebugPaths()
Definition: MCContext.cpp:542
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:67
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:72
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:625
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:86
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:422
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:342
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:216
unsigned const MachineRegisterInfo * MRI
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:77
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:983
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:611
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:365
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:71
#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:584
void setType(unsigned Type) const
Definition: MCSymbolELF.cpp:94
bool hasRootFile() const
Definition: MCDwarf.h:321
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:351
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:146
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:256
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned FileNumber=0)
Definition: MCDwarf.cpp:533
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:261
iterator insert(iterator where, pointer New)
Definition: ilist.h:227
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:122
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:537
#define I(x, y, z)
Definition: MD5.cpp:58
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:322
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
Definition: MCContext.cpp:415
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:601
const unsigned Kind
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:572
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())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:388
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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:72
iterator begin()
Definition: MCSection.h:162
static SectionKind getExecuteOnly()
Definition: SectionKind.h:180
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:371
static SectionKind getText()
Definition: SectionKind.h:179
void resize(size_type N)
Definition: SmallVector.h:343
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:533
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:137