LLVM  14.0.0git
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/MCAsmInfo.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"
20 #include "llvm/MC/MCObjectWriter.h"
21 #include "llvm/MC/MCSection.h"
22 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/MC/MCValue.h"
25 #include "llvm/Support/SourceMgr.h"
26 using namespace llvm;
27 
29  std::unique_ptr<MCAsmBackend> TAB,
30  std::unique_ptr<MCObjectWriter> OW,
31  std::unique_ptr<MCCodeEmitter> Emitter)
33  Assembler(std::make_unique<MCAssembler>(
34  Context, std::move(TAB), std::move(Emitter), std::move(OW))),
35  EmitEHFrame(true), EmitDebugFrame(false) {
36  if (Assembler->getBackendPtr())
37  setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
38 }
39 
41 
42 // AssemblerPtr is used for evaluation of expressions and causes
43 // difference between asm and object outputs. Return nullptr to in
44 // inline asm mode to limit divergence to assembly inputs.
47  return Assembler.get();
48  return nullptr;
49 }
50 
52  MCSection *CurSection = getCurrentSectionOnly();
53  if (CurSection) {
54  // Register labels that have not yet been assigned to a Section.
55  if (!PendingLabels.empty()) {
56  for (MCSymbol* Sym : PendingLabels)
57  CurSection->addPendingLabel(Sym);
58  PendingLabels.clear();
59  }
60 
61  // Add this label to the current Section / Subsection.
62  CurSection->addPendingLabel(S, CurSubsectionIdx);
63 
64  // Add this Section to the list of PendingLabelSections.
65  PendingLabelSections.insert(CurSection);
66  } else
67  // There is no Section / Subsection for this label yet.
68  PendingLabels.push_back(S);
69 }
70 
72  MCSection *CurSection = getCurrentSectionOnly();
73  if (!CurSection) {
74  assert(PendingLabels.empty());
75  return;
76  }
77  // Register labels that have not yet been assigned to a Section.
78  if (!PendingLabels.empty()) {
79  for (MCSymbol* Sym : PendingLabels)
80  CurSection->addPendingLabel(Sym, CurSubsectionIdx);
81  PendingLabels.clear();
82  }
83 
84  // Associate a fragment with this label, either the supplied fragment
85  // or an empty data fragment.
86  if (F)
87  CurSection->flushPendingLabels(F, FOffset, CurSubsectionIdx);
88  else
89  CurSection->flushPendingLabels(nullptr, 0, CurSubsectionIdx);
90 }
91 
93  // Register labels that have not yet been assigned to a Section.
94  if (!PendingLabels.empty()) {
95  MCSection *CurSection = getCurrentSectionOnly();
96  assert(CurSection);
97  for (MCSymbol* Sym : PendingLabels)
98  CurSection->addPendingLabel(Sym, CurSubsectionIdx);
99  PendingLabels.clear();
100  }
101 
102  // Assign an empty data fragment to all remaining pending labels.
103  for (MCSection* Section : PendingLabelSections)
104  Section->flushPendingLabels();
105 }
106 
107 // When fixup's offset is a forward declared label, e.g.:
108 //
109 // .reloc 1f, R_MIPS_JALR, foo
110 // 1: nop
111 //
112 // postpone adding it to Fixups vector until the label is defined and its offset
113 // is known.
114 void MCObjectStreamer::resolvePendingFixups() {
115  for (PendingMCFixup &PendingFixup : PendingFixups) {
116  if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
117  getContext().reportError(PendingFixup.Fixup.getLoc(),
118  "unresolved relocation offset");
119  continue;
120  }
121  flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
122  PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
123  PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
124  }
125  PendingFixups.clear();
126 }
127 
128 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
129 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
131  const MCSymbol *Lo) {
132  assert(Hi && Lo);
133  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
134  Hi->isVariable() || Lo->isVariable())
135  return None;
136 
137  return Hi->getOffset() - Lo->getOffset();
138 }
139 
141  const MCSymbol *Lo,
142  unsigned Size) {
143  if (!getAssembler().getContext().getTargetTriple().isRISCV())
145  return emitIntValue(*Diff, Size);
147 }
148 
150  const MCSymbol *Lo) {
151  if (!getAssembler().getContext().getTargetTriple().isRISCV())
153  return emitULEB128IntValue(*Diff);
155 }
156 
158  if (Assembler)
159  Assembler->reset();
160  CurInsertionPoint = MCSection::iterator();
161  EmitEHFrame = true;
162  EmitDebugFrame = false;
163  PendingLabels.clear();
164  PendingLabelSections.clear();
166 }
167 
169  if (!getNumFrameInfos())
170  return;
171 
172  if (EmitEHFrame)
173  MCDwarfFrameEmitter::Emit(*this, MAB, true);
174 
175  if (EmitDebugFrame)
176  MCDwarfFrameEmitter::Emit(*this, MAB, false);
177 }
178 
180  assert(getCurrentSectionOnly() && "No current section!");
181 
182  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
183  return &*std::prev(CurInsertionPoint);
184 
185  return nullptr;
186 }
187 
189  const MCAssembler &Assembler,
190  const MCSubtargetInfo *STI) {
191  if (!F.hasInstructions())
192  return true;
193  // When bundling is enabled, we don't want to add data to a fragment that
194  // already has instructions (see MCELFStreamer::emitInstToData for details)
195  if (Assembler.isBundlingEnabled())
196  return Assembler.getRelaxAll();
197  // If the subtarget is changed mid fragment we start a new fragment to record
198  // the new STI.
199  return !STI || F.getSubtargetInfo() == STI;
200 }
201 
204  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
205  if (!F || !canReuseDataFragment(*F, *Assembler, STI)) {
206  F = new MCDataFragment();
207  insert(F);
208  }
209  return F;
210 }
211 
213  Assembler->registerSymbol(Sym);
214 }
215 
218  EmitEHFrame = EH;
219  EmitDebugFrame = Debug;
220 }
221 
223  SMLoc Loc) {
226  flushPendingLabels(DF, DF->getContents().size());
227 
229 
230  // Avoid fixups when possible.
231  int64_t AbsValue;
232  if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
233  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
235  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
236  return;
237  }
238  emitIntValue(AbsValue, Size);
239  return;
240  }
241  DF->getFixups().push_back(
242  MCFixup::create(DF->getContents().size(), Value,
243  MCFixup::getKindForSize(Size, false), Loc));
244  DF->getContents().resize(DF->getContents().size() + Size, 0);
245 }
246 
247 MCSymbol *MCObjectStreamer::emitCFILabel() {
248  MCSymbol *Label = getContext().createTempSymbol("cfi");
249  emitLabel(Label);
250  return Label;
251 }
252 
253 void MCObjectStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
254  // We need to create a local symbol to avoid relocations.
255  Frame.Begin = getContext().createTempSymbol();
256  emitLabel(Frame.Begin);
257 }
258 
259 void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
260  Frame.End = getContext().createTempSymbol();
261  emitLabel(Frame.End);
262 }
263 
266 
268 
269  // If there is a current fragment, mark the symbol as pointing into it.
270  // Otherwise queue the label and set its fragment pointer when we emit the
271  // next fragment.
272  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
273  if (F && !(getAssembler().isBundlingEnabled() &&
274  getAssembler().getRelaxAll())) {
275  Symbol->setFragment(F);
276  Symbol->setOffset(F->getContents().size());
277  } else {
278  // Assign all pending labels to offset 0 within the dummy "pending"
279  // fragment. (They will all be reassigned to a real fragment in
280  // flushPendingLabels())
281  Symbol->setOffset(0);
283  }
284 }
285 
286 // Emit a label at a previously emitted fragment/offset position. This must be
287 // within the currently-active section.
290  assert(F->getParent() == getCurrentSectionOnly());
291 
294  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
295  Symbol->setOffset(Offset);
296  if (DF) {
297  Symbol->setFragment(F);
298  } else {
299  assert(isa<MCDummyFragment>(F) &&
300  "F must either be an MCDataFragment or the pending MCDummyFragment");
301  assert(Offset == 0);
303  }
304 }
305 
307  int64_t IntValue;
308  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
309  emitULEB128IntValue(IntValue);
310  return;
311  }
312  insert(new MCLEBFragment(*Value, false));
313 }
314 
316  int64_t IntValue;
317  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
318  emitSLEB128IntValue(IntValue);
319  return;
320  }
321  insert(new MCLEBFragment(*Value, true));
322 }
323 
325  const MCSymbol *Symbol) {
326  report_fatal_error("This file format doesn't support weak aliases.");
327 }
328 
330  const MCExpr *Subsection) {
331  changeSectionImpl(Section, Subsection);
332 }
333 
335  const MCExpr *Subsection) {
336  assert(Section && "Cannot switch to a null section!");
338 
339  bool Created = getAssembler().registerSection(*Section);
340 
341  int64_t IntSubsection = 0;
342  if (Subsection &&
343  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
344  report_fatal_error("Cannot evaluate subsection number");
345  if (IntSubsection < 0 || IntSubsection > 8192)
346  report_fatal_error("Subsection number out of range");
347  CurSubsectionIdx = unsigned(IntSubsection);
348  CurInsertionPoint =
349  Section->getSubsectionInsertionPoint(CurSubsectionIdx);
350  return Created;
351 }
352 
356 }
357 
359  return Sec.hasInstructions();
360 }
361 
363  const MCSubtargetInfo &STI) {
364  const MCSection &Sec = *getCurrentSectionOnly();
365  if (Sec.isVirtualSection()) {
367  " section '" + Sec.getName() +
368  "' cannot have instructions");
369  return;
370  }
371  getAssembler().getBackend().emitInstructionBegin(*this, Inst, STI);
372  emitInstructionImpl(Inst, STI);
373  getAssembler().getBackend().emitInstructionEnd(*this, Inst);
374 }
375 
376 void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
377  const MCSubtargetInfo &STI) {
378  MCStreamer::emitInstruction(Inst, STI);
379 
381  Sec->setHasInstructions(true);
382 
383  // Now that a machine instruction has been assembled into this section, make
384  // a line entry for any .loc directive that has been seen.
386 
387  // If this instruction doesn't need relaxation, just emit it as data.
388  MCAssembler &Assembler = getAssembler();
389  MCAsmBackend &Backend = Assembler.getBackend();
390  if (!(Backend.mayNeedRelaxation(Inst, STI) ||
391  Backend.allowEnhancedRelaxation())) {
392  emitInstToData(Inst, STI);
393  return;
394  }
395 
396  // Otherwise, relax and emit it as data if either:
397  // - The RelaxAll flag was passed
398  // - Bundling is enabled and this instruction is inside a bundle-locked
399  // group. We want to emit all such instructions into the same data
400  // fragment.
401  if (Assembler.getRelaxAll() ||
402  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
403  MCInst Relaxed = Inst;
404  while (Backend.mayNeedRelaxation(Relaxed, STI))
405  Backend.relaxInstruction(Relaxed, STI);
406  emitInstToData(Relaxed, STI);
407  return;
408  }
409 
410  // Otherwise emit to a separate fragment.
411  emitInstToFragment(Inst, STI);
412 }
413 
415  const MCSubtargetInfo &STI) {
416  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
417  llvm_unreachable("All instructions should have already been relaxed");
418 
419  // Always create a new, separate fragment here, because its size can change
420  // during relaxation.
421  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
422  insert(IF);
423 
424  SmallString<128> Code;
425  raw_svector_ostream VecOS(Code);
426  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
427  STI);
428  IF->getContents().append(Code.begin(), Code.end());
429 }
430 
431 #ifndef NDEBUG
432 static const char *const BundlingNotImplementedMsg =
433  "Aligned bundling is not implemented for this object format";
434 #endif
435 
436 void MCObjectStreamer::emitBundleAlignMode(unsigned AlignPow2) {
438 }
439 
440 void MCObjectStreamer::emitBundleLock(bool AlignToEnd) {
442 }
443 
446 }
447 
448 void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
449  unsigned Column, unsigned Flags,
450  unsigned Isa,
451  unsigned Discriminator,
452  StringRef FileName) {
453  // In case we see two .loc directives in a row, make sure the
454  // first one gets a line entry.
456 
457  this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
458  Discriminator, FileName);
459 }
460 
461 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
462  const MCSymbol *B) {
463  MCContext &Context = OS.getContext();
465  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
466  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
467  const MCExpr *AddrDelta =
469  return AddrDelta;
470 }
471 
473  MCDwarfLineTableParams Params,
474  int64_t LineDelta, const MCSymbol *Label,
475  int PointerSize) {
476  // emit the sequence to set the address
477  OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
479  OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
480  OS.emitSymbolValue(Label, PointerSize);
481 
482  // emit the sequence for the LineDelta (from 1) and a zero address delta.
483  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
484 }
485 
487  const MCSymbol *LastLabel,
488  const MCSymbol *Label,
489  unsigned PointerSize) {
490  if (!LastLabel) {
491  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
492  Label, PointerSize);
493  return;
494  }
495  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
496  int64_t Res;
497  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
498  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
499  Res);
500  return;
501  }
502  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
503 }
504 
506  MCSymbol *LastLabel) {
507  // Emit a DW_LNE_end_sequence for the end of the section.
508  // Use the section end label to compute the address delta and use INT64_MAX
509  // as the line delta which is the signal that this is actually a
510  // DW_LNE_end_sequence.
511  MCSymbol *SectionEnd = endSection(Section);
512 
513  // Switch back the dwarf line section, in case endSection had to switch the
514  // section.
515  MCContext &Ctx = getContext();
517 
518  const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
519  emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
520  AsmInfo->getCodePointerSize());
521 }
522 
524  const MCSymbol *Label) {
525  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
526  int64_t Res;
527  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
529  return;
530  }
531  insert(new MCDwarfCallFrameFragment(*AddrDelta));
532 }
533 
534 void MCObjectStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
535  unsigned Line, unsigned Column,
536  bool PrologueEnd, bool IsStmt,
537  StringRef FileName, SMLoc Loc) {
538  // Validate the directive.
539  if (!checkCVLocSection(FunctionId, FileNo, Loc))
540  return;
541 
542  // Emit a label at the current position and record it in the CodeViewContext.
543  MCSymbol *LineSym = getContext().createTempSymbol();
544  emitLabel(LineSym);
545  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
546  FileNo, Line, Column, PrologueEnd,
547  IsStmt);
548 }
549 
551  const MCSymbol *Begin,
552  const MCSymbol *End) {
553  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
554  End);
555  this->MCStreamer::emitCVLinetableDirective(FunctionId, Begin, End);
556 }
557 
559  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
560  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
562  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
563  FnEndSym);
565  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
566 }
567 
569  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
570  StringRef FixedSizePortion) {
571  MCFragment *Frag =
572  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
573  // Attach labels that were pending before we created the defrange fragment to
574  // the beginning of the new fragment.
575  flushPendingLabels(Frag, 0);
576  this->MCStreamer::emitCVDefRangeDirective(Ranges, FixedSizePortion);
577 }
578 
581 }
584 }
585 
588 }
589 
593  flushPendingLabels(DF, DF->getContents().size());
594  DF->getContents().append(Data.begin(), Data.end());
595 }
596 
598  int64_t Value,
599  unsigned ValueSize,
600  unsigned MaxBytesToEmit) {
601  if (MaxBytesToEmit == 0)
602  MaxBytesToEmit = ByteAlignment;
603  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
604 
605  // Update the maximum alignment on the current section if necessary.
606  MCSection *CurSec = getCurrentSectionOnly();
607  if (ByteAlignment > CurSec->getAlignment())
608  CurSec->setAlignment(Align(ByteAlignment));
609 }
610 
612  const MCSubtargetInfo *STI,
613  unsigned MaxBytesToEmit) {
614  emitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
615  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true, STI);
616 }
617 
619  unsigned char Value,
620  SMLoc Loc) {
621  insert(new MCOrgFragment(*Offset, Value, Loc));
622 }
623 
624 // Associate DTPRel32 fixup with data and resize data area
627  flushPendingLabels(DF, DF->getContents().size());
628 
629  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
630  Value, FK_DTPRel_4));
631  DF->getContents().resize(DF->getContents().size() + 4, 0);
632 }
633 
634 // Associate DTPRel64 fixup with data and resize data area
637  flushPendingLabels(DF, DF->getContents().size());
638 
639  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
640  Value, FK_DTPRel_8));
641  DF->getContents().resize(DF->getContents().size() + 8, 0);
642 }
643 
644 // Associate TPRel32 fixup with data and resize data area
647  flushPendingLabels(DF, DF->getContents().size());
648 
649  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
650  Value, FK_TPRel_4));
651  DF->getContents().resize(DF->getContents().size() + 4, 0);
652 }
653 
654 // Associate TPRel64 fixup with data and resize data area
657  flushPendingLabels(DF, DF->getContents().size());
658 
659  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
660  Value, FK_TPRel_8));
661  DF->getContents().resize(DF->getContents().size() + 8, 0);
662 }
663 
664 // Associate GPRel32 fixup with data and resize data area
667  flushPendingLabels(DF, DF->getContents().size());
668 
669  DF->getFixups().push_back(
670  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
671  DF->getContents().resize(DF->getContents().size() + 4, 0);
672 }
673 
674 // Associate GPRel64 fixup with data and resize data area
677  flushPendingLabels(DF, DF->getContents().size());
678 
679  DF->getFixups().push_back(
680  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
681  DF->getContents().resize(DF->getContents().size() + 8, 0);
682 }
683 
686  MCDataFragment *&DF) {
687  if (Symbol.isVariable()) {
688  const MCExpr *SymbolExpr = Symbol.getVariableValue();
689  MCValue OffsetVal;
690  if(!SymbolExpr->evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
691  return std::make_pair(false,
692  std::string("symbol in .reloc offset is not "
693  "relocatable"));
694  if (OffsetVal.isAbsolute()) {
695  RelocOffset = OffsetVal.getConstant();
696  MCFragment *Fragment = Symbol.getFragment();
697  // FIXME Support symbols with no DF. For example:
698  // .reloc .data, ENUM_VALUE, <some expr>
699  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
700  return std::make_pair(false,
701  std::string("symbol in offset has no data "
702  "fragment"));
703  DF = cast<MCDataFragment>(Fragment);
704  return None;
705  }
706 
707  if (OffsetVal.getSymB())
708  return std::make_pair(false,
709  std::string(".reloc symbol offset is not "
710  "representable"));
711 
712  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
713  if (!SRE.getSymbol().isDefined())
714  return std::make_pair(false,
715  std::string("symbol used in the .reloc offset is "
716  "not defined"));
717 
718  if (SRE.getSymbol().isVariable())
719  return std::make_pair(false,
720  std::string("symbol used in the .reloc offset is "
721  "variable"));
722 
723  MCFragment *Fragment = SRE.getSymbol().getFragment();
724  // FIXME Support symbols with no DF. For example:
725  // .reloc .data, ENUM_VALUE, <some expr>
726  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
727  return std::make_pair(false,
728  std::string("symbol in offset has no data "
729  "fragment"));
730  RelocOffset = SRE.getSymbol().getOffset() + OffsetVal.getConstant();
731  DF = cast<MCDataFragment>(Fragment);
732  } else {
733  RelocOffset = Symbol.getOffset();
734  MCFragment *Fragment = Symbol.getFragment();
735  // FIXME Support symbols with no DF. For example:
736  // .reloc .data, ENUM_VALUE, <some expr>
737  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
738  return std::make_pair(false,
739  std::string("symbol in offset has no data "
740  "fragment"));
741  DF = cast<MCDataFragment>(Fragment);
742  }
743  return None;
744 }
745 
748  const MCExpr *Expr, SMLoc Loc,
749  const MCSubtargetInfo &STI) {
750  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
751  if (!MaybeKind.hasValue())
752  return std::make_pair(true, std::string("unknown relocation name"));
753 
754  MCFixupKind Kind = *MaybeKind;
755 
756  if (Expr == nullptr)
757  Expr =
758  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
759 
761  flushPendingLabels(DF, DF->getContents().size());
762 
763  MCValue OffsetVal;
764  if (!Offset.evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
765  return std::make_pair(false,
766  std::string(".reloc offset is not relocatable"));
767  if (OffsetVal.isAbsolute()) {
768  if (OffsetVal.getConstant() < 0)
769  return std::make_pair(false, std::string(".reloc offset is negative"));
770  DF->getFixups().push_back(
771  MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
772  return None;
773  }
774  if (OffsetVal.getSymB())
775  return std::make_pair(false,
776  std::string(".reloc offset is not representable"));
777 
778  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
779  const MCSymbol &Symbol = SRE.getSymbol();
780  if (Symbol.isDefined()) {
781  uint32_t SymbolOffset = 0;
783  Error = getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
784 
785  if (Error != None)
786  return Error;
787 
788  DF->getFixups().push_back(
789  MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
790  Expr, Kind, Loc));
791  return None;
792  }
793 
794  PendingFixups.emplace_back(&SRE.getSymbol(), DF,
795  MCFixup::create(-1, Expr, Kind, Loc));
796  return None;
797 }
798 
799 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
800  SMLoc Loc) {
802  flushPendingLabels(DF, DF->getContents().size());
803 
804  assert(getCurrentSectionOnly() && "need a section");
805  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
806 }
807 
808 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
809  int64_t Expr, SMLoc Loc) {
810  int64_t IntNumValues;
811  // Do additional checking now if we can resolve the value.
812  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
813  if (IntNumValues < 0) {
816  "'.fill' directive with negative repeat count has no effect");
817  return;
818  }
819  // Emit now if we can for better errors.
820  int64_t NonZeroSize = Size > 4 ? 4 : Size;
821  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
822  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
823  emitIntValue(Expr, NonZeroSize);
824  if (NonZeroSize < Size)
825  emitIntValue(0, Size - NonZeroSize);
826  }
827  return;
828  }
829 
830  // Otherwise emit as fragment.
832  flushPendingLabels(DF, DF->getContents().size());
833 
834  assert(getCurrentSectionOnly() && "need a section");
835  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
836 }
837 
838 void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
839  SMLoc Loc, const MCSubtargetInfo &STI) {
840  // Emit an NOP fragment.
842  flushPendingLabels(DF, DF->getContents().size());
843 
844  assert(getCurrentSectionOnly() && "need a section");
845 
846  insert(new MCNopsFragment(NumBytes, ControlledNopLength, Loc, STI));
847 }
848 
850  getAssembler().addFileName(Filename);
851 }
852 
854  StringRef CompilerVerion,
855  StringRef TimeStamp,
856  StringRef Description) {
857  getAssembler().addFileName(Filename);
858  // TODO: add additional info to integrated assembler.
859 }
860 
863 }
864 
868 }
869 
872 
873  // If we are generating dwarf for assembly source files dump out the sections.
874  if (getContext().getGenDwarfForAssembly())
875  MCGenDwarfInfo::Emit(this);
876 
877  // Dump out the dwarf file & directory tables and line tables.
878  MCDwarfLineTable::emit(this, getAssembler().getDWARFLinetableParams());
879 
880  // Emit pseudo probes for the current module.
882 
883  // Update any remaining pending labels with empty data fragments.
885 
886  resolvePendingFixups();
887  getAssembler().Finish();
888 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCStreamer::emitCVInlineLinetableDirective
virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView '.cv_inline_linetable' assembler directive.
Definition: MCStreamer.cpp:342
llvm::MCObjectStreamer::emitRelocDirective
Optional< std::pair< bool, std::string > > emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) override
Record a relocation described by the .reloc directive.
Definition: MCObjectStreamer.cpp:747
llvm::MCAssembler::getBackend
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:300
llvm::MCSection::isBundleLocked
bool isBundleLocked() const
Definition: MCSection.h:149
i
i
Definition: README.txt:29
llvm::MCDwarfFrameInfo::End
MCSymbol * End
Definition: MCDwarf.h:641
llvm::MCObjectStreamer::emitDwarfLocDirective
void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName) override
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
Definition: MCObjectStreamer.cpp:448
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:427
llvm::MCObjectStreamer::emitCVLinetableDirective
void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView '.cv_linetable' assembler directive.
Definition: MCObjectStreamer.cpp:550
MCDwarf.h
llvm::MCObjectStreamer::emitFileDirective
void emitFileDirective(StringRef Filename) override
Switch to a new logical file.
Definition: MCObjectStreamer.cpp:849
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCAssembler::Finish
void Finish()
Finish - Do final processing and write the object to the output stream.
Definition: MCAssembler.cpp:931
llvm::MCRelaxableFragment
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCObjectStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: MCObjectStreamer.cpp:264
llvm::MCObjectStreamer::emitCVLocDirective
void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override
This implements the CodeView '.cv_loc' assembler directive.
Definition: MCObjectStreamer.cpp:534
llvm::FK_DTPRel_8
@ FK_DTPRel_8
A eight-byte dtp relative fixup.
Definition: MCFixup.h:37
llvm::MCAsmBackend::emitInstructionEnd
virtual void emitInstructionEnd(MCObjectStreamer &OS, const MCInst &Inst)
Definition: MCAsmBackend.h:60
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:463
llvm::MCObjectStreamer::~MCObjectStreamer
~MCObjectStreamer()
Definition: MCObjectStreamer.cpp:40
llvm::MCObjectStreamer::emitValueToAlignment
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.
Definition: MCObjectStreamer.cpp:597
llvm::MCContext::getCVContext
CodeViewContext & getCVContext()
Definition: MCContext.cpp:908
llvm::MCStreamer::emitAbsoluteSymbolDiffAsULEB128
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCStreamer.cpp:1132
llvm::MCDwarfCallFrameFragment
Definition: MCFragment.h:481
llvm::MCStreamer::getUseAssemblerInfoForParsing
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:285
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCDwarfFrameInfo::Begin
MCSymbol * Begin
Definition: MCDwarf.h:640
llvm::MCObjectStreamer::MCObjectStreamer
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition: MCObjectStreamer.cpp:28
llvm::MCSymbol::getOffset
uint64_t getOffset() const
Definition: MCSymbol.h:320
llvm::CodeViewContext::recordCVLoc
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
llvm::MCObjectStreamer::emitDTPRel64Value
void emitDTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
Definition: MCObjectStreamer.cpp:635
MCCodeEmitter.h
llvm::MCStreamer::emitCFISections
virtual void emitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:434
llvm::MCSection::addPendingLabel
void addPendingLabel(MCSymbol *label, unsigned Subsection=0)
Add a pending label for the requested subsection.
Definition: MCSection.cpp:91
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCObjectStreamer.cpp:149
llvm::AMDGPUISD::IF
@ IF
Definition: AMDGPUISelLowering.h:350
llvm::MipsISD::Lo
@ Lo
Definition: MipsISelLowering.h:79
llvm::MCFixup::create
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:87
ErrorHandling.h
MCAssembler.h
llvm::MCObjectStreamer::emitBundleLock
void emitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
Definition: MCObjectStreamer.cpp:440
llvm::MCStreamer::emitCVLinetableDirective
virtual void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
Definition: MCStreamer.cpp:338
llvm::MCObjectStreamer::emitCFISections
void emitCFISections(bool EH, bool Debug) override
Definition: MCObjectStreamer.cpp:216
llvm::MCObjectStreamer::emitAbsoluteSymbolDiff
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
Definition: MCObjectStreamer.cpp:140
MCObjectFileInfo.h
llvm::MCObjectStreamer::emitLabelAtPos
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset)
Definition: MCObjectStreamer.cpp:288
llvm::MCStreamer::emitValueImpl
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:1191
llvm::MCSymbol::getFragment
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:392
llvm::MCNopsFragment
Definition: MCFragment.h:371
buildSymbolDiff
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
Definition: MCObjectStreamer.cpp:461
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:243
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::MCStreamer::setAllowAutoPadding
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:291
llvm::MCAsmInfo::getCodePointerSize
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:536
llvm::Optional< uint64_t >
llvm::MCObjectStreamer::visitUsedSymbol
void visitUsedSymbol(const MCSymbol &Sym) override
Definition: MCObjectStreamer.cpp:212
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MCObjectStreamer::emitCVFileChecksumOffsetDirective
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
Definition: MCObjectStreamer.cpp:586
STLExtras.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCObjectStreamer::changeSection
void changeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
Definition: MCObjectStreamer.cpp:329
llvm::MCObjectStreamer::reset
void reset() override
state management
Definition: MCObjectStreamer.cpp:157
llvm::CodeViewContext::emitLineTableForFunction
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:326
llvm::MCObjectStreamer::emitDTPRel32Value
void emitDTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
Definition: MCObjectStreamer.cpp:625
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::FK_TPRel_4
@ FK_TPRel_4
A four-byte tp relative fixup.
Definition: MCFixup.h:38
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCExpr::evaluateAsRelocatable
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:747
llvm::MipsISD::Hi
@ Hi
Definition: MipsISelLowering.h:75
llvm::MCSection::iterator
FragmentListType::iterator iterator
Definition: MCSection.h:62
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
MCObjectStreamer.h
emitDwarfSetLineAddr
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
Definition: MCObjectStreamer.cpp:472
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCObjectWriter::addAddrsigSymbol
virtual void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
Definition: MCObjectWriter.h:98
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::MCGenDwarfInfo::Emit
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1108
llvm::MCAsmBackend
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
llvm::MCFixup::getKindForSize
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
Definition: MCFixup.h:109
llvm::FK_GPRel_4
@ FK_GPRel_4
A four-byte gp relative fixup.
Definition: MCFixup.h:34
MCAsmBackend.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCAlignFragment
Definition: MCFragment.h:295
llvm::MCDwarfLineTableParams
Definition: MCDwarf.h:206
llvm::MCObjectStreamer::emitGPRel32Value
void emitGPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
Definition: MCObjectStreamer.cpp:665
llvm::MCObjectStreamer::emitValueImpl
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.
Definition: MCObjectStreamer.cpp:222
MCContext.h
llvm::MCObjectStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: MCObjectStreamer.cpp:362
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:415
absoluteSymbolDiff
static Optional< uint64_t > absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo)
Definition: MCObjectStreamer.cpp:130
MCSymbol.h
llvm::MCStreamer::emitSymbolValue
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:181
llvm::MCValue::isAbsolute
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:50
llvm::MCObjectStreamer::emitBundleAlignMode
void emitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
Definition: MCObjectStreamer.cpp:436
false
Definition: StackSlotColoring.cpp:142
llvm::MCObjectStreamer
Streaming object file generation interface.
Definition: MCObjectStreamer.h:36
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:455
llvm::MCDwarfLineTable::emit
static void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:236
llvm::MCStreamer::emitAssignment
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:1042
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::MCObjectStreamer::emitDwarfAdvanceLineAddr
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize) override
If targets does not support representing debug line section by .loc/.file directives in assembly outp...
Definition: MCObjectStreamer.cpp:486
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:398
llvm::MCObjectStreamer::emitDwarfLineEndEntry
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override
Emit the debug line end entry.
Definition: MCObjectStreamer.cpp:505
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::MCObjectStreamer::emitTPRel32Value
void emitTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
Definition: MCObjectStreamer.cpp:645
INT64_MAX
#define INT64_MAX
Definition: DataTypes.h:71
llvm::MCDwarfFrameEmitter::Emit
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1816
llvm::MCObjectStreamer::emitNops
void emitNops(int64_t NumBytes, int64_t ControlledNopLength, SMLoc Loc, const MCSubtargetInfo &STI) override
Definition: MCObjectStreamer.cpp:838
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
llvm::FK_DTPRel_4
@ FK_DTPRel_4
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
llvm::MCObjectStreamer::emitAssignment
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
Definition: MCObjectStreamer.cpp:353
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::MCObjectStreamer::getCurrentFragment
MCFragment * getCurrentFragment() const
Definition: MCObjectStreamer.cpp:179
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:376
llvm::MCObjectStreamer::emitValueToOffset
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.
Definition: MCObjectStreamer.cpp:618
llvm::CodeViewContext::emitInlineLineTableForFunction
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:421
llvm::isIntN
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:460
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
SourceMgr.h
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::SmallString< 128 >
canReuseDataFragment
static bool canReuseDataFragment(const MCDataFragment &F, const MCAssembler &Assembler, const MCSubtargetInfo *STI)
Definition: MCObjectStreamer.cpp:188
llvm::CodeViewContext::emitDefRange
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol * >> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:434
llvm::MCDwarfLineAddrFragment
Definition: MCFragment.h:457
llvm::MCContext::RemapDebugPaths
void RemapDebugPaths()
Definition: MCContext.cpp:808
llvm::MCObjectStreamer::addPendingLabel
void addPendingLabel(MCSymbol *label)
Assign a label to the current Section and Subsection even though a fragment is not yet present.
Definition: MCObjectStreamer.cpp:51
llvm::MCStreamer::endSection
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:1226
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCAssembler::getEmitter
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:302
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
llvm::CodeViewContext::emitStringTable
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Definition: MCCodeView.cpp:170
uint64_t
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:423
llvm::FK_TPRel_8
@ FK_TPRel_8
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
llvm::MCDwarfLineAddr::Emit
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:639
llvm::MCObjectStreamer::emitCVFileChecksumsDirective
void emitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
Definition: MCObjectStreamer.cpp:582
llvm::SourceMgr::PrintMessage
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:341
llvm::SourceMgr::DK_Warning
@ DK_Warning
Definition: SourceMgr.h:35
llvm::CodeViewContext::emitFileChecksumOffset
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:247
llvm::MCObjectStreamer::emitBundleUnlock
void emitBundleUnlock() override
Ends a bundle-locked group.
Definition: MCObjectStreamer.cpp:444
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::MCStreamer::emitInstruction
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:1087
llvm::MCAsmBackend::allowEnhancedRelaxation
virtual bool allowEnhancedRelaxation() const
Return true if this target allows an unrelaxable instruction to be emitted into RelaxableFragment and...
Definition: MCAsmBackend.h:53
llvm::MCObjectStreamer::emitSLEB128Value
void emitSLEB128Value(const MCExpr *Value) override
Definition: MCObjectStreamer.cpp:315
Debug
bool Debug
Definition: PassBuilderBindings.cpp:51
llvm::MCSection::flushPendingLabels
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0, unsigned Subsection=0)
Associate all pending labels in a subsection with a fragment.
Definition: MCSection.cpp:95
llvm::MCBinaryExpr::create
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:183
llvm::MCSymbol::isVariable
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:293
llvm::MCObjectStreamer::insert
void insert(MCFragment *F)
Definition: MCObjectStreamer.h:78
llvm::MCAsmBackend::getFixupKind
virtual Optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
Definition: MCAsmBackend.cpp:70
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1607
llvm::MCStreamer::emitIntValue
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:133
BundlingNotImplementedMsg
static const char *const BundlingNotImplementedMsg
Definition: MCObjectStreamer.cpp:432
llvm::MCFillFragment
Definition: MCFragment.h:344
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:963
llvm::MCAssembler::getRelaxAll
bool getRelaxAll() const
Definition: MCAssembler.h:328
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::MCOrgFragment
Definition: MCFragment.h:401
llvm::MCFragment::getKind
FragmentType getKind() const
Definition: MCFragment.h:94
llvm::MCSection::getVirtualSectionKind
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:89
llvm::MCStreamer::getNumFrameInfos
unsigned getNumFrameInfos()
Definition: MCStreamer.cpp:115
MCSection.h
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:112
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MCObjectStreamer::getOrCreateDataFragment
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.
Definition: MCObjectStreamer.cpp:203
MCAsmInfo.h
llvm::MCSection::setHasInstructions
void setHasInstructions(bool Value)
Definition: MCSection.h:159
llvm::MCSection::getAlignment
unsigned getAlignment() const
Definition: MCSection.h:138
llvm::MCObjectStreamer::changeSectionImpl
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
Definition: MCObjectStreamer.cpp:334
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCDwarfLineEntry::make
static void make(MCStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:108
llvm::MCSection::isVirtualSection
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCFragment::FT_Data
@ FT_Data
Definition: MCFragment.h:37
uint32_t
llvm::MCAsmBackend::relaxInstruction
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
Definition: MCAsmBackend.h:166
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCObjectStreamer::emitWeakReference
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
Definition: MCObjectStreamer.cpp:324
llvm::MCObjectStreamer::emitInstToFragment
virtual void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
Definition: MCObjectStreamer.cpp:414
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:303
llvm::MCContext::clearDwarfLocSeen
void clearDwarfLocSeen()
Definition: MCContext.h:748
llvm::MCObjectStreamer::emitAddrsigSym
void emitAddrsigSym(const MCSymbol *Sym) override
Definition: MCObjectStreamer.cpp:865
llvm::MCObjectStreamer::emitFill
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
Definition: MCObjectStreamer.cpp:799
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:122
llvm::MCSection::setAlignment
void setAlignment(Align Value)
Definition: MCSection.h:139
MCObjectWriter.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::MCObjectWriter::emitAddrsigSection
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
Definition: MCObjectWriter.h:94
llvm::MCInst::getLoc
SMLoc getLoc() const
Definition: MCInst.h:204
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
MCCodeView.h
std
Definition: BitVector.h:838
llvm::MCAssembler::addFileName
void addFileName(StringRef FileName)
Definition: MCAssembler.h:454
llvm::MCSection::hasInstructions
bool hasInstructions() const
Definition: MCSection.h:158
llvm::MCStreamer::emitSLEB128IntValue
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:170
llvm::MCBinaryExpr::Sub
@ Sub
Subtraction.
Definition: MCExpr.h:505
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::MCStreamer::emitCVDefRangeDirective
virtual void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * >> Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
Definition: MCStreamer.cpp:360
llvm::MCStreamer::emitAbsoluteSymbolDiff
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:1113
llvm::MCObjectStreamer::emitULEB128Value
void emitULEB128Value(const MCExpr *Value) override
Definition: MCObjectStreamer.cpp:306
llvm::MCObjectStreamer::emitCVDefRangeDirective
void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * >> Ranges, StringRef FixedSizePortion) override
This implements the CodeView '.cv_def_range' assembler directive.
Definition: MCObjectStreamer.cpp:568
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
MCValue.h
llvm::MCObjectStreamer::emitAddrsig
void emitAddrsig() override
Definition: MCObjectStreamer.cpp:861
llvm::LCOMM::ByteAlignment
@ ByteAlignment
Definition: MCAsmInfo.h:50
llvm::MCStreamer::checkCVLocSection
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
Definition: MCStreamer.cpp:316
llvm::MCAssembler::registerSection
bool registerSection(MCSection &Section)
Definition: MCAssembler.cpp:123
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCAsmBackend::emitInstructionBegin
virtual void emitInstructionBegin(MCObjectStreamer &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
Give the target a chance to manipulate state related to instruction alignment (e.g.
Definition: MCAsmBackend.h:58
llvm::MCObjectStreamer::emitCVStringTableDirective
void emitCVStringTableDirective() override
This implements the CodeView '.cv_stringtable' assembler directive.
Definition: MCObjectStreamer.cpp:579
llvm::MCLEBFragment
Definition: MCFragment.h:428
llvm::MCFixupKind
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
llvm::MCObjectStreamer::emitBytes
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
Definition: MCObjectStreamer.cpp:590
llvm::MCObjectStreamer::flushPendingLabels
void flushPendingLabels()
Create a data fragment for any pending labels across all Sections and Subsections.
Definition: MCObjectStreamer.cpp:92
llvm::MCStreamer::emitULEB128IntValue
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:161
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
llvm::MCContext::getSourceManager
const SourceMgr * getSourceManager() const
Definition: MCContext.h:410
llvm::MCDwarfFrameEmitter::EmitAdvanceLoc
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1885
llvm::MCObjectStreamer::emitGPRel64Value
void emitGPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
Definition: MCObjectStreamer.cpp:675
llvm::MCStreamer::emitDwarfLocDirective
virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
Definition: MCStreamer.cpp:254
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::MCObjectStreamer::emitTPRel64Value
void emitTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
Definition: MCObjectStreamer.cpp:655
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::mc::getRelaxAll
bool getRelaxAll()
llvm::MCObjectStreamer::mayHaveInstructions
bool mayHaveInstructions(MCSection &Sec) const override
Definition: MCObjectStreamer.cpp:358
llvm::MCAssembler::getDWARFLinetableParams
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:306
llvm::MCObjectStreamer::finishImpl
void finishImpl() override
Streamer specific finalization.
Definition: MCObjectStreamer.cpp:870
llvm::MCObjectStreamer::emitFrames
void emitFrames(MCAsmBackend *MAB)
Definition: MCObjectStreamer.cpp:168
llvm::MCObjectStreamer::emitCodeAlignment
void emitCodeAlignment(unsigned ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
Definition: MCObjectStreamer.cpp:611
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1212
llvm::MCObjectStreamer::emitCVInlineLinetableDirective
void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView '.cv_inline_linetable' assembler directive.
Definition: MCObjectStreamer.cpp:558
llvm::MCDwarfFrameInfo
Definition: MCDwarf.h:637
llvm::MCAssembler::isBundlingEnabled
bool isBundlingEnabled() const
Definition: MCAssembler.h:331
MCExpr.h
llvm::MCObjectFileInfo::getDwarfLineSection
MCSection * getDwarfLineSection() const
Definition: MCObjectFileInfo.h:269
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
getOffsetAndDataFragment
static Optional< std::pair< bool, std::string > > getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset, MCDataFragment *&DF)
Definition: MCObjectStreamer.cpp:685
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCAsmBackend::mayNeedRelaxation
virtual bool mayNeedRelaxation(const MCInst &Inst, const MCSubtargetInfo &STI) const
Check whether the given instruction may need relaxation.
Definition: MCAsmBackend.h:143
llvm::CodeViewContext::emitFileChecksums
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:192
llvm::MCStreamer::reset
virtual void reset()
State management.
Definition: MCStreamer.cpp:101
llvm::MCObjectStreamer::emitDwarfAdvanceFrameAddr
void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
Definition: MCObjectStreamer.cpp:523
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
llvm::MCCodeEmitter::encodeInstruction
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.
llvm::MCObjectStreamer::getAssemblerPtr
MCAssembler * getAssemblerPtr() override
Definition: MCObjectStreamer.cpp:45
llvm::MCPseudoProbeTable::emit
static void emit(MCObjectStreamer *MCOS)
Definition: MCPseudoProbe.cpp:194
llvm::MCAssembler::getWriter
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:304