LLVM  8.0.1
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 // When fixup's offset is a forward declared label, e.g.:
63 //
64 // .reloc 1f, R_MIPS_JALR, foo
65 // 1: nop
66 //
67 // postpone adding it to Fixups vector until the label is defined and its offset
68 // is known.
69 void MCObjectStreamer::resolvePendingFixups() {
70  for (PendingMCFixup &PendingFixup : PendingFixups) {
71  if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
72  getContext().reportError(PendingFixup.Fixup.getLoc(),
73  "unresolved relocation offset");
74  continue;
75  }
76  flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
77  PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
78  PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
79  }
80  PendingFixups.clear();
81 }
82 
83 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
84 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
85 static Optional<uint64_t>
87  assert(Hi && Lo);
89  return None;
90 
91  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
92  Hi->isVariable() || Lo->isVariable())
93  return None;
94 
95  return Hi->getOffset() - Lo->getOffset();
96 }
97 
99  const MCSymbol *Lo,
100  unsigned Size) {
101  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
102  EmitIntValue(*Diff, Size);
103  return;
104  }
106 }
107 
109  const MCSymbol *Lo) {
110  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
111  EmitULEB128IntValue(*Diff);
112  return;
113  }
115 }
116 
118  if (Assembler)
119  Assembler->reset();
120  CurInsertionPoint = MCSection::iterator();
121  EmitEHFrame = true;
122  EmitDebugFrame = false;
123  PendingLabels.clear();
125 }
126 
128  if (!getNumFrameInfos())
129  return;
130 
131  if (EmitEHFrame)
132  MCDwarfFrameEmitter::Emit(*this, MAB, true);
133 
134  if (EmitDebugFrame)
135  MCDwarfFrameEmitter::Emit(*this, MAB, false);
136 }
137 
139  assert(getCurrentSectionOnly() && "No current section!");
140 
141  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
142  return &*std::prev(CurInsertionPoint);
143 
144  return nullptr;
145 }
146 
148  const MCAssembler &Assembler,
149  const MCSubtargetInfo *STI) {
150  if (!F.hasInstructions())
151  return true;
152  // When bundling is enabled, we don't want to add data to a fragment that
153  // already has instructions (see MCELFStreamer::EmitInstToData for details)
154  if (Assembler.isBundlingEnabled())
155  return Assembler.getRelaxAll();
156  // If the subtarget is changed mid fragment we start a new fragment to record
157  // the new STI.
158  return !STI || F.getSubtargetInfo() == STI;
159 }
160 
163  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
164  if (!F || !CanReuseDataFragment(*F, *Assembler, STI)) {
165  F = new MCDataFragment();
166  insert(F);
167  }
168  return F;
169 }
170 
173  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
174  if (!F) {
175  F = new MCPaddingFragment();
176  insert(F);
177  }
178  return F;
179 }
180 
182  Assembler->registerSymbol(Sym);
183 }
184 
186  MCStreamer::EmitCFISections(EH, Debug);
187  EmitEHFrame = EH;
188  EmitDebugFrame = Debug;
189 }
190 
192  SMLoc Loc) {
193  MCStreamer::EmitValueImpl(Value, Size, Loc);
195  flushPendingLabels(DF, DF->getContents().size());
196 
198 
199  // Avoid fixups when possible.
200  int64_t AbsValue;
201  if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
202  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
204  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
205  return;
206  }
207  EmitIntValue(AbsValue, Size);
208  return;
209  }
210  DF->getFixups().push_back(
211  MCFixup::create(DF->getContents().size(), Value,
212  MCFixup::getKindForSize(Size, false), Loc));
213  DF->getContents().resize(DF->getContents().size() + Size, 0);
214 }
215 
216 MCSymbol *MCObjectStreamer::EmitCFILabel() {
217  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
218  EmitLabel(Label);
219  return Label;
220 }
221 
222 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
223  // We need to create a local symbol to avoid relocations.
224  Frame.Begin = getContext().createTempSymbol();
225  EmitLabel(Frame.Begin);
226 }
227 
228 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
229  Frame.End = getContext().createTempSymbol();
230  EmitLabel(Frame.End);
231 }
232 
234  MCStreamer::EmitLabel(Symbol, Loc);
235 
236  getAssembler().registerSymbol(*Symbol);
237 
238  // If there is a current fragment, mark the symbol as pointing into it.
239  // Otherwise queue the label and set its fragment pointer when we emit the
240  // next fragment.
241  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
242  if (F && !(getAssembler().isBundlingEnabled() &&
243  getAssembler().getRelaxAll())) {
244  Symbol->setFragment(F);
245  Symbol->setOffset(F->getContents().size());
246  } else {
247  PendingLabels.push_back(Symbol);
248  }
249 }
250 
252  MCStreamer::EmitLabel(Symbol, Loc);
253  getAssembler().registerSymbol(*Symbol);
254  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
255  if (DF)
256  Symbol->setFragment(F);
257  else
258  PendingLabels.push_back(Symbol);
259 }
260 
262  int64_t IntValue;
263  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
264  EmitULEB128IntValue(IntValue);
265  return;
266  }
267  insert(new MCLEBFragment(*Value, false));
268 }
269 
271  int64_t IntValue;
272  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
273  EmitSLEB128IntValue(IntValue);
274  return;
275  }
276  insert(new MCLEBFragment(*Value, true));
277 }
278 
280  const MCSymbol *Symbol) {
281  report_fatal_error("This file format doesn't support weak aliases.");
282 }
283 
285  const MCExpr *Subsection) {
286  changeSectionImpl(Section, Subsection);
287 }
288 
290  const MCExpr *Subsection) {
291  assert(Section && "Cannot switch to a null section!");
292  flushPendingLabels(nullptr);
294 
295  bool Created = getAssembler().registerSection(*Section);
296 
297  int64_t IntSubsection = 0;
298  if (Subsection &&
299  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
300  report_fatal_error("Cannot evaluate subsection number");
301  if (IntSubsection < 0 || IntSubsection > 8192)
302  report_fatal_error("Subsection number out of range");
303  CurInsertionPoint =
304  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
305  return Created;
306 }
307 
309  getAssembler().registerSymbol(*Symbol);
310  MCStreamer::EmitAssignment(Symbol, Value);
311 }
312 
314  return Sec.hasInstructions();
315 }
316 
318  const MCSubtargetInfo &STI, bool) {
320  EmitInstructionImpl(Inst, STI);
322 }
323 
324 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
325  const MCSubtargetInfo &STI) {
326  MCStreamer::EmitInstruction(Inst, STI);
327 
329  Sec->setHasInstructions(true);
330 
331  // Now that a machine instruction has been assembled into this section, make
332  // a line entry for any .loc directive that has been seen.
334 
335  // If this instruction doesn't need relaxation, just emit it as data.
336  MCAssembler &Assembler = getAssembler();
337  if (!Assembler.getBackend().mayNeedRelaxation(Inst, STI)) {
338  EmitInstToData(Inst, STI);
339  return;
340  }
341 
342  // Otherwise, relax and emit it as data if either:
343  // - The RelaxAll flag was passed
344  // - Bundling is enabled and this instruction is inside a bundle-locked
345  // group. We want to emit all such instructions into the same data
346  // fragment.
347  if (Assembler.getRelaxAll() ||
348  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
349  MCInst Relaxed;
350  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
351  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
352  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
353  EmitInstToData(Relaxed, STI);
354  return;
355  }
356 
357  // Otherwise emit to a separate fragment.
358  EmitInstToFragment(Inst, STI);
359 }
360 
362  const MCSubtargetInfo &STI) {
363  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
364  llvm_unreachable("All instructions should have already been relaxed");
365 
366  // Always create a new, separate fragment here, because its size can change
367  // during relaxation.
368  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
369  insert(IF);
370 
371  SmallString<128> Code;
372  raw_svector_ostream VecOS(Code);
373  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
374  STI);
375  IF->getContents().append(Code.begin(), Code.end());
376 }
377 
378 #ifndef NDEBUG
379 static const char *const BundlingNotImplementedMsg =
380  "Aligned bundling is not implemented for this object format";
381 #endif
382 
383 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
384  llvm_unreachable(BundlingNotImplementedMsg);
385 }
386 
387 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
388  llvm_unreachable(BundlingNotImplementedMsg);
389 }
390 
392  llvm_unreachable(BundlingNotImplementedMsg);
393 }
394 
395 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
396  unsigned Column, unsigned Flags,
397  unsigned Isa,
398  unsigned Discriminator,
399  StringRef FileName) {
400  // In case we see two .loc directives in a row, make sure the
401  // first one gets a line entry.
403 
404  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
405  Isa, Discriminator, FileName);
406 }
407 
408 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
409  const MCSymbol *B) {
410  MCContext &Context = OS.getContext();
412  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
413  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
414  const MCExpr *AddrDelta =
415  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
416  return AddrDelta;
417 }
418 
420  MCDwarfLineTableParams Params,
421  int64_t LineDelta, const MCSymbol *Label,
422  int PointerSize) {
423  // emit the sequence to set the address
424  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
425  OS.EmitULEB128IntValue(PointerSize + 1);
426  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
427  OS.EmitSymbolValue(Label, PointerSize);
428 
429  // emit the sequence for the LineDelta (from 1) and a zero address delta.
430  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
431 }
432 
434  const MCSymbol *LastLabel,
435  const MCSymbol *Label,
436  unsigned PointerSize) {
437  if (!LastLabel) {
438  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
439  Label, PointerSize);
440  return;
441  }
442  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
443  int64_t Res;
444  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
445  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
446  Res);
447  return;
448  }
449  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
450 }
451 
453  const MCSymbol *Label) {
454  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
455  int64_t Res;
456  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
458  return;
459  }
460  insert(new MCDwarfCallFrameFragment(*AddrDelta));
461 }
462 
463 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
464  unsigned Line, unsigned Column,
465  bool PrologueEnd, bool IsStmt,
466  StringRef FileName, SMLoc Loc) {
467  // Validate the directive.
468  if (!checkCVLocSection(FunctionId, FileNo, Loc))
469  return;
470 
471  // Emit a label at the current position and record it in the CodeViewContext.
472  MCSymbol *LineSym = getContext().createTempSymbol();
473  EmitLabel(LineSym);
474  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
475  FileNo, Line, Column, PrologueEnd,
476  IsStmt);
477 }
478 
480  const MCSymbol *Begin,
481  const MCSymbol *End) {
482  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
483  End);
484  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
485 }
486 
488  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
489  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
491  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
492  FnEndSym);
494  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
495 }
496 
498  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
499  StringRef FixedSizePortion) {
500  MCFragment *Frag =
501  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
502  // Attach labels that were pending before we created the defrange fragment to
503  // the beginning of the new fragment.
504  flushPendingLabels(Frag, 0);
505  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
506 }
507 
510 }
513 }
514 
517 }
518 
522  flushPendingLabels(DF, DF->getContents().size());
523  DF->getContents().append(Data.begin(), Data.end());
524 
525  // EmitBytes might not cover all possible ways we emit data (or could be used
526  // to emit executable code in some cases), but is the best method we have
527  // right now for checking this.
529  Sec->setHasData(true);
530 }
531 
533  int64_t Value,
534  unsigned ValueSize,
535  unsigned MaxBytesToEmit) {
536  if (MaxBytesToEmit == 0)
537  MaxBytesToEmit = ByteAlignment;
538  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
539 
540  // Update the maximum alignment on the current section if necessary.
541  MCSection *CurSec = getCurrentSectionOnly();
542  if (ByteAlignment > CurSec->getAlignment())
543  CurSec->setAlignment(ByteAlignment);
544 }
545 
547  unsigned MaxBytesToEmit) {
548  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
549  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
550 }
551 
553  unsigned char Value,
554  SMLoc Loc) {
555  insert(new MCOrgFragment(*Offset, Value, Loc));
556 }
557 
559  const MCCodePaddingContext &Context) {
561 }
562 
564  const MCCodePaddingContext &Context) {
566 }
567 
568 // Associate DTPRel32 fixup with data and resize data area
571  flushPendingLabels(DF, DF->getContents().size());
572 
573  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
574  Value, FK_DTPRel_4));
575  DF->getContents().resize(DF->getContents().size() + 4, 0);
576 }
577 
578 // Associate DTPRel64 fixup with data and resize data area
581  flushPendingLabels(DF, DF->getContents().size());
582 
583  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
584  Value, FK_DTPRel_8));
585  DF->getContents().resize(DF->getContents().size() + 8, 0);
586 }
587 
588 // Associate TPRel32 fixup with data and resize data area
591  flushPendingLabels(DF, DF->getContents().size());
592 
593  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
594  Value, FK_TPRel_4));
595  DF->getContents().resize(DF->getContents().size() + 4, 0);
596 }
597 
598 // Associate TPRel64 fixup with data and resize data area
601  flushPendingLabels(DF, DF->getContents().size());
602 
603  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
604  Value, FK_TPRel_8));
605  DF->getContents().resize(DF->getContents().size() + 8, 0);
606 }
607 
608 // Associate GPRel32 fixup with data and resize data area
611  flushPendingLabels(DF, DF->getContents().size());
612 
613  DF->getFixups().push_back(
614  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
615  DF->getContents().resize(DF->getContents().size() + 4, 0);
616 }
617 
618 // Associate GPRel64 fixup with data and resize data area
621  flushPendingLabels(DF, DF->getContents().size());
622 
623  DF->getFixups().push_back(
624  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
625  DF->getContents().resize(DF->getContents().size() + 8, 0);
626 }
627 
629  const MCExpr *Expr, SMLoc Loc,
630  const MCSubtargetInfo &STI) {
631  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
632  if (!MaybeKind.hasValue())
633  return true;
634 
635  MCFixupKind Kind = *MaybeKind;
636 
637  if (Expr == nullptr)
638  Expr =
639  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
640 
642  flushPendingLabels(DF, DF->getContents().size());
643 
644  int64_t OffsetValue;
645  if (Offset.evaluateAsAbsolute(OffsetValue)) {
646  if (OffsetValue < 0)
647  llvm_unreachable(".reloc offset is negative");
648  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
649  return false;
650  }
651 
652  if (Offset.getKind() != llvm::MCExpr::SymbolRef)
653  llvm_unreachable(".reloc offset is not absolute nor a label");
654 
655  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(Offset);
656  if (SRE.getSymbol().isDefined()) {
657  DF->getFixups().push_back(MCFixup::create(SRE.getSymbol().getOffset(),
658  Expr, Kind, Loc));
659  return false;
660  }
661 
662  PendingFixups.emplace_back(&SRE.getSymbol(), DF,
663  MCFixup::create(-1, Expr, Kind, Loc));
664  return false;
665 }
666 
667 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
668  SMLoc Loc) {
670  flushPendingLabels(DF, DF->getContents().size());
671 
672  assert(getCurrentSectionOnly() && "need a section");
673  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
674 }
675 
676 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
677  int64_t Expr, SMLoc Loc) {
678  int64_t IntNumValues;
679  // Do additional checking now if we can resolve the value.
680  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
681  if (IntNumValues < 0) {
684  "'.fill' directive with negative repeat count has no effect");
685  return;
686  }
687  // Emit now if we can for better errors.
688  int64_t NonZeroSize = Size > 4 ? 4 : Size;
689  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
690  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
691  EmitIntValue(Expr, NonZeroSize);
692  if (NonZeroSize < Size)
693  EmitIntValue(0, Size - NonZeroSize);
694  }
695  return;
696  }
697 
698  // Otherwise emit as fragment.
700  flushPendingLabels(DF, DF->getContents().size());
701 
702  assert(getCurrentSectionOnly() && "need a section");
703  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
704 }
705 
707  getAssembler().addFileName(Filename);
708 }
709 
712 }
713 
717 }
718 
721 
722  // If we are generating dwarf for assembly source files dump out the sections.
723  if (getContext().getGenDwarfForAssembly())
724  MCGenDwarfInfo::Emit(this);
725 
726  // Dump out the dwarf file & directory tables and line tables.
727  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
728 
730  resolvePendingFixups();
731  getAssembler().Finish();
732 }
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 &#39;.loc fileno lineno ...&#39; assembler directive.
Definition: MCStreamer.cpp:231
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:326
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:323
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:148
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition: MCStreamer.cpp:159
bool 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:97
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:435
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1852
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:1349
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:983
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:324
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.
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:956
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:365
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:251
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:248
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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:295
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:590
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:297
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:912
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.
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:256
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:124
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:189
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:316
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:287
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:964
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:293
const MCSymbol & getSymbol() const
Definition: MCExpr.h:336
ExprKind getKind() const
Definition: MCExpr.h:73
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:320
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:445
bool getRelaxAll() const
Definition: MCAssembler.h:321
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:248
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:346
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:294
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...
bool hasValue() const
Definition: Optional.h:165
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:270
void EmitBundleUnlock() override
Ends a bundle-locked group.
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
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
References to labels and assigned expressions.
Definition: MCExpr.h:41
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:347
Subtraction.
Definition: MCExpr.h:441
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1792
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:139
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