LLVM  10.0.0svn
MCObjectStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
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 
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/MC/MCAsmBackend.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCCodeEmitter.h"
14 #include "llvm/MC/MCCodeView.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCDwarf.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCObjectWriter.h"
19 #include "llvm/MC/MCSection.h"
20 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/Support/SourceMgr.h"
23 using namespace llvm;
24 
26  std::unique_ptr<MCAsmBackend> TAB,
27  std::unique_ptr<MCObjectWriter> OW,
28  std::unique_ptr<MCCodeEmitter> Emitter)
29  : MCStreamer(Context),
30  Assembler(std::make_unique<MCAssembler>(
31  Context, std::move(TAB), std::move(Emitter), std::move(OW))),
32  EmitEHFrame(true), EmitDebugFrame(false) {}
33 
35 
36 // AssemblerPtr is used for evaluation of expressions and causes
37 // difference between asm and object outputs. Return nullptr to in
38 // inline asm mode to limit divergence to assembly inputs.
41  return Assembler.get();
42  return nullptr;
43 }
44 
46  if (PendingLabels.empty())
47  return;
48  if (!F) {
49  F = new MCDataFragment();
50  MCSection *CurSection = getCurrentSectionOnly();
51  CurSection->getFragmentList().insert(CurInsertionPoint, F);
52  F->setParent(CurSection);
53  }
54  for (MCSymbol *Sym : PendingLabels) {
55  Sym->setFragment(F);
56  Sym->setOffset(FOffset);
57  }
58  PendingLabels.clear();
59 }
60 
61 // When fixup's offset is a forward declared label, e.g.:
62 //
63 // .reloc 1f, R_MIPS_JALR, foo
64 // 1: nop
65 //
66 // postpone adding it to Fixups vector until the label is defined and its offset
67 // is known.
68 void MCObjectStreamer::resolvePendingFixups() {
69  for (PendingMCFixup &PendingFixup : PendingFixups) {
70  if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
71  getContext().reportError(PendingFixup.Fixup.getLoc(),
72  "unresolved relocation offset");
73  continue;
74  }
75  flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
76  PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
77  PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
78  }
79  PendingFixups.clear();
80 }
81 
82 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
83 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
84 static Optional<uint64_t>
86  assert(Hi && Lo);
88  return None;
89 
90  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
91  Hi->isVariable() || Lo->isVariable())
92  return None;
93 
94  return Hi->getOffset() - Lo->getOffset();
95 }
96 
98  const MCSymbol *Lo,
99  unsigned Size) {
100  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
101  EmitIntValue(*Diff, Size);
102  return;
103  }
105 }
106 
108  const MCSymbol *Lo) {
109  if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
110  EmitULEB128IntValue(*Diff);
111  return;
112  }
114 }
115 
117  if (Assembler)
118  Assembler->reset();
119  CurInsertionPoint = MCSection::iterator();
120  EmitEHFrame = true;
121  EmitDebugFrame = false;
122  PendingLabels.clear();
124 }
125 
127  if (!getNumFrameInfos())
128  return;
129 
130  if (EmitEHFrame)
131  MCDwarfFrameEmitter::Emit(*this, MAB, true);
132 
133  if (EmitDebugFrame)
134  MCDwarfFrameEmitter::Emit(*this, MAB, false);
135 }
136 
138  assert(getCurrentSectionOnly() && "No current section!");
139 
140  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
141  return &*std::prev(CurInsertionPoint);
142 
143  return nullptr;
144 }
145 
147  const MCAssembler &Assembler,
148  const MCSubtargetInfo *STI) {
149  if (!F.hasInstructions())
150  return true;
151  // When bundling is enabled, we don't want to add data to a fragment that
152  // already has instructions (see MCELFStreamer::EmitInstToData for details)
153  if (Assembler.isBundlingEnabled())
154  return Assembler.getRelaxAll();
155  // If the subtarget is changed mid fragment we start a new fragment to record
156  // the new STI.
157  return !STI || F.getSubtargetInfo() == STI;
158 }
159 
162  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
163  if (!F || !CanReuseDataFragment(*F, *Assembler, STI)) {
164  F = new MCDataFragment();
165  insert(F);
166  }
167  return F;
168 }
169 
172  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
173  if (!F) {
174  F = new MCPaddingFragment();
175  insert(F);
176  }
177  return F;
178 }
179 
181  Assembler->registerSymbol(Sym);
182 }
183 
185  MCStreamer::EmitCFISections(EH, Debug);
186  EmitEHFrame = EH;
187  EmitDebugFrame = Debug;
188 }
189 
191  SMLoc Loc) {
192  MCStreamer::EmitValueImpl(Value, Size, Loc);
194  flushPendingLabels(DF, DF->getContents().size());
195 
197 
198  // Avoid fixups when possible.
199  int64_t AbsValue;
200  if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
201  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
203  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
204  return;
205  }
206  EmitIntValue(AbsValue, Size);
207  return;
208  }
209  DF->getFixups().push_back(
211  MCFixup::getKindForSize(Size, false), Loc));
212  DF->getContents().resize(DF->getContents().size() + Size, 0);
213 }
214 
215 MCSymbol *MCObjectStreamer::EmitCFILabel() {
216  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
217  EmitLabel(Label);
218  return Label;
219 }
220 
221 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
222  // We need to create a local symbol to avoid relocations.
223  Frame.Begin = getContext().createTempSymbol();
224  EmitLabel(Frame.Begin);
225 }
226 
227 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
228  Frame.End = getContext().createTempSymbol();
229  EmitLabel(Frame.End);
230 }
231 
233  MCStreamer::EmitLabel(Symbol, Loc);
234 
235  getAssembler().registerSymbol(*Symbol);
236 
237  // If there is a current fragment, mark the symbol as pointing into it.
238  // Otherwise queue the label and set its fragment pointer when we emit the
239  // next fragment.
240  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
241  if (F && !(getAssembler().isBundlingEnabled() &&
242  getAssembler().getRelaxAll())) {
243  Symbol->setFragment(F);
244  Symbol->setOffset(F->getContents().size());
245  } else {
246  PendingLabels.push_back(Symbol);
247  }
248 }
249 
251  MCStreamer::EmitLabel(Symbol, Loc);
252  getAssembler().registerSymbol(*Symbol);
253  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
254  if (DF)
255  Symbol->setFragment(F);
256  else
257  PendingLabels.push_back(Symbol);
258 }
259 
261  int64_t IntValue;
262  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
263  EmitULEB128IntValue(IntValue);
264  return;
265  }
266  insert(new MCLEBFragment(*Value, false));
267 }
268 
270  int64_t IntValue;
271  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
272  EmitSLEB128IntValue(IntValue);
273  return;
274  }
275  insert(new MCLEBFragment(*Value, true));
276 }
277 
279  const MCSymbol *Symbol) {
280  report_fatal_error("This file format doesn't support weak aliases.");
281 }
282 
284  const MCExpr *Subsection) {
285  changeSectionImpl(Section, Subsection);
286 }
287 
289  const MCExpr *Subsection) {
290  assert(Section && "Cannot switch to a null section!");
291  flushPendingLabels(nullptr);
293 
294  bool Created = getAssembler().registerSection(*Section);
295 
296  int64_t IntSubsection = 0;
297  if (Subsection &&
298  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
299  report_fatal_error("Cannot evaluate subsection number");
300  if (IntSubsection < 0 || IntSubsection > 8192)
301  report_fatal_error("Subsection number out of range");
302  CurInsertionPoint =
303  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
304  return Created;
305 }
306 
308  getAssembler().registerSymbol(*Symbol);
309  MCStreamer::EmitAssignment(Symbol, Value);
310 }
311 
313  return Sec.hasInstructions();
314 }
315 
317  const MCSubtargetInfo &STI) {
319  EmitInstructionImpl(Inst, STI);
321 }
322 
323 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
324  const MCSubtargetInfo &STI) {
325  MCStreamer::EmitInstruction(Inst, STI);
326 
328  Sec->setHasInstructions(true);
329 
330  // Now that a machine instruction has been assembled into this section, make
331  // a line entry for any .loc directive that has been seen.
333 
334  // If this instruction doesn't need relaxation, just emit it as data.
335  MCAssembler &Assembler = getAssembler();
336  if (!Assembler.getBackend().mayNeedRelaxation(Inst, STI)) {
337  EmitInstToData(Inst, STI);
338  return;
339  }
340 
341  // Otherwise, relax and emit it as data if either:
342  // - The RelaxAll flag was passed
343  // - Bundling is enabled and this instruction is inside a bundle-locked
344  // group. We want to emit all such instructions into the same data
345  // fragment.
346  if (Assembler.getRelaxAll() ||
347  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
348  MCInst Relaxed;
349  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
350  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
351  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
352  EmitInstToData(Relaxed, STI);
353  return;
354  }
355 
356  // Otherwise emit to a separate fragment.
357  EmitInstToFragment(Inst, STI);
358 }
359 
361  const MCSubtargetInfo &STI) {
362  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
363  llvm_unreachable("All instructions should have already been relaxed");
364 
365  // Always create a new, separate fragment here, because its size can change
366  // during relaxation.
367  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
368  insert(IF);
369 
370  SmallString<128> Code;
371  raw_svector_ostream VecOS(Code);
372  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
373  STI);
374  IF->getContents().append(Code.begin(), Code.end());
375 }
376 
377 #ifndef NDEBUG
378 static const char *const BundlingNotImplementedMsg =
379  "Aligned bundling is not implemented for this object format";
380 #endif
381 
382 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
383  llvm_unreachable(BundlingNotImplementedMsg);
384 }
385 
386 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
387  llvm_unreachable(BundlingNotImplementedMsg);
388 }
389 
391  llvm_unreachable(BundlingNotImplementedMsg);
392 }
393 
394 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
395  unsigned Column, unsigned Flags,
396  unsigned Isa,
397  unsigned Discriminator,
398  StringRef FileName) {
399  // In case we see two .loc directives in a row, make sure the
400  // first one gets a line entry.
402 
403  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
404  Isa, Discriminator, FileName);
405 }
406 
407 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
408  const MCSymbol *B) {
409  MCContext &Context = OS.getContext();
411  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
412  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
413  const MCExpr *AddrDelta =
414  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
415  return AddrDelta;
416 }
417 
419  MCDwarfLineTableParams Params,
420  int64_t LineDelta, const MCSymbol *Label,
421  int PointerSize) {
422  // emit the sequence to set the address
423  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
424  OS.EmitULEB128IntValue(PointerSize + 1);
425  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
426  OS.EmitSymbolValue(Label, PointerSize);
427 
428  // emit the sequence for the LineDelta (from 1) and a zero address delta.
429  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
430 }
431 
433  const MCSymbol *LastLabel,
434  const MCSymbol *Label,
435  unsigned PointerSize) {
436  if (!LastLabel) {
437  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
438  Label, PointerSize);
439  return;
440  }
441  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
442  int64_t Res;
443  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
444  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
445  Res);
446  return;
447  }
448  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
449 }
450 
452  const MCSymbol *Label) {
453  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
454  int64_t Res;
455  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
457  return;
458  }
459  insert(new MCDwarfCallFrameFragment(*AddrDelta));
460 }
461 
462 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
463  unsigned Line, unsigned Column,
464  bool PrologueEnd, bool IsStmt,
465  StringRef FileName, SMLoc Loc) {
466  // Validate the directive.
467  if (!checkCVLocSection(FunctionId, FileNo, Loc))
468  return;
469 
470  // Emit a label at the current position and record it in the CodeViewContext.
471  MCSymbol *LineSym = getContext().createTempSymbol();
472  EmitLabel(LineSym);
473  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
474  FileNo, Line, Column, PrologueEnd,
475  IsStmt);
476 }
477 
479  const MCSymbol *Begin,
480  const MCSymbol *End) {
481  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
482  End);
483  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
484 }
485 
487  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
488  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
490  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
491  FnEndSym);
493  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
494 }
495 
497  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
498  StringRef FixedSizePortion) {
499  MCFragment *Frag =
500  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
501  // Attach labels that were pending before we created the defrange fragment to
502  // the beginning of the new fragment.
503  flushPendingLabels(Frag, 0);
504  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
505 }
506 
509 }
512 }
513 
516 }
517 
521  flushPendingLabels(DF, DF->getContents().size());
522  DF->getContents().append(Data.begin(), Data.end());
523 
524  // EmitBytes might not cover all possible ways we emit data (or could be used
525  // to emit executable code in some cases), but is the best method we have
526  // right now for checking this.
528  Sec->setHasData(true);
529 }
530 
532  int64_t Value,
533  unsigned ValueSize,
534  unsigned MaxBytesToEmit) {
535  if (MaxBytesToEmit == 0)
536  MaxBytesToEmit = ByteAlignment;
537  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
538 
539  // Update the maximum alignment on the current section if necessary.
540  MCSection *CurSec = getCurrentSectionOnly();
541  if (ByteAlignment > CurSec->getAlignment())
542  CurSec->setAlignment(ByteAlignment);
543 }
544 
546  unsigned MaxBytesToEmit) {
547  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
548  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
549 }
550 
552  unsigned char Value,
553  SMLoc Loc) {
554  insert(new MCOrgFragment(*Offset, Value, Loc));
555 }
556 
558  const MCCodePaddingContext &Context) {
560 }
561 
563  const MCCodePaddingContext &Context) {
565 }
566 
567 // Associate DTPRel32 fixup with data and resize data area
570  flushPendingLabels(DF, DF->getContents().size());
571 
572  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
573  Value, FK_DTPRel_4));
574  DF->getContents().resize(DF->getContents().size() + 4, 0);
575 }
576 
577 // Associate DTPRel64 fixup with data and resize data area
580  flushPendingLabels(DF, DF->getContents().size());
581 
582  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
583  Value, FK_DTPRel_8));
584  DF->getContents().resize(DF->getContents().size() + 8, 0);
585 }
586 
587 // Associate TPRel32 fixup with data and resize data area
590  flushPendingLabels(DF, DF->getContents().size());
591 
592  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
593  Value, FK_TPRel_4));
594  DF->getContents().resize(DF->getContents().size() + 4, 0);
595 }
596 
597 // Associate TPRel64 fixup with data and resize data area
600  flushPendingLabels(DF, DF->getContents().size());
601 
602  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
603  Value, FK_TPRel_8));
604  DF->getContents().resize(DF->getContents().size() + 8, 0);
605 }
606 
607 // Associate GPRel32 fixup with data and resize data area
610  flushPendingLabels(DF, DF->getContents().size());
611 
612  DF->getFixups().push_back(
614  DF->getContents().resize(DF->getContents().size() + 4, 0);
615 }
616 
617 // Associate GPRel64 fixup with data and resize data area
620  flushPendingLabels(DF, DF->getContents().size());
621 
622  DF->getFixups().push_back(
624  DF->getContents().resize(DF->getContents().size() + 8, 0);
625 }
626 
628  const MCExpr *Expr, SMLoc Loc,
629  const MCSubtargetInfo &STI) {
630  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
631  if (!MaybeKind.hasValue())
632  return true;
633 
634  MCFixupKind Kind = *MaybeKind;
635 
636  if (Expr == nullptr)
637  Expr =
638  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
639 
641  flushPendingLabels(DF, DF->getContents().size());
642 
643  int64_t OffsetValue;
644  if (Offset.evaluateAsAbsolute(OffsetValue)) {
645  if (OffsetValue < 0)
646  llvm_unreachable(".reloc offset is negative");
647  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
648  return false;
649  }
650 
651  if (Offset.getKind() != llvm::MCExpr::SymbolRef)
652  llvm_unreachable(".reloc offset is not absolute nor a label");
653 
654  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(Offset);
655  if (SRE.getSymbol().isDefined()) {
656  DF->getFixups().push_back(MCFixup::create(SRE.getSymbol().getOffset(),
657  Expr, Kind, Loc));
658  return false;
659  }
660 
661  PendingFixups.emplace_back(&SRE.getSymbol(), DF,
662  MCFixup::create(-1, Expr, Kind, Loc));
663  return false;
664 }
665 
666 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
667  SMLoc Loc) {
669  flushPendingLabels(DF, DF->getContents().size());
670 
671  assert(getCurrentSectionOnly() && "need a section");
672  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
673 }
674 
675 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
676  int64_t Expr, SMLoc Loc) {
677  int64_t IntNumValues;
678  // Do additional checking now if we can resolve the value.
679  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
680  if (IntNumValues < 0) {
683  "'.fill' directive with negative repeat count has no effect");
684  return;
685  }
686  // Emit now if we can for better errors.
687  int64_t NonZeroSize = Size > 4 ? 4 : Size;
688  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
689  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
690  EmitIntValue(Expr, NonZeroSize);
691  if (NonZeroSize < Size)
692  EmitIntValue(0, Size - NonZeroSize);
693  }
694  return;
695  }
696 
697  // Otherwise emit as fragment.
699  flushPendingLabels(DF, DF->getContents().size());
700 
701  assert(getCurrentSectionOnly() && "need a section");
702  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
703 }
704 
706  getAssembler().addFileName(Filename);
707 }
708 
711 }
712 
716 }
717 
720 
721  // If we are generating dwarf for assembly source files dump out the sections.
722  if (getContext().getGenDwarfForAssembly())
723  MCGenDwarfInfo::Emit(this);
724 
725  // Dump out the dwarf file & directory tables and line tables.
726  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
727 
729  resolvePendingFixups();
730  getAssembler().Finish();
731 }
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:235
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
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:342
Fragment for adding required padding.
Definition: MCFragment.h:342
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:326
A eight-byte dtp relative fixup.
Definition: MCFixup.h:38
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
bool hasInstructions() const
Definition: MCSection.h:140
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:87
static const char *const BundlingNotImplementedMsg
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:327
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:152
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
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:163
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:297
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:41
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:119
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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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:121
virtual void reset()
State management.
Definition: MCStreamer.cpp:96
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:434
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1890
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:530
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
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
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.
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:644
bool isBundlingEnabled() const
Definition: MCAssembler.h:323
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.
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:415
unsigned getAlignment() const
Definition: MCSection.h:120
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:421
MCContext & getContext() const
Definition: MCStreamer.h:251
unsigned getNumFrameInfos()
Definition: MCStreamer.cpp:110
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:242
Definition: BitVector.h:937
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
void setHasInstructions(bool Value)
Definition: MCSection.h:141
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:294
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:39
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
bool registerSection(MCSection &Section)
MCSymbol * Begin
Definition: MCDwarf.h:609
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:169
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:296
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:274
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:962
Context object for machine code objects.
Definition: MCContext.h:65
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:35
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:581
MCAssembler * getAssemblerPtr() override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
bool isBundleLocked() const
Definition: MCSection.h:131
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:256
void setHasData(bool Value)
Definition: MCSection.h:144
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:128
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:158
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:272
A four-byte dtp relative fixup.
Definition: MCFixup.h:37
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:225
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:320
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.
MCAssembler & getAssembler()
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:22
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:224
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:687
uint64_t getOffset() const
Definition: MCSymbol.h:324
A eight-byte tp relative fixup.
Definition: MCFixup.h:40
void EmitFrames(MCAsmBackend *MAB)
const SourceMgr * getSourceManager() const
Definition: MCContext.h:314
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:397
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:330
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:93
size_t size() const
Definition: SmallVector.h:52
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:613
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:286
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:292
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
const MCSymbol & getSymbol() const
Definition: MCExpr.h:340
ExprKind getKind() const
Definition: MCExpr.h:68
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:396
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:324
void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
void EmitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:143
void addFileName(StringRef FileName)
Definition: MCAssembler.h:444
bool getRelaxAll() const
Definition: MCAssembler.h:320
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:249
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:344
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:130
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:109
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:298
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1136
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
iterator begin() const
Definition: StringRef.h:101
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
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:232
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:259
iterator insert(iterator where, pointer New)
Definition: ilist.h:226
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:170
References to labels and assigned expressions.
Definition: MCExpr.h:40
uint32_t Size
Definition: Profile.cpp:46
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:247
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:677
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
Definition: MCFixup.h:137
Fragment for data and encoded instructions.
Definition: MCFragment.h:243
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:58
LLVM Value Representation.
Definition: Value.h:73
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))
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:397
Subtraction.
Definition: MCExpr.h:445
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1821
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
FragmentListType::iterator iterator
Definition: MCSection.h:52
void EmitCVFileChecksumsDirective() override
This implements the CodeView &#39;.cv_filechecksums&#39; assembler directive.
Represents a location in source code.
Definition: SMLoc.h:23
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:392
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:192
void setParent(MCSection *Value)
Definition: MCFragment.h:99
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
iterator end() const
Definition: StringRef.h:103
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:149
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 resize(size_type N)
Definition: SmallVector.h:344