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 
286 }
287 
289  auto Assignments = pendingAssignments.find(Symbol);
290  if (Assignments != pendingAssignments.end()) {
291  for (const PendingAssignment &A : Assignments->second)
292  emitAssignment(A.Symbol, A.Value);
293 
294  pendingAssignments.erase(Assignments);
295  }
296 }
297 
298 // Emit a label at a previously emitted fragment/offset position. This must be
299 // within the currently-active section.
302  assert(F->getParent() == getCurrentSectionOnly());
303 
306  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
307  Symbol->setOffset(Offset);
308  if (DF) {
309  Symbol->setFragment(F);
310  } else {
311  assert(isa<MCDummyFragment>(F) &&
312  "F must either be an MCDataFragment or the pending MCDummyFragment");
313  assert(Offset == 0);
315  }
316 }
317 
319  int64_t IntValue;
320  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
321  emitULEB128IntValue(IntValue);
322  return;
323  }
324  insert(new MCLEBFragment(*Value, false));
325 }
326 
328  int64_t IntValue;
329  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
330  emitSLEB128IntValue(IntValue);
331  return;
332  }
333  insert(new MCLEBFragment(*Value, true));
334 }
335 
337  const MCSymbol *Symbol) {
338  report_fatal_error("This file format doesn't support weak aliases.");
339 }
340 
342  const MCExpr *Subsection) {
343  changeSectionImpl(Section, Subsection);
344 }
345 
347  const MCExpr *Subsection) {
348  assert(Section && "Cannot switch to a null section!");
350 
351  bool Created = getAssembler().registerSection(*Section);
352 
353  int64_t IntSubsection = 0;
354  if (Subsection &&
355  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
356  report_fatal_error("Cannot evaluate subsection number");
357  if (IntSubsection < 0 || IntSubsection > 8192)
358  report_fatal_error("Subsection number out of range");
359  CurSubsectionIdx = unsigned(IntSubsection);
360  CurInsertionPoint =
361  Section->getSubsectionInsertionPoint(CurSubsectionIdx);
362  return Created;
363 }
364 
369 }
370 
372  const MCExpr *Value) {
373  const MCSymbol *Target = &cast<MCSymbolRefExpr>(*Value).getSymbol();
374 
375  // If the symbol already exists, emit the assignment. Otherwise, emit it
376  // later only if the symbol is also emitted.
377  if (Target->isRegistered())
379  else
380  pendingAssignments[Target].push_back({Symbol, Value});
381 }
382 
384  return Sec.hasInstructions();
385 }
386 
388  const MCSubtargetInfo &STI) {
389  const MCSection &Sec = *getCurrentSectionOnly();
390  if (Sec.isVirtualSection()) {
392  " section '" + Sec.getName() +
393  "' cannot have instructions");
394  return;
395  }
396  getAssembler().getBackend().emitInstructionBegin(*this, Inst, STI);
397  emitInstructionImpl(Inst, STI);
398  getAssembler().getBackend().emitInstructionEnd(*this, Inst);
399 }
400 
401 void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
402  const MCSubtargetInfo &STI) {
403  MCStreamer::emitInstruction(Inst, STI);
404 
406  Sec->setHasInstructions(true);
407 
408  // Now that a machine instruction has been assembled into this section, make
409  // a line entry for any .loc directive that has been seen.
411 
412  // If this instruction doesn't need relaxation, just emit it as data.
413  MCAssembler &Assembler = getAssembler();
414  MCAsmBackend &Backend = Assembler.getBackend();
415  if (!(Backend.mayNeedRelaxation(Inst, STI) ||
416  Backend.allowEnhancedRelaxation())) {
417  emitInstToData(Inst, STI);
418  return;
419  }
420 
421  // Otherwise, relax and emit it as data if either:
422  // - The RelaxAll flag was passed
423  // - Bundling is enabled and this instruction is inside a bundle-locked
424  // group. We want to emit all such instructions into the same data
425  // fragment.
426  if (Assembler.getRelaxAll() ||
427  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
428  MCInst Relaxed = Inst;
429  while (Backend.mayNeedRelaxation(Relaxed, STI))
430  Backend.relaxInstruction(Relaxed, STI);
431  emitInstToData(Relaxed, STI);
432  return;
433  }
434 
435  // Otherwise emit to a separate fragment.
436  emitInstToFragment(Inst, STI);
437 }
438 
440  const MCSubtargetInfo &STI) {
441  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
442  llvm_unreachable("All instructions should have already been relaxed");
443 
444  // Always create a new, separate fragment here, because its size can change
445  // during relaxation.
446  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
447  insert(IF);
448 
449  SmallString<128> Code;
450  raw_svector_ostream VecOS(Code);
451  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
452  STI);
453  IF->getContents().append(Code.begin(), Code.end());
454 }
455 
456 #ifndef NDEBUG
457 static const char *const BundlingNotImplementedMsg =
458  "Aligned bundling is not implemented for this object format";
459 #endif
460 
461 void MCObjectStreamer::emitBundleAlignMode(unsigned AlignPow2) {
463 }
464 
465 void MCObjectStreamer::emitBundleLock(bool AlignToEnd) {
467 }
468 
471 }
472 
473 void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
474  unsigned Column, unsigned Flags,
475  unsigned Isa,
476  unsigned Discriminator,
477  StringRef FileName) {
478  // In case we see two .loc directives in a row, make sure the
479  // first one gets a line entry.
481 
482  this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
483  Discriminator, FileName);
484 }
485 
486 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
487  const MCSymbol *B) {
488  MCContext &Context = OS.getContext();
490  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
491  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
492  const MCExpr *AddrDelta =
494  return AddrDelta;
495 }
496 
498  MCDwarfLineTableParams Params,
499  int64_t LineDelta, const MCSymbol *Label,
500  int PointerSize) {
501  // emit the sequence to set the address
502  OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
504  OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
505  OS.emitSymbolValue(Label, PointerSize);
506 
507  // emit the sequence for the LineDelta (from 1) and a zero address delta.
508  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
509 }
510 
512  const MCSymbol *LastLabel,
513  const MCSymbol *Label,
514  unsigned PointerSize) {
515  if (!LastLabel) {
516  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
517  Label, PointerSize);
518  return;
519  }
520  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
521  int64_t Res;
522  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
523  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
524  Res);
525  return;
526  }
527  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
528 }
529 
531  MCSymbol *LastLabel) {
532  // Emit a DW_LNE_end_sequence for the end of the section.
533  // Use the section end label to compute the address delta and use INT64_MAX
534  // as the line delta which is the signal that this is actually a
535  // DW_LNE_end_sequence.
536  MCSymbol *SectionEnd = endSection(Section);
537 
538  // Switch back the dwarf line section, in case endSection had to switch the
539  // section.
540  MCContext &Ctx = getContext();
542 
543  const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
544  emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
545  AsmInfo->getCodePointerSize());
546 }
547 
549  const MCSymbol *Label) {
550  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
551  int64_t Res;
552  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
554  return;
555  }
556  insert(new MCDwarfCallFrameFragment(*AddrDelta));
557 }
558 
559 void MCObjectStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
560  unsigned Line, unsigned Column,
561  bool PrologueEnd, bool IsStmt,
562  StringRef FileName, SMLoc Loc) {
563  // Validate the directive.
564  if (!checkCVLocSection(FunctionId, FileNo, Loc))
565  return;
566 
567  // Emit a label at the current position and record it in the CodeViewContext.
568  MCSymbol *LineSym = getContext().createTempSymbol();
569  emitLabel(LineSym);
570  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
571  FileNo, Line, Column, PrologueEnd,
572  IsStmt);
573 }
574 
576  const MCSymbol *Begin,
577  const MCSymbol *End) {
578  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
579  End);
580  this->MCStreamer::emitCVLinetableDirective(FunctionId, Begin, End);
581 }
582 
584  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
585  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
587  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
588  FnEndSym);
590  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
591 }
592 
594  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
595  StringRef FixedSizePortion) {
596  MCFragment *Frag =
597  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
598  // Attach labels that were pending before we created the defrange fragment to
599  // the beginning of the new fragment.
600  flushPendingLabels(Frag, 0);
601  this->MCStreamer::emitCVDefRangeDirective(Ranges, FixedSizePortion);
602 }
603 
606 }
609 }
610 
613 }
614 
618  flushPendingLabels(DF, DF->getContents().size());
619  DF->getContents().append(Data.begin(), Data.end());
620 }
621 
623  int64_t Value,
624  unsigned ValueSize,
625  unsigned MaxBytesToEmit) {
626  if (MaxBytesToEmit == 0)
627  MaxBytesToEmit = ByteAlignment;
628  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
629 
630  // Update the maximum alignment on the current section if necessary.
631  MCSection *CurSec = getCurrentSectionOnly();
632  if (ByteAlignment > CurSec->getAlignment())
633  CurSec->setAlignment(Align(ByteAlignment));
634 }
635 
637  const MCSubtargetInfo *STI,
638  unsigned MaxBytesToEmit) {
639  emitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
640  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true, STI);
641 }
642 
644  unsigned char Value,
645  SMLoc Loc) {
646  insert(new MCOrgFragment(*Offset, Value, Loc));
647 }
648 
649 // Associate DTPRel32 fixup with data and resize data area
652  flushPendingLabels(DF, DF->getContents().size());
653 
654  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
655  Value, FK_DTPRel_4));
656  DF->getContents().resize(DF->getContents().size() + 4, 0);
657 }
658 
659 // Associate DTPRel64 fixup with data and resize data area
662  flushPendingLabels(DF, DF->getContents().size());
663 
664  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
665  Value, FK_DTPRel_8));
666  DF->getContents().resize(DF->getContents().size() + 8, 0);
667 }
668 
669 // Associate TPRel32 fixup with data and resize data area
672  flushPendingLabels(DF, DF->getContents().size());
673 
674  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
675  Value, FK_TPRel_4));
676  DF->getContents().resize(DF->getContents().size() + 4, 0);
677 }
678 
679 // Associate TPRel64 fixup with data and resize data area
682  flushPendingLabels(DF, DF->getContents().size());
683 
684  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
685  Value, FK_TPRel_8));
686  DF->getContents().resize(DF->getContents().size() + 8, 0);
687 }
688 
689 // Associate GPRel32 fixup with data and resize data area
692  flushPendingLabels(DF, DF->getContents().size());
693 
694  DF->getFixups().push_back(
695  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
696  DF->getContents().resize(DF->getContents().size() + 4, 0);
697 }
698 
699 // Associate GPRel64 fixup with data and resize data area
702  flushPendingLabels(DF, DF->getContents().size());
703 
704  DF->getFixups().push_back(
705  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
706  DF->getContents().resize(DF->getContents().size() + 8, 0);
707 }
708 
711  MCDataFragment *&DF) {
712  if (Symbol.isVariable()) {
713  const MCExpr *SymbolExpr = Symbol.getVariableValue();
714  MCValue OffsetVal;
715  if(!SymbolExpr->evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
716  return std::make_pair(false,
717  std::string("symbol in .reloc offset is not "
718  "relocatable"));
719  if (OffsetVal.isAbsolute()) {
720  RelocOffset = OffsetVal.getConstant();
721  MCFragment *Fragment = Symbol.getFragment();
722  // FIXME Support symbols with no DF. For example:
723  // .reloc .data, ENUM_VALUE, <some expr>
724  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
725  return std::make_pair(false,
726  std::string("symbol in offset has no data "
727  "fragment"));
728  DF = cast<MCDataFragment>(Fragment);
729  return None;
730  }
731 
732  if (OffsetVal.getSymB())
733  return std::make_pair(false,
734  std::string(".reloc symbol offset is not "
735  "representable"));
736 
737  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
738  if (!SRE.getSymbol().isDefined())
739  return std::make_pair(false,
740  std::string("symbol used in the .reloc offset is "
741  "not defined"));
742 
743  if (SRE.getSymbol().isVariable())
744  return std::make_pair(false,
745  std::string("symbol used in the .reloc offset is "
746  "variable"));
747 
748  MCFragment *Fragment = SRE.getSymbol().getFragment();
749  // FIXME Support symbols with no DF. For example:
750  // .reloc .data, ENUM_VALUE, <some expr>
751  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
752  return std::make_pair(false,
753  std::string("symbol in offset has no data "
754  "fragment"));
755  RelocOffset = SRE.getSymbol().getOffset() + OffsetVal.getConstant();
756  DF = cast<MCDataFragment>(Fragment);
757  } else {
758  RelocOffset = Symbol.getOffset();
759  MCFragment *Fragment = Symbol.getFragment();
760  // FIXME Support symbols with no DF. For example:
761  // .reloc .data, ENUM_VALUE, <some expr>
762  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
763  return std::make_pair(false,
764  std::string("symbol in offset has no data "
765  "fragment"));
766  DF = cast<MCDataFragment>(Fragment);
767  }
768  return None;
769 }
770 
773  const MCExpr *Expr, SMLoc Loc,
774  const MCSubtargetInfo &STI) {
775  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
776  if (!MaybeKind.hasValue())
777  return std::make_pair(true, std::string("unknown relocation name"));
778 
779  MCFixupKind Kind = *MaybeKind;
780 
781  if (Expr == nullptr)
782  Expr =
783  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
784 
786  flushPendingLabels(DF, DF->getContents().size());
787 
788  MCValue OffsetVal;
789  if (!Offset.evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
790  return std::make_pair(false,
791  std::string(".reloc offset is not relocatable"));
792  if (OffsetVal.isAbsolute()) {
793  if (OffsetVal.getConstant() < 0)
794  return std::make_pair(false, std::string(".reloc offset is negative"));
795  DF->getFixups().push_back(
796  MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
797  return None;
798  }
799  if (OffsetVal.getSymB())
800  return std::make_pair(false,
801  std::string(".reloc offset is not representable"));
802 
803  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
804  const MCSymbol &Symbol = SRE.getSymbol();
805  if (Symbol.isDefined()) {
806  uint32_t SymbolOffset = 0;
808  Error = getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
809 
810  if (Error != None)
811  return Error;
812 
813  DF->getFixups().push_back(
814  MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
815  Expr, Kind, Loc));
816  return None;
817  }
818 
819  PendingFixups.emplace_back(&SRE.getSymbol(), DF,
820  MCFixup::create(-1, Expr, Kind, Loc));
821  return None;
822 }
823 
824 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
825  SMLoc Loc) {
827  flushPendingLabels(DF, DF->getContents().size());
828 
829  assert(getCurrentSectionOnly() && "need a section");
830  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
831 }
832 
833 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
834  int64_t Expr, SMLoc Loc) {
835  int64_t IntNumValues;
836  // Do additional checking now if we can resolve the value.
837  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
838  if (IntNumValues < 0) {
841  "'.fill' directive with negative repeat count has no effect");
842  return;
843  }
844  // Emit now if we can for better errors.
845  int64_t NonZeroSize = Size > 4 ? 4 : Size;
846  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
847  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
848  emitIntValue(Expr, NonZeroSize);
849  if (NonZeroSize < Size)
850  emitIntValue(0, Size - NonZeroSize);
851  }
852  return;
853  }
854 
855  // Otherwise emit as fragment.
857  flushPendingLabels(DF, DF->getContents().size());
858 
859  assert(getCurrentSectionOnly() && "need a section");
860  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
861 }
862 
863 void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
864  SMLoc Loc, const MCSubtargetInfo &STI) {
865  // Emit an NOP fragment.
867  flushPendingLabels(DF, DF->getContents().size());
868 
869  assert(getCurrentSectionOnly() && "need a section");
870 
871  insert(new MCNopsFragment(NumBytes, ControlledNopLength, Loc, STI));
872 }
873 
875  getAssembler().addFileName(Filename);
876 }
877 
879  StringRef CompilerVerion,
880  StringRef TimeStamp,
881  StringRef Description) {
882  getAssembler().addFileName(Filename);
883  // TODO: add additional info to integrated assembler.
884 }
885 
888 }
889 
893 }
894 
897 
898  // If we are generating dwarf for assembly source files dump out the sections.
899  if (getContext().getGenDwarfForAssembly())
900  MCGenDwarfInfo::Emit(this);
901 
902  // Dump out the dwarf file & directory tables and line tables.
903  MCDwarfLineTable::emit(this, getAssembler().getDWARFLinetableParams());
904 
905  // Emit pseudo probes for the current module.
907 
908  // Update any remaining pending labels with empty data fragments.
910 
911  resolvePendingFixups();
912  getAssembler().Finish();
913 }
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:772
llvm::MCAssembler::getBackend
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:316
llvm::MCSection::isBundleLocked
bool isBundleLocked() const
Definition: MCSection.h:149
i
i
Definition: README.txt:29
llvm::MCDwarfFrameInfo::End
MCSymbol * End
Definition: MCDwarf.h:677
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:473
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:575
MCDwarf.h
llvm::MCObjectStreamer::emitFileDirective
void emitFileDirective(StringRef Filename) override
Switch to a new logical file.
Definition: MCObjectStreamer.cpp:874
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MCAssembler::Finish
void Finish()
Finish - Do final processing and write the object to the output stream.
Definition: MCAssembler.cpp:934
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:559
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:466
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:622
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:1135
llvm::MCDwarfCallFrameFragment
Definition: MCFragment.h:481
llvm::MCStreamer::getUseAssemblerInfoForParsing
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:284
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCDwarfFrameInfo::Begin
MCSymbol * Begin
Definition: MCDwarf.h:676
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:660
MCCodeEmitter.h
llvm::MCStreamer::emitCFISections
virtual void emitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:437
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::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
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:357
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:465
llvm::MCObjectStreamer::emitConditionalAssignment
void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol, but only if Value is also emitted.
Definition: MCObjectStreamer.cpp:371
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:300
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:1194
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1886
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:486
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:227
llvm::MCStreamer::setAllowAutoPadding
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:290
llvm::MCAsmInfo::getCodePointerSize
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:536
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:745
llvm::Optional< uint64_t >
llvm::MCObjectStreamer::visitUsedSymbol
void visitUsedSymbol(const MCSymbol &Sym) override
Definition: MCObjectStreamer.cpp:212
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::MCObjectStreamer::emitCVFileChecksumOffsetDirective
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
Definition: MCObjectStreamer.cpp:611
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:341
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:650
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:55
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:749
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
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:289
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
MCObjectStreamer.h
emitDwarfSetLineAddr
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
Definition: MCObjectStreamer.cpp:497
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:198
llvm::MCGenDwarfInfo::Emit
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1128
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:237
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:690
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:387
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:461
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:256
llvm::MCStreamer::emitAssignment
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:1045
llvm::MCObjectStreamer::emitPendingAssignments
void emitPendingAssignments(MCSymbol *Symbol)
Emits pending conditional assignments that depend on Symbol being emitted.
Definition: MCObjectStreamer.cpp:288
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:143
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:511
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:399
llvm::MCObjectStreamer::emitDwarfLineEndEntry
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override
Emit the debug line end entry.
Definition: MCObjectStreamer.cpp:530
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:670
INT64_MAX
#define INT64_MAX
Definition: DataTypes.h:71
llvm::MCDwarfFrameEmitter::Emit
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1836
llvm::MCObjectStreamer::emitNops
void emitNops(int64_t NumBytes, int64_t ControlledNopLength, SMLoc Loc, const MCSubtargetInfo &STI) override
Definition: MCObjectStreamer.cpp:863
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:365
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::MCObjectStreamer::getCurrentFragment
MCFragment * getCurrentFragment() const
Definition: MCObjectStreamer.cpp:179
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:375
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:643
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:1229
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCAssembler::getEmitter
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:318
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:659
llvm::MCObjectStreamer::emitCVFileChecksumsDirective
void emitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
Definition: MCObjectStreamer.cpp:607
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:340
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:469
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:1090
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:327
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:88
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:1707
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:457
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:344
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:122
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:346
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MCDwarfLineEntry::make
static void make(MCStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:91
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:134
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:336
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:439
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:890
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:824
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:470
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:506
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:1116
llvm::MCObjectStreamer::emitULEB128Value
void emitULEB128Value(const MCExpr *Value) override
Definition: MCObjectStreamer.cpp:318
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:593
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
MCValue.h
llvm::MCObjectStreamer::emitAddrsig
void emitAddrsig() override
Definition: MCObjectStreamer.cpp:886
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:126
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
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:604
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:615
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:279
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:1905
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:700
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:661
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:680
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:383
llvm::MCAssembler::getDWARFLinetableParams
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:322
llvm::MCObjectStreamer::finishImpl
void finishImpl() override
Streamer specific finalization.
Definition: MCObjectStreamer.cpp:895
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:636
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
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:1215
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:583
llvm::MCDwarfFrameInfo
Definition: MCDwarf.h:673
llvm::MCAssembler::isBundlingEnabled
bool isBundlingEnabled() const
Definition: MCAssembler.h:347
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:74
getOffsetAndDataFragment
static Optional< std::pair< bool, std::string > > getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset, MCDataFragment *&DF)
Definition: MCObjectStreamer.cpp:710
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:548
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:195
llvm::MCAssembler::getWriter
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:320