LLVM  8.0.1
MCStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/MC/MCStreamer.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/BinaryFormat/COFF.h"
16 #include "llvm/MC/MCAsmBackend.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCCodeView.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstPrinter.h"
25 #include "llvm/MC/MCSection.h"
26 #include "llvm/MC/MCSectionCOFF.h"
27 #include "llvm/MC/MCSymbol.h"
28 #include "llvm/MC/MCWin64EH.h"
29 #include "llvm/MC/MCWinEH.h"
30 #include "llvm/Support/Casting.h"
32 #include "llvm/Support/LEB128.h"
35 #include <cassert>
36 #include <cstdint>
37 #include <cstdlib>
38 #include <utility>
39 
40 using namespace llvm;
41 
43  S.setTargetStreamer(this);
44 }
45 
46 // Pin the vtables to this file.
48 
50 
52 
55  const MCExpr *Subsection,
56  raw_ostream &OS) {
57  Section->PrintSwitchToSection(
60  Subsection);
61 }
62 
64  Streamer.EmitRawText(Directive);
65 }
66 
68  SmallString<128> Str;
69  raw_svector_ostream OS(Str);
70 
71  Value->print(OS, Streamer.getContext().getAsmInfo());
72  Streamer.EmitRawText(OS.str());
73 }
74 
76  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
77  const char *Directive = MAI->getData8bitsDirective();
78  for (const unsigned char C : Data.bytes()) {
79  SmallString<128> Str;
80  raw_svector_ostream OS(Str);
81 
82  OS << Directive << (unsigned)C;
83  Streamer.EmitRawText(OS.str());
84  }
85 }
86 
88 
90  : Context(Ctx), CurrentWinFrameInfo(nullptr),
91  UseAssemblerInfoForParsing(false) {
92  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
93 }
94 
96 
98  DwarfFrameInfos.clear();
99  CurrentWinFrameInfo = nullptr;
100  WinFrameInfos.clear();
101  SymbolOrdering.clear();
102  SectionStack.clear();
103  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
104 }
105 
107  // By default, discard comments.
108  return nulls();
109 }
110 
111 void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
112 
115 
117  for (auto &FI : DwarfFrameInfos)
118  FI.CompactUnwindEncoding =
119  (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0);
120 }
121 
122 /// EmitIntValue - Special case of EmitValue that avoids the client having to
123 /// pass in a MCExpr for constant integers.
124 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
125  assert(1 <= Size && Size <= 8 && "Invalid size");
126  assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
127  "Invalid size");
128  char buf[8];
129  const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian();
130  for (unsigned i = 0; i != Size; ++i) {
131  unsigned index = isLittleEndian ? i : (Size - i - 1);
132  buf[i] = uint8_t(Value >> (index * 8));
133  }
134  EmitBytes(StringRef(buf, Size));
135 }
136 
137 /// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the
138 /// client having to pass in a MCExpr for constant integers.
140  SmallString<128> Tmp;
141  raw_svector_ostream OSE(Tmp);
142  encodeULEB128(Value, OSE);
143  EmitBytes(OSE.str());
144 }
145 
146 /// EmitSLEB128IntValue - Special case of EmitSLEB128Value that avoids the
147 /// client having to pass in a MCExpr for constant integers.
149  SmallString<128> Tmp;
150  raw_svector_ostream OSE(Tmp);
151  encodeSLEB128(Value, OSE);
152  EmitBytes(OSE.str());
153 }
154 
155 void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) {
156  EmitValueImpl(Value, Size, Loc);
157 }
158 
159 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
160  bool IsSectionRelative) {
161  assert((!IsSectionRelative || Size == 4) &&
162  "SectionRelative value requires 4-bytes");
163 
164  if (!IsSectionRelative)
166  else
167  EmitCOFFSecRel32(Sym, /*Offset=*/0);
168 }
169 
171  report_fatal_error("unsupported directive in streamer");
172 }
173 
175  report_fatal_error("unsupported directive in streamer");
176 }
177 
179  report_fatal_error("unsupported directive in streamer");
180 }
181 
183  report_fatal_error("unsupported directive in streamer");
184 }
185 
187  report_fatal_error("unsupported directive in streamer");
188 }
189 
191  report_fatal_error("unsupported directive in streamer");
192 }
193 
194 /// Emit NumBytes bytes worth of the value specified by FillValue.
195 /// This implements directives such as '.space'.
196 void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
197  emitFill(*MCConstantExpr::create(NumBytes, getContext()), FillValue);
198 }
199 
200 /// The implementation in this class just redirects to emitFill.
201 void MCStreamer::EmitZeros(uint64_t NumBytes) {
202  emitFill(NumBytes, 0);
203 }
204 
207  StringRef Filename,
208  MD5::MD5Result *Checksum,
210  unsigned CUID) {
211  return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
212  Source, CUID);
213 }
214 
216  StringRef Filename,
217  MD5::MD5Result *Checksum,
219  unsigned CUID) {
220  getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
221  Source);
222 }
223 
225  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
226  if (!CurFrame)
227  return;
228  CurFrame->IsBKeyFrame = true;
229 }
230 
231 void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
232  unsigned Column, unsigned Flags,
233  unsigned Isa,
234  unsigned Discriminator,
235  StringRef FileName) {
236  getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
237  Discriminator);
238 }
239 
242  if (!Table.getLabel()) {
244  Table.setLabel(
245  Context.getOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
246  }
247  return Table.getLabel();
248 }
249 
251  return !DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End;
252 }
253 
254 MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() {
256  getContext().reportError(SMLoc(), "this directive must appear between "
257  ".cfi_startproc and .cfi_endproc "
258  "directives");
259  return nullptr;
260  }
261  return &DwarfFrameInfos.back();
262 }
263 
264 bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
265  ArrayRef<uint8_t> Checksum,
266  unsigned ChecksumKind) {
267  return getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
268  ChecksumKind);
269 }
270 
271 bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) {
272  return getContext().getCVContext().recordFunctionId(FunctionId);
273 }
274 
276  unsigned IAFunc, unsigned IAFile,
277  unsigned IALine, unsigned IACol,
278  SMLoc Loc) {
279  if (getContext().getCVContext().getCVFunctionInfo(IAFunc) == nullptr) {
280  getContext().reportError(Loc, "parent function id not introduced by "
281  ".cv_func_id or .cv_inline_site_id");
282  return true;
283  }
284 
286  FunctionId, IAFunc, IAFile, IALine, IACol);
287 }
288 
289 void MCStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
290  unsigned Line, unsigned Column,
291  bool PrologueEnd, bool IsStmt,
292  StringRef FileName, SMLoc Loc) {}
293 
294 bool MCStreamer::checkCVLocSection(unsigned FuncId, unsigned FileNo,
295  SMLoc Loc) {
297  MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FuncId);
298  if (!FI) {
300  Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id");
301  return false;
302  }
303 
304  // Track the section
305  if (FI->Section == nullptr)
307  else if (FI->Section != getCurrentSectionOnly()) {
309  Loc,
310  "all .cv_loc directives for a function must be in the same section");
311  return false;
312  }
313  return true;
314 }
315 
316 void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId,
317  const MCSymbol *Begin,
318  const MCSymbol *End) {}
319 
320 void MCStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
321  unsigned SourceFileId,
322  unsigned SourceLineNum,
323  const MCSymbol *FnStartSym,
324  const MCSymbol *FnEndSym) {}
325 
327  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
328  StringRef FixedSizePortion) {}
329 
331  MCSymbol *EHSymbol) {
332 }
333 
334 void MCStreamer::InitSections(bool NoExecStack) {
335  SwitchSection(getContext().getObjectFileInfo()->getTextSection());
336 }
337 
339  assert(Fragment);
340  Symbol->setFragment(Fragment);
341 
342  // As we emit symbols into a section, track the order so that they can
343  // be sorted upon later. Zero is reserved to mean 'unemitted'.
344  SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
345 }
346 
348  Symbol->redefineIfPossible();
349 
350  if (!Symbol->isUndefined() || Symbol->isVariable())
351  return getContext().reportError(Loc, "invalid symbol redefinition");
352 
353  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
354  assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
355  assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
356  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
357 
358  Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
359 
361  if (TS)
362  TS->emitLabel(Symbol);
363 }
364 
365 void MCStreamer::EmitCFISections(bool EH, bool Debug) {
366  assert(EH || Debug);
367 }
368 
369 void MCStreamer::EmitCFIStartProc(bool IsSimple, SMLoc Loc) {
371  return getContext().reportError(
372  Loc, "starting new .cfi frame before finishing the previous one");
373 
374  MCDwarfFrameInfo Frame;
375  Frame.IsSimple = IsSimple;
376  EmitCFIStartProcImpl(Frame);
377 
378  const MCAsmInfo* MAI = Context.getAsmInfo();
379  if (MAI) {
380  for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
381  if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
382  Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
383  Frame.CurrentCfaRegister = Inst.getRegister();
384  }
385  }
386  }
387 
388  DwarfFrameInfos.push_back(Frame);
389 }
390 
392 }
393 
395  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
396  if (!CurFrame)
397  return;
398  EmitCFIEndProcImpl(*CurFrame);
399 }
400 
402  // Put a dummy non-null value in Frame.End to mark that this frame has been
403  // closed.
404  Frame.End = (MCSymbol *)1;
405 }
406 
408  // Return a dummy non-null value so that label fields appear filled in when
409  // generating textual assembly.
410  return (MCSymbol *)1;
411 }
412 
413 void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
414  MCSymbol *Label = EmitCFILabel();
416  MCCFIInstruction::createDefCfa(Label, Register, Offset);
417  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
418  if (!CurFrame)
419  return;
420  CurFrame->Instructions.push_back(Instruction);
421  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
422 }
423 
425  MCSymbol *Label = EmitCFILabel();
428  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
429  if (!CurFrame)
430  return;
431  CurFrame->Instructions.push_back(Instruction);
432 }
433 
434 void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
435  MCSymbol *Label = EmitCFILabel();
437  MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
438  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
439  if (!CurFrame)
440  return;
441  CurFrame->Instructions.push_back(Instruction);
442 }
443 
445  MCSymbol *Label = EmitCFILabel();
448  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
449  if (!CurFrame)
450  return;
451  CurFrame->Instructions.push_back(Instruction);
452  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
453 }
454 
455 void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
456  MCSymbol *Label = EmitCFILabel();
458  MCCFIInstruction::createOffset(Label, Register, Offset);
459  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
460  if (!CurFrame)
461  return;
462  CurFrame->Instructions.push_back(Instruction);
463 }
464 
466  MCSymbol *Label = EmitCFILabel();
468  MCCFIInstruction::createRelOffset(Label, Register, Offset);
469  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
470  if (!CurFrame)
471  return;
472  CurFrame->Instructions.push_back(Instruction);
473 }
474 
476  unsigned Encoding) {
477  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
478  if (!CurFrame)
479  return;
480  CurFrame->Personality = Sym;
481  CurFrame->PersonalityEncoding = Encoding;
482 }
483 
484 void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
485  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
486  if (!CurFrame)
487  return;
488  CurFrame->Lsda = Sym;
489  CurFrame->LsdaEncoding = Encoding;
490 }
491 
493  MCSymbol *Label = EmitCFILabel();
495  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
496  if (!CurFrame)
497  return;
498  CurFrame->Instructions.push_back(Instruction);
499 }
500 
502  // FIXME: Error if there is no matching cfi_remember_state.
503  MCSymbol *Label = EmitCFILabel();
505  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
506  if (!CurFrame)
507  return;
508  CurFrame->Instructions.push_back(Instruction);
509 }
510 
512  MCSymbol *Label = EmitCFILabel();
514  MCCFIInstruction::createSameValue(Label, Register);
515  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
516  if (!CurFrame)
517  return;
518  CurFrame->Instructions.push_back(Instruction);
519 }
520 
522  MCSymbol *Label = EmitCFILabel();
524  MCCFIInstruction::createRestore(Label, Register);
525  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
526  if (!CurFrame)
527  return;
528  CurFrame->Instructions.push_back(Instruction);
529 }
530 
532  MCSymbol *Label = EmitCFILabel();
534  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
535  if (!CurFrame)
536  return;
537  CurFrame->Instructions.push_back(Instruction);
538 }
539 
541  MCSymbol *Label = EmitCFILabel();
544  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
545  if (!CurFrame)
546  return;
547  CurFrame->Instructions.push_back(Instruction);
548 }
549 
551  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
552  if (!CurFrame)
553  return;
554  CurFrame->IsSignalFrame = true;
555 }
556 
558  MCSymbol *Label = EmitCFILabel();
560  MCCFIInstruction::createUndefined(Label, Register);
561  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
562  if (!CurFrame)
563  return;
564  CurFrame->Instructions.push_back(Instruction);
565 }
566 
567 void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
568  MCSymbol *Label = EmitCFILabel();
570  MCCFIInstruction::createRegister(Label, Register1, Register2);
571  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
572  if (!CurFrame)
573  return;
574  CurFrame->Instructions.push_back(Instruction);
575 }
576 
578  MCSymbol *Label = EmitCFILabel();
581  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
582  if (!CurFrame)
583  return;
584  CurFrame->Instructions.push_back(Instruction);
585 }
586 
588  MCSymbol *Label = EmitCFILabel();
590  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
591  if (!CurFrame)
592  return;
593  CurFrame->Instructions.push_back(Instruction);
594 }
595 
597  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
598  if (!CurFrame)
599  return;
600  CurFrame->RAReg = Register;
601 }
602 
604  const MCAsmInfo *MAI = Context.getAsmInfo();
605  if (!MAI->usesWindowsCFI()) {
607  Loc, ".seh_* directives are not supported on this target");
608  return nullptr;
609  }
610  if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) {
612  Loc, ".seh_ directive must appear within an active frame");
613  return nullptr;
614  }
615  return CurrentWinFrameInfo;
616 }
617 
619  const MCAsmInfo *MAI = Context.getAsmInfo();
620  if (!MAI->usesWindowsCFI())
621  return getContext().reportError(
622  Loc, ".seh_* directives are not supported on this target");
623  if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
625  Loc, "Starting a function before ending the previous one!");
626 
627  MCSymbol *StartProc = EmitCFILabel();
628 
629  WinFrameInfos.emplace_back(
630  llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
631  CurrentWinFrameInfo = WinFrameInfos.back().get();
632  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
633 }
634 
636  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
637  if (!CurFrame)
638  return;
639  if (CurFrame->ChainedParent)
640  getContext().reportError(Loc, "Not all chained regions terminated!");
641 
642  MCSymbol *Label = EmitCFILabel();
643  CurFrame->End = Label;
644 }
645 
647  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
648  if (!CurFrame)
649  return;
650  if (CurFrame->ChainedParent)
651  getContext().reportError(Loc, "Not all chained regions terminated!");
652 
653  MCSymbol *Label = EmitCFILabel();
654  CurFrame->FuncletOrFuncEnd = Label;
655 }
656 
658  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
659  if (!CurFrame)
660  return;
661 
662  MCSymbol *StartProc = EmitCFILabel();
663 
664  WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>(
665  CurFrame->Function, StartProc, CurFrame));
666  CurrentWinFrameInfo = WinFrameInfos.back().get();
667  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
668 }
669 
671  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
672  if (!CurFrame)
673  return;
674  if (!CurFrame->ChainedParent)
675  return getContext().reportError(
676  Loc, "End of a chained region outside a chained region!");
677 
678  MCSymbol *Label = EmitCFILabel();
679 
680  CurFrame->End = Label;
681  CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent);
682 }
683 
684 void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
685  SMLoc Loc) {
686  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
687  if (!CurFrame)
688  return;
689  if (CurFrame->ChainedParent)
690  return getContext().reportError(
691  Loc, "Chained unwind areas can't have handlers!");
692  CurFrame->ExceptionHandler = Sym;
693  if (!Except && !Unwind)
694  getContext().reportError(Loc, "Don't know what kind of handler this is!");
695  if (Unwind)
696  CurFrame->HandlesUnwind = true;
697  if (Except)
698  CurFrame->HandlesExceptions = true;
699 }
700 
702  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
703  if (!CurFrame)
704  return;
705  if (CurFrame->ChainedParent)
706  getContext().reportError(Loc, "Chained unwind areas can't have handlers!");
707 }
708 
710  const MCSymbolRefExpr *To, uint64_t Count) {
711 }
712 
713 static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
714  MCSection *MainCFISec,
715  const MCSection *TextSec) {
716  // If this is the main .text section, use the main unwind info section.
717  if (TextSec == Context.getObjectFileInfo()->getTextSection())
718  return MainCFISec;
719 
720  const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
721  auto *MainCFISecCOFF = cast<MCSectionCOFF>(MainCFISec);
722  unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
723 
724  // If this section is COMDAT, this unwind section should be COMDAT associative
725  // with its group.
726  const MCSymbol *KeySym = nullptr;
727  if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
728  KeySym = TextSecCOFF->getCOMDATSymbol();
729 
730  // In a GNU environment, we can't use associative comdats. Instead, do what
731  // GCC does, which is to make plain comdat selectany section named like
732  // ".[px]data$_Z3foov".
733  if (!Context.getAsmInfo()->hasCOFFAssociativeComdats()) {
734  std::string SectionName =
735  (MainCFISecCOFF->getSectionName() + "$" +
736  TextSecCOFF->getSectionName().split('$').second)
737  .str();
738  return Context.getCOFFSection(
739  SectionName,
740  MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
741  MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
742  }
743  }
744 
745  return Context.getAssociativeCOFFSection(MainCFISecCOFF, KeySym, UniqueID);
746 }
747 
749  return getWinCFISection(getContext(), &NextWinCFIID,
750  getContext().getObjectFileInfo()->getPDataSection(),
751  TextSec);
752 }
753 
755  return getWinCFISection(getContext(), &NextWinCFIID,
756  getContext().getObjectFileInfo()->getXDataSection(),
757  TextSec);
758 }
759 
761 
763  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
764  if (!CurFrame)
765  return;
766 
767  MCSymbol *Label = EmitCFILabel();
768 
770  CurFrame->Instructions.push_back(Inst);
771 }
772 
774  SMLoc Loc) {
775  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
776  if (!CurFrame)
777  return;
778  if (CurFrame->LastFrameInst >= 0)
779  return getContext().reportError(
780  Loc, "frame register and offset can be set at most once");
781  if (Offset & 0x0F)
782  return getContext().reportError(Loc, "offset is not a multiple of 16");
783  if (Offset > 240)
784  return getContext().reportError(
785  Loc, "frame offset must be less than or equal to 240");
786 
787  MCSymbol *Label = EmitCFILabel();
788 
789  WinEH::Instruction Inst =
790  Win64EH::Instruction::SetFPReg(Label, Register, Offset);
791  CurFrame->LastFrameInst = CurFrame->Instructions.size();
792  CurFrame->Instructions.push_back(Inst);
793 }
794 
796  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
797  if (!CurFrame)
798  return;
799  if (Size == 0)
800  return getContext().reportError(Loc,
801  "stack allocation size must be non-zero");
802  if (Size & 7)
803  return getContext().reportError(
804  Loc, "stack allocation size is not a multiple of 8");
805 
806  MCSymbol *Label = EmitCFILabel();
807 
809  CurFrame->Instructions.push_back(Inst);
810 }
811 
813  SMLoc Loc) {
814  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
815  if (!CurFrame)
816  return;
817 
818  if (Offset & 7)
819  return getContext().reportError(
820  Loc, "register save offset is not 8 byte aligned");
821 
822  MCSymbol *Label = EmitCFILabel();
823 
824  WinEH::Instruction Inst =
825  Win64EH::Instruction::SaveNonVol(Label, Register, Offset);
826  CurFrame->Instructions.push_back(Inst);
827 }
828 
830  SMLoc Loc) {
831  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
832  if (!CurFrame)
833  return;
834  if (Offset & 0x0F)
835  return getContext().reportError(Loc, "offset is not a multiple of 16");
836 
837  MCSymbol *Label = EmitCFILabel();
838 
839  WinEH::Instruction Inst =
840  Win64EH::Instruction::SaveXMM(Label, Register, Offset);
841  CurFrame->Instructions.push_back(Inst);
842 }
843 
845  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
846  if (!CurFrame)
847  return;
848  if (!CurFrame->Instructions.empty())
849  return getContext().reportError(
850  Loc, "If present, PushMachFrame must be the first UOP");
851 
852  MCSymbol *Label = EmitCFILabel();
853 
855  CurFrame->Instructions.push_back(Inst);
856 }
857 
859  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
860  if (!CurFrame)
861  return;
862 
863  MCSymbol *Label = EmitCFILabel();
864 
865  CurFrame->PrologEnd = Label;
866 }
867 
869 
871 
873 
875 
877 
878 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
879 /// the specified string in the output .s file. This capability is
880 /// indicated by the hasRawTextSupport() predicate.
882  // This is not llvm_unreachable for the sake of out of tree backend
883  // developers who may not have assembly streamers and should serve as a
884  // reminder to not accidentally call EmitRawText in the absence of such.
885  report_fatal_error("EmitRawText called on an MCStreamer that doesn't support "
886  "it (target backend is likely missing an AsmStreamer "
887  "implementation)");
888 }
889 
891  SmallString<128> Str;
893 }
894 
896 }
897 
899  if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
900  (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
901  getContext().reportError(SMLoc(), "Unfinished frame!");
902  return;
903  }
904 
906  if (TS)
907  TS->finish();
908 
909  FinishImpl();
910 }
911 
913  visitUsedExpr(*Value);
914  Symbol->setVariableValue(Value);
915 
917  if (TS)
918  TS->emitAssignment(Symbol, Value);
919 }
920 
922  raw_ostream &OS, const MCInst &Inst,
923  const MCSubtargetInfo &STI) {
924  InstPrinter.printInst(&Inst, OS, "", STI);
925 }
926 
928 }
929 
931  switch (Expr.getKind()) {
932  case MCExpr::Target:
933  cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
934  break;
935 
936  case MCExpr::Constant:
937  break;
938 
939  case MCExpr::Binary: {
940  const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
941  visitUsedExpr(*BE.getLHS());
942  visitUsedExpr(*BE.getRHS());
943  break;
944  }
945 
946  case MCExpr::SymbolRef:
947  visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
948  break;
949 
950  case MCExpr::Unary:
951  visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
952  break;
953  }
954 }
955 
957  bool) {
958  // Scan for values.
959  for (unsigned i = Inst.getNumOperands(); i--;)
960  if (Inst.getOperand(i).isExpr())
961  visitUsedExpr(*Inst.getOperand(i).getExpr());
962 }
963 
965  unsigned Size) {
966  // Get the Hi-Lo expression.
967  const MCExpr *Diff =
969  MCSymbolRefExpr::create(Lo, Context), Context);
970 
971  const MCAsmInfo *MAI = Context.getAsmInfo();
972  if (!MAI->doesSetDirectiveSuppressReloc()) {
973  EmitValue(Diff, Size);
974  return;
975  }
976 
977  // Otherwise, emit with .set (aka assignment).
978  MCSymbol *SetLabel = Context.createTempSymbol("set", true);
979  EmitAssignment(SetLabel, Diff);
980  EmitSymbolValue(SetLabel, Size);
981 }
982 
984  const MCSymbol *Lo) {
985  // Get the Hi-Lo expression.
986  const MCExpr *Diff =
988  MCSymbolRefExpr::create(Lo, Context), Context);
989 
990  EmitULEB128Value(Diff);
991 }
992 
995 void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
997  llvm_unreachable("this directive only supported on COFF targets");
998 }
1000  llvm_unreachable("this directive only supported on COFF targets");
1001 }
1004  llvm_unreachable("this directive only supported on COFF targets");
1005 }
1007  llvm_unreachable("this directive only supported on COFF targets");
1008 }
1011  const MCSymbol *Aliasee) {}
1013  unsigned ByteAlignment) {}
1015  uint64_t Size, unsigned ByteAlignment) {}
1020 void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
1021  visitUsedExpr(*Value);
1022 }
1025 void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {}
1026 void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
1027  SMLoc Loc) {}
1029  unsigned ValueSize,
1030  unsigned MaxBytesToEmit) {}
1032  unsigned MaxBytesToEmit) {}
1034  SMLoc Loc) {}
1035 void MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {}
1036 void MCStreamer::EmitBundleLock(bool AlignToEnd) {}
1039 
1041  assert(Section && "Cannot switch to a null section!");
1042  MCSectionSubPair curSection = SectionStack.back().first;
1043  SectionStack.back().second = curSection;
1044  if (MCSectionSubPair(Section, Subsection) != curSection) {
1045  ChangeSection(Section, Subsection);
1046  SectionStack.back().first = MCSectionSubPair(Section, Subsection);
1047  assert(!Section->hasEnded() && "Section already ended");
1048  MCSymbol *Sym = Section->getBeginSymbol();
1049  if (Sym && !Sym->isInSection())
1050  EmitLabel(Sym);
1051  }
1052 }
1053 
1055  // TODO: keep track of the last subsection so that this symbol appears in the
1056  // correct place.
1057  MCSymbol *Sym = Section->getEndSymbol(Context);
1058  if (Sym->isInSection())
1059  return Sym;
1060 
1061  SwitchSection(Section);
1062  EmitLabel(Sym);
1063  return Sym;
1064 }
1065 
1067  const VersionTuple &SDKVersion) {
1068  if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin())
1069  return;
1070  // Do we even know the version?
1071  if (Target.getOSMajorVersion() == 0)
1072  return;
1073 
1074  unsigned Major;
1075  unsigned Minor;
1076  unsigned Update;
1077  MCVersionMinType VersionType;
1078  if (Target.isWatchOS()) {
1079  VersionType = MCVM_WatchOSVersionMin;
1080  Target.getWatchOSVersion(Major, Minor, Update);
1081  } else if (Target.isTvOS()) {
1082  VersionType = MCVM_TvOSVersionMin;
1083  Target.getiOSVersion(Major, Minor, Update);
1084  } else if (Target.isMacOSX()) {
1085  VersionType = MCVM_OSXVersionMin;
1086  if (!Target.getMacOSXVersion(Major, Minor, Update))
1087  Major = 0;
1088  } else {
1089  VersionType = MCVM_IOSVersionMin;
1090  Target.getiOSVersion(Major, Minor, Update);
1091  }
1092  if (Major != 0)
1093  EmitVersionMin(VersionType, Major, Minor, Update, SDKVersion);
1094 }
virtual void EmitBundleUnlock()
Ends a bundle-locked group.
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)
Note in the output the specified Flag.
Definition: MCStreamer.cpp:993
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 &#39;.loc fileno lineno ...&#39; assembler directive.
Definition: MCStreamer.cpp:231
uint64_t CallInst * C
virtual void EmitBundleAlignMode(unsigned AlignPow2)
Set the bundle alignment mode from now on in the section.
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:475
Profile::FuncID FuncId
Definition: Profile.cpp:321
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:524
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1092
MCStreamer(MCContext &Ctx)
Definition: MCStreamer.cpp:89
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:584
virtual void EmitCFISameValue(int64_t Register)
Definition: MCStreamer.cpp:511
virtual void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
This implements the CodeView &#39;.cv_def_range&#39; assembler directive.
Definition: MCStreamer.cpp:326
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:475
virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:762
virtual void EmitSLEB128Value(const MCExpr *Value)
virtual void EmitCFIGnuArgsSize(int64_t Size)
Definition: MCStreamer.cpp:540
LLVMContext & Context
void EmitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ...
Definition: MCStreamer.cpp:890
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:148
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:294
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition: MCStreamer.cpp:159
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:447
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee)
Emit an ELF .symver directive.
virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI)=0
Print the specified MCInst to the specified raw_ostream.
virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0)
Emit a thread local bss (.tbss) symbol.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void redefineIfPossible()
Prepare this symbol to be redefined.
Definition: MCSymbol.h:230
virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:618
virtual void EndCOFFSymbolDef()
Marks the end of the symbol definition.
Definition: MCStreamer.cpp:999
MCSection * Section
The section of the first .cv_loc directive used for this function, or null if none has been seen yet...
Definition: MCCodeView.h:112
const MCSymbol * End
Definition: MCWinEH.h:34
.watchos_version_min
Definition: MCDirectives.h:68
virtual void EmitULEB128Value(const MCExpr *Value)
virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID=0)
Specify the "root" file of the compilation, using the ".file 0" extension.
Definition: MCStreamer.cpp:215
static MCCFIInstruction createRememberState(MCSymbol *L)
.cfi_remember_state Save all current rules for all registers.
Definition: MCDwarf.h:538
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol)
Emit an weak reference from Alias to Symbol.
void push_back(const T &Elt)
Definition: SmallVector.h:218
static WinEH::Instruction SaveNonVol(MCSymbol *L, unsigned Reg, unsigned Offset)
Definition: MCWin64EH.h:37
virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:829
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition: MCDwarf.h:488
Target specific streamer interface.
Definition: MCStreamer.h:84
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:453
.ios_version_min
Definition: MCDirectives.h:65
virtual void reset()
State management.
Definition: MCStreamer.cpp:97
unsigned CurrentCfaRegister
Definition: MCDwarf.h:595
virtual void EmitWindowsUnwindTables()
Definition: MCStreamer.cpp:895
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)
Start emitting COFF symbol definition.
Definition: MCStreamer.cpp:996
virtual void EmitDTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
Definition: MCStreamer.cpp:170
bool isWatchOS() const
Is this an Apple watchOS triple.
Definition: Triple.h:466
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:564
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:567
virtual void emitExplicitComments()
Emit added explicit comments.
Definition: MCStreamer.cpp:114
virtual void emitValue(const MCExpr *Value)
Definition: MCStreamer.cpp:67
.macosx_version_min
Definition: MCDirectives.h:66
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCStreamer.cpp:983
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:424
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:240
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:491
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:475
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:354
virtual void EmitCOFFSymbolStorageClass(int StorageClass)
Emit the storage class of the symbol.
std::vector< Instruction > Instructions
Definition: MCWinEH.h:47
virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
unsigned LsdaEncoding
Definition: MCDwarf.h:597
virtual void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset)
Emits a COFF image relative relocation.
Definition: MCStreamer.cpp:876
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment)
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Definition: MCDwarf.h:482
bool addFile(MCStreamer &OS, unsigned FileNumber, StringRef Filename, ArrayRef< uint8_t > ChecksumBytes, uint8_t ChecksumKind)
Definition: MCCodeView.cpp:47
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:956
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:422
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
Definition: MCStreamer.cpp:113
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:365
virtual void EmitGPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
Definition: MCStreamer.cpp:190
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:470
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:594
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register)
.cfi_undefined From now on the previous value of Register can&#39;t be restored anymore.
Definition: MCDwarf.h:527
virtual void EmitCFIRememberState()
Definition: MCStreamer.cpp:492
MCContext & getContext() const
Definition: MCStreamer.h:251
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:484
virtual void EmitGPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
Definition: MCStreamer.cpp:186
void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment)
Sets the symbol&#39;s section.
Definition: MCStreamer.cpp:338
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
virtual void EmitWinCFIEndProc(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:635
virtual void EmitCFIEscape(StringRef Values)
Definition: MCStreamer.cpp:531
virtual void EmitCOFFSymbolType(int Type)
Emit the type of the symbol.
virtual Expected< unsigned > tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum=nullptr, Optional< StringRef > Source=None, unsigned CUID=0)
Associate a filename with a specified logical file number.
Definition: MCStreamer.cpp:206
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:252
virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:684
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
const MCSymbol * Lsda
Definition: MCDwarf.h:593
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
iterator_range< const unsigned char * > bytes() const
Definition: StringRef.h:116
virtual uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction >) const
Generate the compact unwind encoding for the CFI instructions.
Definition: MCAsmBackend.h:164
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
virtual void emitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:49
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame)
Definition: MCStreamer.cpp:391
virtual ~MCStreamer()
Definition: MCStreamer.cpp:95
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:524
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:29
virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc)
This implements the CodeView &#39;.cv_loc&#39; assembler directive.
Definition: MCStreamer.cpp:289
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:912
virtual void EmitWinCFIStartChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:657
Context object for machine code objects.
Definition: MCContext.h:63
virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, ArrayRef< uint8_t > Checksum, unsigned ChecksumKind)
Associate a filename with a specified logical file number, and also specify that file&#39;s checksum info...
Definition: MCStreamer.cpp:264
static WinEH::Instruction PushNonVol(MCSymbol *L, unsigned Reg)
Definition: MCWin64EH.h:27
bool hasEnded() const
Definition: MCSection.cpp:35
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:546
virtual void finish()
Definition: MCStreamer.cpp:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:567
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
Definition: MCStreamer.cpp:401
virtual void EmitTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
Definition: MCStreamer.cpp:178
virtual void emitRawComment(const Twine &T, bool TabPrefix=true)
Print T and prefix it with the comment string (normally #) and optionally a tab.
Definition: MCStreamer.cpp:111
virtual void EmitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
const MCExpr * getExpr() const
Definition: MCInst.h:96
virtual void EmitCFIRestoreState()
Definition: MCStreamer.cpp:501
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:124
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:337
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:155
Unary expressions.
Definition: MCExpr.h:42
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
virtual void EmitCFIRestore(int64_t Register)
Definition: MCStreamer.cpp:521
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:414
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:118
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
virtual void EmitBundleLock(bool AlignToEnd)
The following instructions are a bundle-locked group.
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)
Emit a local common (.lcomm) symbol.
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register)
.cfi_same_value Current value of Register is the same as in the previous frame.
Definition: MCDwarf.h:533
virtual raw_ostream & GetCommentOS()
Return a raw_ostream that comments can be written to.
Definition: MCStreamer.cpp:106
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:201
static MCCFIInstruction createNegateRAState(MCSymbol *L)
.cfi_negate_ra_state AArch64 negate RA state.
Definition: MCDwarf.h:514
Streaming machine code generation interface.
Definition: MCStreamer.h:189
virtual void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc=SMLoc())
This is used on platforms, such as Windows on ARM64, that require function or funclet sizes to be emi...
Definition: MCStreamer.cpp:646
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
const FrameInfo * ChainedParent
Definition: MCWinEH.h:46
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:258
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
Definition: MCDwarf.h:461
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
virtual void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:316
.tvos_version_min
Definition: MCDirectives.h:67
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:468
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
Definition: MCDwarf.h:509
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
Definition: MCDwarf.h:554
static WinEH::Instruction PushMachFrame(MCSymbol *L, bool Code)
Definition: MCWin64EH.h:34
MCSection * getAssociatedPDataSection(const MCSection *TextSec)
Get the .pdata section used for the given section.
Definition: MCStreamer.cpp:748
virtual void EmitSyntaxDirective()
Definition: MCStreamer.cpp:760
virtual void EmitCFIDefCfaRegister(int64_t Register)
Definition: MCStreamer.cpp:444
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void getWatchOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getWatchOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1118
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register...
Definition: MCDwarf.h:496
bool isExpr() const
Definition: MCInst.h:61
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register)
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
Definition: MCDwarf.h:521
virtual void EmitRawTextImpl(StringRef String)
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
Definition: MCStreamer.cpp:881
virtual void EmitWinEHHandlerData(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:701
unsigned getNumOperands() const
Definition: MCInst.h:184
unsigned size() const
Definition: DenseMap.h:126
virtual void EmitCFIUndefined(int64_t Register)
Definition: MCStreamer.cpp:557
virtual void EmitCFINegateRAState()
Definition: MCStreamer.cpp:587
unsigned PersonalityEncoding
Definition: MCDwarf.h:596
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:614
static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWin64EH.h:49
void Finish()
Finish emission of machine code.
Definition: MCStreamer.cpp:898
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
Definition: MCStreamer.cpp:330
virtual void EmitWinCFIEndChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:670
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:398
static MCCFIInstruction createRestoreState(MCSymbol *L)
.cfi_restore_state Restore the previously saved state.
Definition: MCDwarf.h:543
Binary assembler expressions.
Definition: MCExpr.h:417
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const =0
unsigned getOSMajorVersion() const
getOSMajorVersion - Return just the major version number, this is specialized because it is a common ...
Definition: Triple.h:332
virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol)
Definition: MCStreamer.cpp:868
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:773
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
Definition: MCStreamer.cpp:116
MCCVFunctionInfo * getCVFunctionInfo(unsigned FuncId)
Retreive the function info if this is a valid function id, or nullptr.
Definition: MCCodeView.cpp:79
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static MCSection * getWinCFISection(MCContext &Context, unsigned *NextWinCFIID, MCSection *MainCFISec, const MCSection *TextSec)
Definition: MCStreamer.cpp:713
virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:844
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:605
static WinEH::Instruction SaveXMM(MCSymbol *L, unsigned Reg, unsigned Offset)
Definition: MCWin64EH.h:43
virtual void EmitTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
Definition: MCStreamer.cpp:182
const MCSymbol * PrologEnd
Definition: MCWinEH.h:38
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
Definition: MCStreamer.cpp:334
virtual void EmitCFIReturnColumn(int64_t Register)
Definition: MCStreamer.cpp:596
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:57
BlockVerifier::State From
bool getMacOSXVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getMacOSXVersion - Parse the version number as with getOSVersion and then translate generic "darwin" ...
Definition: Triple.cpp:1051
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:964
virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol)
Emits the symbol table index of a Symbol into the current section.
Definition: MCStreamer.cpp:870
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:81
ExprKind getKind() const
Definition: MCExpr.h:73
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:455
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:257
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:384
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:24
const MCSection * TextSection
Definition: MCWinEH.h:40
virtual void EmitWinCFIEndProlog(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:858
static WinEH::Instruction Alloc(MCSymbol *L, unsigned Size)
Definition: MCWin64EH.h:30
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:795
virtual void EmitVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion)
Specify the Mach-O minimum deployment target version.
Definition: MCStreamer.h:455
MCStreamer & Streamer
Definition: MCStreamer.h:86
Promote Memory to Register
Definition: Mem2Reg.cpp:110
virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView &#39;.cv_inline_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:320
MCSymbol * getBeginSymbol()
Definition: MCSection.h:110
const Triple & getTargetTriple() const
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
Definition: MCStreamer.cpp:921
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:535
virtual void ChangeSection(MCSection *, const MCExpr *)
Update streamer for a new active section.
void setVariableValue(const MCExpr *Value)
Definition: MCSymbol.cpp:49
bool hasUnfinishedDwarfFrameInfo()
Definition: MCStreamer.cpp:250
virtual void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS)
Update streamer for a new active section.
Definition: MCStreamer.cpp:53
const MCSymbol * Function
Definition: MCWinEH.h:37
Target - Wrapper for Target specific information.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:346
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:930
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
Definition: MCStreamer.cpp:294
MCTargetStreamer(MCStreamer &S)
Definition: MCStreamer.cpp:42
virtual MCSymbol * EmitCFILabel()
When emitting an object file, create and emit a real label.
Definition: MCStreamer.cpp:407
bool recordFunctionId(unsigned FuncId)
Records the function id of a normal function.
Definition: MCCodeView.cpp:87
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:40
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:27
virtual void EmitThumbFunc(MCSymbol *Func)
Note in the output that the specified Func is a Thumb mode function (ARM target only).
Definition: MCStreamer.cpp:994
const MCSymbol * FuncletOrFuncEnd
Definition: MCWinEH.h:35
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:812
virtual void EmitCFISignalFrame()
Definition: MCStreamer.cpp:550
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:465
const MCSymbol * Personality
Definition: MCDwarf.h:592
MCAssemblerFlag
Definition: MCDirectives.h:48
bool recordInlinedCallSiteId(unsigned FuncId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol)
Records the function id of an inlined call site.
Definition: MCCodeView.cpp:100
bool hasCOFFAssociativeComdats() const
Definition: MCAsmInfo.h:475
virtual void EmitFileDirective(StringRef Filename)
Switch to a new logical file.
virtual void EmitDTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
Definition: MCStreamer.cpp:174
Generic base class for all target subtargets.
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
References to labels and assigned expressions.
Definition: MCExpr.h:41
uint32_t Size
Definition: Profile.cpp:47
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:405
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, MD5::MD5Result *Checksum, Optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Definition: MCContext.h:557
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:196
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:413
MCSymbol * endSection(MCSection *Section)
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator)
Saves the information from the currently parsed dwarf .loc directive and sets DwarfLocSeen.
Definition: MCContext.h:573
CodeViewContext & getCVContext()
Definition: MCContext.cpp:602
WinEH::FrameInfo * EnsureValidWinFrameInfo(SMLoc Loc)
Retreive the current frame info if one is available and it is not yet closed.
Definition: MCStreamer.cpp:603
virtual void emitRawBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:75
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:573
MCSymbol * getLabel() const
Definition: MCDwarf.h:327
MCSection * getTextSection() const
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset)
Emits a COFF section relative relocation.
Definition: MCStreamer.cpp:874
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void FinishImpl()
Streamer specific finalization.
virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol, SMLoc Loc)
Introduces an inline call site id for use with .cv_loc.
Definition: MCStreamer.cpp:275
bool isTvOS() const
Is this an Apple tvOS triple.
Definition: Triple.h:461
MCVersionMinType
Definition: MCDirectives.h:64
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
Constant expressions.
Definition: MCExpr.h:40
Binary expressions.
Definition: MCExpr.h:39
virtual bool EmitCVFuncIdDirective(unsigned FunctionId)
Introduces a function id for use with .cv_loc.
Definition: MCStreamer.cpp:271
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
virtual void EmitCFIBKeyFrame()
Definition: MCStreamer.cpp:224
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:347
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
virtual void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count)
Definition: MCStreamer.cpp:709
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Target specific expression.
Definition: MCExpr.h:43
void EmitULEB128IntValue(uint64_t Value)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:139
Information describing a function or inlined call site introduced by .cv_func_id or ...
Definition: MCCodeView.h:92
virtual void visitUsedSymbol(const MCSymbol &Sym)
Definition: MCStreamer.cpp:927
virtual void emitDwarfFileDirective(StringRef Directive)
Definition: MCStreamer.cpp:63
Represents a location in source code.
Definition: SMLoc.h:24
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals)
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
Definition: MCDwarf.h:549
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:393
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:36
void EmitVersionForTarget(const Triple &Target, const VersionTuple &SDKVersion)
void setTargetStreamer(MCTargetStreamer *TS)
Definition: MCStreamer.h:243
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Definition: MCStreamer.cpp:87
virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol)
Emits a COFF section index.
Definition: MCStreamer.cpp:872
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
Definition: MCStreamer.cpp:434
void setLabel(MCSymbol *Label)
Definition: MCDwarf.h:331
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2)
.cfi_register Previous value of Register1 is saved in register Register2.
Definition: MCDwarf.h:503
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue)
Set the DescValue for the Symbol.
Definition: MCStreamer.cpp:995
void EmitCFIStartProc(bool IsSimple, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:369
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:577
MCSection * getAssociatedXDataSection(const MCSection *TextSec)
Get the .xdata section used for the given section.
Definition: MCStreamer.cpp:754
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:138