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