LLVM  8.0.0svn
MCObjectStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
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 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCCodeEmitter.h"
15 #include "llvm/MC/MCCodeView.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCDwarf.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCObjectWriter.h"
20 #include "llvm/MC/MCSection.h"
21 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/Support/SourceMgr.h"
24 using namespace llvm;
25 
27  std::unique_ptr<MCAsmBackend> TAB,
28  std::unique_ptr<MCObjectWriter> OW,
29  std::unique_ptr<MCCodeEmitter> Emitter)
30  : MCStreamer(Context),
31  Assembler(llvm::make_unique<MCAssembler>(
32  Context, std::move(TAB), std::move(Emitter), std::move(OW))),
33  EmitEHFrame(true), EmitDebugFrame(false) {}
34 
36 
37 // AssemblerPtr is used for evaluation of expressions and causes
38 // difference between asm and object outputs. Return nullptr to in
39 // inline asm mode to limit divergence to assembly inputs.
42  return Assembler.get();
43  return nullptr;
44 }
45 
47  if (PendingLabels.empty())
48  return;
49  if (!F) {
50  F = new MCDataFragment();
51  MCSection *CurSection = getCurrentSectionOnly();
52  CurSection->getFragmentList().insert(CurInsertionPoint, F);
53  F->setParent(CurSection);
54  }
55  for (MCSymbol *Sym : PendingLabels) {
56  Sym->setFragment(F);
57  Sym->setOffset(FOffset);
58  }
59  PendingLabels.clear();
60 }
61 
62 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
63 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
64 static Optional<uint64_t>
66  assert(Hi && Lo);
68  return None;
69 
70  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
71  Hi->isVariable() || Lo->isVariable())
72  return None;
73 
74  return Hi->getOffset() - Lo->getOffset();
75 }
76 
78  const MCSymbol *Lo,
79  unsigned Size) {
80  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
81  EmitIntValue(*Diff, Size);
82  return;
83  }
85 }
86 
88  const MCSymbol *Lo) {
89  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
90  EmitULEB128IntValue(*Diff);
91  return;
92  }
94 }
95 
97  if (Assembler)
98  Assembler->reset();
99  CurInsertionPoint = MCSection::iterator();
100  EmitEHFrame = true;
101  EmitDebugFrame = false;
102  PendingLabels.clear();
104 }
105 
107  if (!getNumFrameInfos())
108  return;
109 
110  if (EmitEHFrame)
111  MCDwarfFrameEmitter::Emit(*this, MAB, true);
112 
113  if (EmitDebugFrame)
114  MCDwarfFrameEmitter::Emit(*this, MAB, false);
115 }
116 
118  assert(getCurrentSectionOnly() && "No current section!");
119 
120  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
121  return &*std::prev(CurInsertionPoint);
122 
123  return nullptr;
124 }
125 
127  const MCAssembler &Assembler,
128  const MCSubtargetInfo *STI) {
129  if (!F.hasInstructions())
130  return true;
131  // When bundling is enabled, we don't want to add data to a fragment that
132  // already has instructions (see MCELFStreamer::EmitInstToData for details)
133  if (Assembler.isBundlingEnabled())
134  return Assembler.getRelaxAll();
135  // If the subtarget is changed mid fragment we start a new fragment to record
136  // the new STI.
137  return !STI || F.getSubtargetInfo() == STI;
138 }
139 
142  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
143  if (!F || !CanReuseDataFragment(*F, *Assembler, STI)) {
144  F = new MCDataFragment();
145  insert(F);
146  }
147  return F;
148 }
149 
152  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
153  if (!F) {
154  F = new MCPaddingFragment();
155  insert(F);
156  }
157  return F;
158 }
159 
161  Assembler->registerSymbol(Sym);
162 }
163 
165  MCStreamer::EmitCFISections(EH, Debug);
166  EmitEHFrame = EH;
167  EmitDebugFrame = Debug;
168 }
169 
171  SMLoc Loc) {
172  MCStreamer::EmitValueImpl(Value, Size, Loc);
174  flushPendingLabels(DF, DF->getContents().size());
175 
177 
178  // Avoid fixups when possible.
179  int64_t AbsValue;
180  if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
181  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
183  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
184  return;
185  }
186  EmitIntValue(AbsValue, Size);
187  return;
188  }
189  DF->getFixups().push_back(
190  MCFixup::create(DF->getContents().size(), Value,
191  MCFixup::getKindForSize(Size, false), Loc));
192  DF->getContents().resize(DF->getContents().size() + Size, 0);
193 }
194 
195 MCSymbol *MCObjectStreamer::EmitCFILabel() {
196  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
197  EmitLabel(Label);
198  return Label;
199 }
200 
201 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
202  // We need to create a local symbol to avoid relocations.
203  Frame.Begin = getContext().createTempSymbol();
204  EmitLabel(Frame.Begin);
205 }
206 
207 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
208  Frame.End = getContext().createTempSymbol();
209  EmitLabel(Frame.End);
210 }
211 
213  MCStreamer::EmitLabel(Symbol, Loc);
214 
215  getAssembler().registerSymbol(*Symbol);
216 
217  // If there is a current fragment, mark the symbol as pointing into it.
218  // Otherwise queue the label and set its fragment pointer when we emit the
219  // next fragment.
220  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
221  if (F && !(getAssembler().isBundlingEnabled() &&
222  getAssembler().getRelaxAll())) {
223  Symbol->setFragment(F);
224  Symbol->setOffset(F->getContents().size());
225  } else {
226  PendingLabels.push_back(Symbol);
227  }
228 }
229 
231  MCStreamer::EmitLabel(Symbol, Loc);
232  getAssembler().registerSymbol(*Symbol);
233  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
234  if (DF)
235  Symbol->setFragment(F);
236  else
237  PendingLabels.push_back(Symbol);
238 }
239 
241  int64_t IntValue;
242  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
243  EmitULEB128IntValue(IntValue);
244  return;
245  }
246  insert(new MCLEBFragment(*Value, false));
247 }
248 
250  int64_t IntValue;
251  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
252  EmitSLEB128IntValue(IntValue);
253  return;
254  }
255  insert(new MCLEBFragment(*Value, true));
256 }
257 
259  const MCSymbol *Symbol) {
260  report_fatal_error("This file format doesn't support weak aliases.");
261 }
262 
264  const MCExpr *Subsection) {
265  changeSectionImpl(Section, Subsection);
266 }
267 
269  const MCExpr *Subsection) {
270  assert(Section && "Cannot switch to a null section!");
271  flushPendingLabels(nullptr);
273 
274  bool Created = getAssembler().registerSection(*Section);
275 
276  int64_t IntSubsection = 0;
277  if (Subsection &&
278  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
279  report_fatal_error("Cannot evaluate subsection number");
280  if (IntSubsection < 0 || IntSubsection > 8192)
281  report_fatal_error("Subsection number out of range");
282  CurInsertionPoint =
283  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
284  return Created;
285 }
286 
288  getAssembler().registerSymbol(*Symbol);
289  MCStreamer::EmitAssignment(Symbol, Value);
290 }
291 
293  return Sec.hasInstructions();
294 }
295 
297  const MCSubtargetInfo &STI, bool) {
299  EmitInstructionImpl(Inst, STI);
301 }
302 
303 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
304  const MCSubtargetInfo &STI) {
305  MCStreamer::EmitInstruction(Inst, STI);
306 
308  Sec->setHasInstructions(true);
309 
310  // Now that a machine instruction has been assembled into this section, make
311  // a line entry for any .loc directive that has been seen.
313 
314  // If this instruction doesn't need relaxation, just emit it as data.
315  MCAssembler &Assembler = getAssembler();
316  if (!Assembler.getBackend().mayNeedRelaxation(Inst, STI)) {
317  EmitInstToData(Inst, STI);
318  return;
319  }
320 
321  // Otherwise, relax and emit it as data if either:
322  // - The RelaxAll flag was passed
323  // - Bundling is enabled and this instruction is inside a bundle-locked
324  // group. We want to emit all such instructions into the same data
325  // fragment.
326  if (Assembler.getRelaxAll() ||
327  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
328  MCInst Relaxed;
329  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
330  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
331  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
332  EmitInstToData(Relaxed, STI);
333  return;
334  }
335 
336  // Otherwise emit to a separate fragment.
337  EmitInstToFragment(Inst, STI);
338 }
339 
341  const MCSubtargetInfo &STI) {
342  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
343  llvm_unreachable("All instructions should have already been relaxed");
344 
345  // Always create a new, separate fragment here, because its size can change
346  // during relaxation.
347  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
348  insert(IF);
349 
350  SmallString<128> Code;
351  raw_svector_ostream VecOS(Code);
352  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
353  STI);
354  IF->getContents().append(Code.begin(), Code.end());
355 }
356 
357 #ifndef NDEBUG
358 static const char *const BundlingNotImplementedMsg =
359  "Aligned bundling is not implemented for this object format";
360 #endif
361 
362 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
363  llvm_unreachable(BundlingNotImplementedMsg);
364 }
365 
366 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
367  llvm_unreachable(BundlingNotImplementedMsg);
368 }
369 
371  llvm_unreachable(BundlingNotImplementedMsg);
372 }
373 
374 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
375  unsigned Column, unsigned Flags,
376  unsigned Isa,
377  unsigned Discriminator,
378  StringRef FileName) {
379  // In case we see two .loc directives in a row, make sure the
380  // first one gets a line entry.
382 
383  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
384  Isa, Discriminator, FileName);
385 }
386 
387 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
388  const MCSymbol *B) {
389  MCContext &Context = OS.getContext();
391  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
392  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
393  const MCExpr *AddrDelta =
394  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
395  return AddrDelta;
396 }
397 
399  MCDwarfLineTableParams Params,
400  int64_t LineDelta, const MCSymbol *Label,
401  int PointerSize) {
402  // emit the sequence to set the address
403  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
404  OS.EmitULEB128IntValue(PointerSize + 1);
405  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
406  OS.EmitSymbolValue(Label, PointerSize);
407 
408  // emit the sequence for the LineDelta (from 1) and a zero address delta.
409  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
410 }
411 
413  const MCSymbol *LastLabel,
414  const MCSymbol *Label,
415  unsigned PointerSize) {
416  if (!LastLabel) {
417  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
418  Label, PointerSize);
419  return;
420  }
421  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
422  int64_t Res;
423  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
424  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
425  Res);
426  return;
427  }
428  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
429 }
430 
432  const MCSymbol *Label) {
433  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
434  int64_t Res;
435  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
437  return;
438  }
439  insert(new MCDwarfCallFrameFragment(*AddrDelta));
440 }
441 
442 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
443  unsigned Line, unsigned Column,
444  bool PrologueEnd, bool IsStmt,
445  StringRef FileName, SMLoc Loc) {
446  // Validate the directive.
447  if (!checkCVLocSection(FunctionId, FileNo, Loc))
448  return;
449 
450  // Emit a label at the current position and record it in the CodeViewContext.
451  MCSymbol *LineSym = getContext().createTempSymbol();
452  EmitLabel(LineSym);
453  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
454  FileNo, Line, Column, PrologueEnd,
455  IsStmt);
456 }
457 
459  const MCSymbol *Begin,
460  const MCSymbol *End) {
461  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
462  End);
463  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
464 }
465 
467  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
468  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
470  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
471  FnEndSym);
473  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
474 }
475 
477  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
478  StringRef FixedSizePortion) {
479  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
480  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
481 }
482 
485 }
488 }
489 
492 }
493 
497  flushPendingLabels(DF, DF->getContents().size());
498  DF->getContents().append(Data.begin(), Data.end());
499 
500  // EmitBytes might not cover all possible ways we emit data (or could be used
501  // to emit executable code in some cases), but is the best method we have
502  // right now for checking this.
504  Sec->setHasData(true);
505 }
506 
508  int64_t Value,
509  unsigned ValueSize,
510  unsigned MaxBytesToEmit) {
511  if (MaxBytesToEmit == 0)
512  MaxBytesToEmit = ByteAlignment;
513  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
514 
515  // Update the maximum alignment on the current section if necessary.
516  MCSection *CurSec = getCurrentSectionOnly();
517  if (ByteAlignment > CurSec->getAlignment())
518  CurSec->setAlignment(ByteAlignment);
519 }
520 
522  unsigned MaxBytesToEmit) {
523  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
524  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
525 }
526 
528  unsigned char Value,
529  SMLoc Loc) {
530  insert(new MCOrgFragment(*Offset, Value, Loc));
531 }
532 
534  const MCCodePaddingContext &Context) {
536 }
537 
539  const MCCodePaddingContext &Context) {
541 }
542 
543 // Associate DTPRel32 fixup with data and resize data area
546  flushPendingLabels(DF, DF->getContents().size());
547 
548  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
549  Value, FK_DTPRel_4));
550  DF->getContents().resize(DF->getContents().size() + 4, 0);
551 }
552 
553 // Associate DTPRel64 fixup with data and resize data area
556  flushPendingLabels(DF, DF->getContents().size());
557 
558  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
559  Value, FK_DTPRel_8));
560  DF->getContents().resize(DF->getContents().size() + 8, 0);
561 }
562 
563 // Associate TPRel32 fixup with data and resize data area
566  flushPendingLabels(DF, DF->getContents().size());
567 
568  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
569  Value, FK_TPRel_4));
570  DF->getContents().resize(DF->getContents().size() + 4, 0);
571 }
572 
573 // Associate TPRel64 fixup with data and resize data area
576  flushPendingLabels(DF, DF->getContents().size());
577 
578  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
579  Value, FK_TPRel_8));
580  DF->getContents().resize(DF->getContents().size() + 8, 0);
581 }
582 
583 // Associate GPRel32 fixup with data and resize data area
586  flushPendingLabels(DF, DF->getContents().size());
587 
588  DF->getFixups().push_back(
589  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
590  DF->getContents().resize(DF->getContents().size() + 4, 0);
591 }
592 
593 // Associate GPRel64 fixup with data and resize data area
596  flushPendingLabels(DF, DF->getContents().size());
597 
598  DF->getFixups().push_back(
599  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
600  DF->getContents().resize(DF->getContents().size() + 8, 0);
601 }
602 
604  const MCExpr *Expr, SMLoc Loc,
605  const MCSubtargetInfo &STI) {
606  int64_t OffsetValue;
607  if (!Offset.evaluateAsAbsolute(OffsetValue))
608  llvm_unreachable("Offset is not absolute");
609 
610  if (OffsetValue < 0)
611  llvm_unreachable("Offset is negative");
612 
614  flushPendingLabels(DF, DF->getContents().size());
615 
616  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
617  if (!MaybeKind.hasValue())
618  return true;
619 
620  MCFixupKind Kind = *MaybeKind;
621 
622  if (Expr == nullptr)
623  Expr =
624  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
625  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
626  return false;
627 }
628 
629 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
630  SMLoc Loc) {
632  flushPendingLabels(DF, DF->getContents().size());
633 
634  assert(getCurrentSectionOnly() && "need a section");
635  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
636 }
637 
638 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
639  int64_t Expr, SMLoc Loc) {
640  int64_t IntNumValues;
641  // Do additional checking now if we can resolve the value.
642  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
643  if (IntNumValues < 0) {
646  "'.fill' directive with negative repeat count has no effect");
647  return;
648  }
649  // Emit now if we can for better errors.
650  int64_t NonZeroSize = Size > 4 ? 4 : Size;
651  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
652  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
653  EmitIntValue(Expr, NonZeroSize);
654  if (NonZeroSize < Size)
655  EmitIntValue(0, Size - NonZeroSize);
656  }
657  return;
658  }
659 
660  // Otherwise emit as fragment.
662  flushPendingLabels(DF, DF->getContents().size());
663 
664  assert(getCurrentSectionOnly() && "need a section");
665  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
666 }
667 
669  getAssembler().addFileName(Filename);
670 }
671 
674 }
675 
679 }
680 
683 
684  // If we are generating dwarf for assembly source files dump out the sections.
685  if (getContext().getGenDwarfForAssembly())
686  MCGenDwarfInfo::Emit(this);
687 
688  // Dump out the dwarf file & directory tables and line tables.
689  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
690 
692  getAssembler().Finish();
693 }
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:212
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
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:307
Fragment for adding required padding.
Definition: MCFragment.h:341
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void handleCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context)
Handles all target related code padding after writing a block to an object file.
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:327
A eight-byte dtp relative fixup.
Definition: MCFixup.h:37
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
bool hasInstructions() const
Definition: MCSection.h:141
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:88
static const char *const BundlingNotImplementedMsg
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:136
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
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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:147
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:294
virtual bool mayNeedRelaxation(const MCInst &Inst, const MCSubtargetInfo &STI) const =0
Check whether the given instruction may need relaxation.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
virtual void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
virtual bool requiresDiffExpressionRelocations() const
Check whether the given target requires emitting differences of two symbols as a set of relocations...
Definition: MCAsmBackend.h:104
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
void EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) override
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void setAlignment(unsigned Value)
Definition: MCSection.h:122
virtual void reset()
State management.
Definition: MCStreamer.cpp:85
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1838
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
Definition: MCFixup.h:132
F(f)
void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView &#39;.cv_filechecksumoffset&#39; assembler directive.
void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion) override
This implements the CodeView &#39;.cv_def_range&#39; assembler directive.
block Block Frequency true
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:1199
void handleCodePaddingInstructionEnd(const MCInst &Inst)
Handles all target related code padding after writing an instruction to an object file...
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCStreamer.cpp:942
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:633
bool isBundlingEnabled() const
Definition: MCAssembler.h:317
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.
Definition: MCStreamer.cpp:979
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:915
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:346
unsigned getAlignment() const
Definition: MCSection.h:121
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:422
MCContext & getContext() const
Definition: MCStreamer.h:253
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:247
Definition: BitVector.h:938
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void setHasInstructions(bool Value)
Definition: MCSection.h:142
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) override
Emit a .reloc directive.
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:288
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
A four-byte tp relative fixup.
Definition: MCFixup.h:38
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool registerSection(MCSection &Section)
MCSymbol * Begin
Definition: MCDwarf.h:584
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:290
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
bool mayHaveInstructions(MCSection &Sec) const override
void flushPendingLabels()
Create a dummy fragment to assign any pending labels.
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:872
Context object for machine code objects.
Definition: MCContext.h:63
void EmitDTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
void emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:435
A four-byte gp relative fixup.
Definition: MCFixup.h:34
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
Streaming object file generation interface.
void RemapDebugPaths()
Definition: MCContext.cpp:543
MCAssembler * getAssemblerPtr() override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool isBundleLocked() const
Definition: MCSection.h:132
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:258
void setHasData(bool Value)
Definition: MCSection.h:145
void EmitDTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:198
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:112
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:153
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
void EmitULEB128Value(const MCExpr *Value) override
Streaming machine code generation interface.
Definition: MCStreamer.h:183
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void visitUsedSymbol(const MCSymbol &Sym) override
void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override
This implements the CodeView &#39;.cv_loc&#39; assembler directive.
virtual void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:297
void EmitSLEB128Value(const MCExpr *Value) override
void insert(MCFragment *F)
void EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) override
void EmitAddrsigSym(const MCSymbol *Sym) override
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
MCAssembler & getAssembler()
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:224
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
uint64_t getOffset() const
Definition: MCSymbol.h:321
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
void EmitFrames(MCAsmBackend *MAB)
const SourceMgr * getSourceManager() const
Definition: MCContext.h:289
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:398
void handleCodePaddingInstructionBegin(const MCInst &Inst)
Handles all target related code padding before writing a new instruction to an object file...
void setOffset(uint64_t Value)
Definition: MCSymbol.h:327
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:90
size_t size() const
Definition: SmallVector.h:53
void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) override
Emit some number of copies of Value until the byte offset Offset is reached.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void clearDwarfLocSeen()
Definition: MCContext.h:585
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
MCPaddingFragment * getOrCreatePaddingFragment()
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
void EmitCFISections(bool EH, bool Debug) override
void handleCodePaddingBasicBlockStart(MCObjectStreamer *OS, const MCCodePaddingContext &Context)
Handles all target related code padding when starting to write a new basic block to an object file...
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
MCAsmBackend * getBackendPtr() const
Definition: MCAssembler.h:280
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:923
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:286
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:384
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:301
void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
void addFileName(StringRef FileName)
Definition: MCAssembler.h:438
bool getRelaxAll() const
Definition: MCAssembler.h:314
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:340
void recordCVLoc(MCContext &Ctx, const MCSymbol *Label, unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt)
Saves the information from the currently parsed .cv_loc directive and sets CVLocSeen.
Definition: MCCodeView.cpp:131
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:110
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition: MCFragment.h:174
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
Definition: MCStreamer.cpp:275
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1121
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
iterator begin() const
Definition: StringRef.h:106
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:394
void EmitTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:233
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
unsigned getNumFrameInfos()
Definition: MCStreamer.h:264
void EmitBundleUnlock() override
Ends a bundle-locked group.
void FinishImpl() override
Streamer specific finalization.
static Optional< uint64_t > absoluteSymbolDiff(MCAssembler &Asm, const MCSymbol *Hi, const MCSymbol *Lo)
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void reset() override
state management
static bool CanReuseDataFragment(const MCDataFragment &F, const MCAssembler &Assembler, const MCSubtargetInfo *STI)
Generic base class for all target subtargets.
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Definition: MCCodeView.cpp:171
uint32_t Size
Definition: Profile.cpp:47
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:248
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName) override
This implements the DWARF2 &#39;.loc fileno lineno ...&#39; assembler directive.
void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView &#39;.cv_inline_linetable&#39; assembler directive.
MCFragment * getCurrentFragment() const
CodeViewContext & getCVContext()
Definition: MCContext.cpp:602
const unsigned Kind
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:59
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))
void EmitGPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:328
Subtraction.
Definition: MCExpr.h:440
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1778
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FragmentListType::iterator iterator
Definition: MCSection.h:53
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:127
void EmitCVFileChecksumsDirective() override
This implements the CodeView &#39;.cv_filechecksums&#39; assembler directive.
Represents a location in source code.
Definition: SMLoc.h:24
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:393
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:193
void setParent(MCSection *Value)
Definition: MCFragment.h:100
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
iterator end() const
Definition: StringRef.h:108
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
void Finish()
Finish - Do final processing and write the object to the output stream.
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:150
void EmitGPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
void EmitTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Emit the given Instruction into the current section.
void resize(size_type N)
Definition: SmallVector.h:351