LLVM  16.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/MC/MCAsmBackend.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCCodeEmitter.h"
14 #include "llvm/MC/MCCodeView.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCDwarf.h"
17 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCObjectWriter.h"
20 #include "llvm/MC/MCSection.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/MC/MCValue.h"
24 #include "llvm/Support/SourceMgr.h"
25 using namespace llvm;
26 
28  std::unique_ptr<MCAsmBackend> TAB,
29  std::unique_ptr<MCObjectWriter> OW,
30  std::unique_ptr<MCCodeEmitter> Emitter)
32  Assembler(std::make_unique<MCAssembler>(
33  Context, std::move(TAB), std::move(Emitter), std::move(OW))),
34  EmitEHFrame(true), EmitDebugFrame(false) {
35  if (Assembler->getBackendPtr())
36  setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
37 }
38 
40 
41 // AssemblerPtr is used for evaluation of expressions and causes
42 // difference between asm and object outputs. Return nullptr to in
43 // inline asm mode to limit divergence to assembly inputs.
46  return Assembler.get();
47  return nullptr;
48 }
49 
51  MCSection *CurSection = getCurrentSectionOnly();
52  if (CurSection) {
53  // Register labels that have not yet been assigned to a Section.
54  if (!PendingLabels.empty()) {
55  for (MCSymbol* Sym : PendingLabels)
56  CurSection->addPendingLabel(Sym);
57  PendingLabels.clear();
58  }
59 
60  // Add this label to the current Section / Subsection.
61  CurSection->addPendingLabel(S, CurSubsectionIdx);
62 
63  // Add this Section to the list of PendingLabelSections.
64  PendingLabelSections.insert(CurSection);
65  } else
66  // There is no Section / Subsection for this label yet.
67  PendingLabels.push_back(S);
68 }
69 
71  MCSection *CurSection = getCurrentSectionOnly();
72  if (!CurSection) {
73  assert(PendingLabels.empty());
74  return;
75  }
76  // Register labels that have not yet been assigned to a Section.
77  if (!PendingLabels.empty()) {
78  for (MCSymbol* Sym : PendingLabels)
79  CurSection->addPendingLabel(Sym, CurSubsectionIdx);
80  PendingLabels.clear();
81  }
82 
83  // Associate a fragment with this label, either the supplied fragment
84  // or an empty data fragment.
85  if (F)
86  CurSection->flushPendingLabels(F, FOffset, CurSubsectionIdx);
87  else
88  CurSection->flushPendingLabels(nullptr, 0, CurSubsectionIdx);
89 }
90 
92  // Register labels that have not yet been assigned to a Section.
93  if (!PendingLabels.empty()) {
94  MCSection *CurSection = getCurrentSectionOnly();
95  assert(CurSection);
96  for (MCSymbol* Sym : PendingLabels)
97  CurSection->addPendingLabel(Sym, CurSubsectionIdx);
98  PendingLabels.clear();
99  }
100 
101  // Assign an empty data fragment to all remaining pending labels.
102  for (MCSection* Section : PendingLabelSections)
103  Section->flushPendingLabels();
104 }
105 
106 // When fixup's offset is a forward declared label, e.g.:
107 //
108 // .reloc 1f, R_MIPS_JALR, foo
109 // 1: nop
110 //
111 // postpone adding it to Fixups vector until the label is defined and its offset
112 // is known.
113 void MCObjectStreamer::resolvePendingFixups() {
114  for (PendingMCFixup &PendingFixup : PendingFixups) {
115  if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
116  getContext().reportError(PendingFixup.Fixup.getLoc(),
117  "unresolved relocation offset");
118  continue;
119  }
120  flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
121  PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset() +
122  PendingFixup.Fixup.getOffset());
123 
124  // If the location symbol to relocate is in MCEncodedFragmentWithFixups,
125  // put the Fixup into location symbol's fragment. Otherwise
126  // put into PendingFixup.DF
127  MCFragment *SymFragment = PendingFixup.Sym->getFragment();
128  switch (SymFragment->getKind()) {
132  cast<MCEncodedFragmentWithFixups<8, 1>>(SymFragment)
133  ->getFixups()
134  .push_back(PendingFixup.Fixup);
135  break;
136  case MCFragment::FT_Data:
138  cast<MCEncodedFragmentWithFixups<32, 4>>(SymFragment)
139  ->getFixups()
140  .push_back(PendingFixup.Fixup);
141  break;
142  default:
143  PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
144  break;
145  }
146  }
147  PendingFixups.clear();
148 }
149 
150 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
151 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
153  const MCSymbol *Lo) {
154  assert(Hi && Lo);
155  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
156  Hi->isVariable() || Lo->isVariable())
157  return None;
158 
159  return Hi->getOffset() - Lo->getOffset();
160 }
161 
163  const MCSymbol *Lo,
164  unsigned Size) {
165  if (!getAssembler().getContext().getTargetTriple().isRISCV())
166  if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
167  return emitIntValue(*Diff, Size);
169 }
170 
172  const MCSymbol *Lo) {
173  if (!getAssembler().getContext().getTargetTriple().isRISCV())
174  if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
175  return emitULEB128IntValue(*Diff);
177 }
178 
180  if (Assembler)
181  Assembler->reset();
182  CurInsertionPoint = MCSection::iterator();
183  EmitEHFrame = true;
184  EmitDebugFrame = false;
185  PendingLabels.clear();
186  PendingLabelSections.clear();
188 }
189 
191  if (!getNumFrameInfos())
192  return;
193 
194  if (EmitEHFrame)
195  MCDwarfFrameEmitter::Emit(*this, MAB, true);
196 
197  if (EmitDebugFrame)
198  MCDwarfFrameEmitter::Emit(*this, MAB, false);
199 }
200 
202  assert(getCurrentSectionOnly() && "No current section!");
203 
204  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
205  return &*std::prev(CurInsertionPoint);
206 
207  return nullptr;
208 }
209 
211  const MCAssembler &Assembler,
212  const MCSubtargetInfo *STI) {
213  if (!F.hasInstructions())
214  return true;
215  // When bundling is enabled, we don't want to add data to a fragment that
216  // already has instructions (see MCELFStreamer::emitInstToData for details)
217  if (Assembler.isBundlingEnabled())
218  return Assembler.getRelaxAll();
219  // If the subtarget is changed mid fragment we start a new fragment to record
220  // the new STI.
221  return !STI || F.getSubtargetInfo() == STI;
222 }
223 
226  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
227  if (!F || !canReuseDataFragment(*F, *Assembler, STI)) {
228  F = new MCDataFragment();
229  insert(F);
230  }
231  return F;
232 }
233 
235  Assembler->registerSymbol(Sym);
236 }
237 
238 void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
239  MCStreamer::emitCFISections(EH, Debug);
240  EmitEHFrame = EH;
241  EmitDebugFrame = Debug;
242 }
243 
244 void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
245  SMLoc Loc) {
246  MCStreamer::emitValueImpl(Value, Size, Loc);
248  flushPendingLabels(DF, DF->getContents().size());
249 
251 
252  // Avoid fixups when possible.
253  int64_t AbsValue;
254  if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
255  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
257  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
258  return;
259  }
260  emitIntValue(AbsValue, Size);
261  return;
262  }
263  DF->getFixups().push_back(
264  MCFixup::create(DF->getContents().size(), Value,
265  MCFixup::getKindForSize(Size, false), Loc));
266  DF->getContents().resize(DF->getContents().size() + Size, 0);
267 }
268 
269 MCSymbol *MCObjectStreamer::emitCFILabel() {
270  MCSymbol *Label = getContext().createTempSymbol("cfi");
271  emitLabel(Label);
272  return Label;
273 }
274 
275 void MCObjectStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
276  // We need to create a local symbol to avoid relocations.
277  Frame.Begin = getContext().createTempSymbol();
278  emitLabel(Frame.Begin);
279 }
280 
281 void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
282  Frame.End = getContext().createTempSymbol();
283  emitLabel(Frame.End);
284 }
285 
288 
290 
291  // If there is a current fragment, mark the symbol as pointing into it.
292  // Otherwise queue the label and set its fragment pointer when we emit the
293  // next fragment.
294  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
295  if (F && !(getAssembler().isBundlingEnabled() &&
296  getAssembler().getRelaxAll())) {
297  Symbol->setFragment(F);
298  Symbol->setOffset(F->getContents().size());
299  } else {
300  // Assign all pending labels to offset 0 within the dummy "pending"
301  // fragment. (They will all be reassigned to a real fragment in
302  // flushPendingLabels())
303  Symbol->setOffset(0);
305  }
306 
308 }
309 
311  auto Assignments = pendingAssignments.find(Symbol);
312  if (Assignments != pendingAssignments.end()) {
313  for (const PendingAssignment &A : Assignments->second)
314  emitAssignment(A.Symbol, A.Value);
315 
316  pendingAssignments.erase(Assignments);
317  }
318 }
319 
320 // Emit a label at a previously emitted fragment/offset position. This must be
321 // within the currently-active section.
323  MCFragment *F, uint64_t Offset) {
324  assert(F->getParent() == getCurrentSectionOnly());
325 
328  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
329  Symbol->setOffset(Offset);
330  if (DF) {
331  Symbol->setFragment(F);
332  } else {
333  assert(isa<MCDummyFragment>(F) &&
334  "F must either be an MCDataFragment or the pending MCDummyFragment");
335  assert(Offset == 0);
337  }
338 }
339 
341  int64_t IntValue;
342  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
343  emitULEB128IntValue(IntValue);
344  return;
345  }
346  insert(new MCLEBFragment(*Value, false));
347 }
348 
350  int64_t IntValue;
351  if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
352  emitSLEB128IntValue(IntValue);
353  return;
354  }
355  insert(new MCLEBFragment(*Value, true));
356 }
357 
359  const MCSymbol *Symbol) {
360  report_fatal_error("This file format doesn't support weak aliases.");
361 }
362 
364  const MCExpr *Subsection) {
365  changeSectionImpl(Section, Subsection);
366 }
367 
369  const MCExpr *Subsection) {
370  assert(Section && "Cannot switch to a null section!");
372 
373  bool Created = getAssembler().registerSection(*Section);
374 
375  int64_t IntSubsection = 0;
376  if (Subsection &&
377  !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
378  report_fatal_error("Cannot evaluate subsection number");
379  if (IntSubsection < 0 || IntSubsection > 8192)
380  report_fatal_error("Subsection number out of range");
381  CurSubsectionIdx = unsigned(IntSubsection);
382  CurInsertionPoint =
383  Section->getSubsectionInsertionPoint(CurSubsectionIdx);
384  return Created;
385 }
386 
391 }
392 
394  const MCExpr *Value) {
395  const MCSymbol *Target = &cast<MCSymbolRefExpr>(*Value).getSymbol();
396 
397  // If the symbol already exists, emit the assignment. Otherwise, emit it
398  // later only if the symbol is also emitted.
399  if (Target->isRegistered())
401  else
402  pendingAssignments[Target].push_back({Symbol, Value});
403 }
404 
406  return Sec.hasInstructions();
407 }
408 
410  const MCSubtargetInfo &STI) {
411  const MCSection &Sec = *getCurrentSectionOnly();
412  if (Sec.isVirtualSection()) {
414  " section '" + Sec.getName() +
415  "' cannot have instructions");
416  return;
417  }
418  getAssembler().getBackend().emitInstructionBegin(*this, Inst, STI);
419  emitInstructionImpl(Inst, STI);
420  getAssembler().getBackend().emitInstructionEnd(*this, Inst);
421 }
422 
423 void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
424  const MCSubtargetInfo &STI) {
425  MCStreamer::emitInstruction(Inst, STI);
426 
428  Sec->setHasInstructions(true);
429 
430  // Now that a machine instruction has been assembled into this section, make
431  // a line entry for any .loc directive that has been seen.
433 
434  // If this instruction doesn't need relaxation, just emit it as data.
435  MCAssembler &Assembler = getAssembler();
436  MCAsmBackend &Backend = Assembler.getBackend();
437  if (!(Backend.mayNeedRelaxation(Inst, STI) ||
438  Backend.allowEnhancedRelaxation())) {
439  emitInstToData(Inst, STI);
440  return;
441  }
442 
443  // Otherwise, relax and emit it as data if either:
444  // - The RelaxAll flag was passed
445  // - Bundling is enabled and this instruction is inside a bundle-locked
446  // group. We want to emit all such instructions into the same data
447  // fragment.
448  if (Assembler.getRelaxAll() ||
449  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
450  MCInst Relaxed = Inst;
451  while (Backend.mayNeedRelaxation(Relaxed, STI))
452  Backend.relaxInstruction(Relaxed, STI);
453  emitInstToData(Relaxed, STI);
454  return;
455  }
456 
457  // Otherwise emit to a separate fragment.
458  emitInstToFragment(Inst, STI);
459 }
460 
462  const MCSubtargetInfo &STI) {
463  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
464  llvm_unreachable("All instructions should have already been relaxed");
465 
466  // Always create a new, separate fragment here, because its size can change
467  // during relaxation.
468  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
469  insert(IF);
470 
471  SmallString<128> Code;
472  raw_svector_ostream VecOS(Code);
473  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
474  STI);
475  IF->getContents().append(Code.begin(), Code.end());
476 }
477 
478 #ifndef NDEBUG
479 static const char *const BundlingNotImplementedMsg =
480  "Aligned bundling is not implemented for this object format";
481 #endif
482 
483 void MCObjectStreamer::emitBundleAlignMode(unsigned AlignPow2) {
485 }
486 
487 void MCObjectStreamer::emitBundleLock(bool AlignToEnd) {
489 }
490 
493 }
494 
495 void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
496  unsigned Column, unsigned Flags,
497  unsigned Isa,
498  unsigned Discriminator,
499  StringRef FileName) {
500  // In case we see two .loc directives in a row, make sure the
501  // first one gets a line entry.
503 
504  this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
505  Discriminator, FileName);
506 }
507 
508 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
509  const MCSymbol *B) {
510  MCContext &Context = OS.getContext();
512  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
513  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
514  const MCExpr *AddrDelta =
516  return AddrDelta;
517 }
518 
520  MCDwarfLineTableParams Params,
521  int64_t LineDelta, const MCSymbol *Label,
522  int PointerSize) {
523  // emit the sequence to set the address
524  OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
526  OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
527  OS.emitSymbolValue(Label, PointerSize);
528 
529  // emit the sequence for the LineDelta (from 1) and a zero address delta.
530  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
531 }
532 
534  const MCSymbol *LastLabel,
535  const MCSymbol *Label,
536  unsigned PointerSize) {
537  if (!LastLabel) {
538  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
539  Label, PointerSize);
540  return;
541  }
542  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
543  int64_t Res;
544  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
545  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
546  Res);
547  return;
548  }
549  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
550 }
551 
553  MCSymbol *LastLabel) {
554  // Emit a DW_LNE_end_sequence for the end of the section.
555  // Use the section end label to compute the address delta and use INT64_MAX
556  // as the line delta which is the signal that this is actually a
557  // DW_LNE_end_sequence.
558  MCSymbol *SectionEnd = endSection(Section);
559 
560  // Switch back the dwarf line section, in case endSection had to switch the
561  // section.
562  MCContext &Ctx = getContext();
564 
565  const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
566  emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
567  AsmInfo->getCodePointerSize());
568 }
569 
571  const MCSymbol *Label) {
572  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
573  int64_t Res;
574  if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
576  return;
577  }
578  insert(new MCDwarfCallFrameFragment(*AddrDelta));
579 }
580 
581 void MCObjectStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
582  unsigned Line, unsigned Column,
583  bool PrologueEnd, bool IsStmt,
584  StringRef FileName, SMLoc Loc) {
585  // Validate the directive.
586  if (!checkCVLocSection(FunctionId, FileNo, Loc))
587  return;
588 
589  // Emit a label at the current position and record it in the CodeViewContext.
590  MCSymbol *LineSym = getContext().createTempSymbol();
591  emitLabel(LineSym);
592  getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
593  FileNo, Line, Column, PrologueEnd,
594  IsStmt);
595 }
596 
598  const MCSymbol *Begin,
599  const MCSymbol *End) {
600  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
601  End);
602  this->MCStreamer::emitCVLinetableDirective(FunctionId, Begin, End);
603 }
604 
606  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
607  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
609  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
610  FnEndSym);
612  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
613 }
614 
616  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
617  StringRef FixedSizePortion) {
618  MCFragment *Frag =
619  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
620  // Attach labels that were pending before we created the defrange fragment to
621  // the beginning of the new fragment.
622  flushPendingLabels(Frag, 0);
623  this->MCStreamer::emitCVDefRangeDirective(Ranges, FixedSizePortion);
624 }
625 
628 }
631 }
632 
635 }
636 
640  flushPendingLabels(DF, DF->getContents().size());
641  DF->getContents().append(Data.begin(), Data.end());
642 }
643 
645  int64_t Value,
646  unsigned ValueSize,
647  unsigned MaxBytesToEmit) {
648  if (MaxBytesToEmit == 0)
649  MaxBytesToEmit = ByteAlignment;
651  MaxBytesToEmit));
652 
653  // Update the maximum alignment on the current section if necessary.
654  MCSection *CurSec = getCurrentSectionOnly();
655  if (ByteAlignment > CurSec->getAlignment())
656  CurSec->setAlignment(Align(ByteAlignment));
657 }
658 
660  const MCSubtargetInfo *STI,
661  unsigned MaxBytesToEmit) {
662  emitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
663  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true, STI);
664 }
665 
667  unsigned char Value,
668  SMLoc Loc) {
669  insert(new MCOrgFragment(*Offset, Value, Loc));
670 }
671 
672 // Associate DTPRel32 fixup with data and resize data area
675  flushPendingLabels(DF, DF->getContents().size());
676 
677  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
678  Value, FK_DTPRel_4));
679  DF->getContents().resize(DF->getContents().size() + 4, 0);
680 }
681 
682 // Associate DTPRel64 fixup with data and resize data area
685  flushPendingLabels(DF, DF->getContents().size());
686 
687  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
688  Value, FK_DTPRel_8));
689  DF->getContents().resize(DF->getContents().size() + 8, 0);
690 }
691 
692 // Associate TPRel32 fixup with data and resize data area
695  flushPendingLabels(DF, DF->getContents().size());
696 
697  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
698  Value, FK_TPRel_4));
699  DF->getContents().resize(DF->getContents().size() + 4, 0);
700 }
701 
702 // Associate TPRel64 fixup with data and resize data area
705  flushPendingLabels(DF, DF->getContents().size());
706 
707  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
708  Value, FK_TPRel_8));
709  DF->getContents().resize(DF->getContents().size() + 8, 0);
710 }
711 
712 // Associate GPRel32 fixup with data and resize data area
715  flushPendingLabels(DF, DF->getContents().size());
716 
717  DF->getFixups().push_back(
718  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
719  DF->getContents().resize(DF->getContents().size() + 4, 0);
720 }
721 
722 // Associate GPRel64 fixup with data and resize data area
725  flushPendingLabels(DF, DF->getContents().size());
726 
727  DF->getFixups().push_back(
728  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
729  DF->getContents().resize(DF->getContents().size() + 8, 0);
730 }
731 
734  MCDataFragment *&DF) {
735  if (Symbol.isVariable()) {
736  const MCExpr *SymbolExpr = Symbol.getVariableValue();
737  MCValue OffsetVal;
738  if(!SymbolExpr->evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
739  return std::make_pair(false,
740  std::string("symbol in .reloc offset is not "
741  "relocatable"));
742  if (OffsetVal.isAbsolute()) {
743  RelocOffset = OffsetVal.getConstant();
744  MCFragment *Fragment = Symbol.getFragment();
745  // FIXME Support symbols with no DF. For example:
746  // .reloc .data, ENUM_VALUE, <some expr>
747  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
748  return std::make_pair(false,
749  std::string("symbol in offset has no data "
750  "fragment"));
751  DF = cast<MCDataFragment>(Fragment);
752  return None;
753  }
754 
755  if (OffsetVal.getSymB())
756  return std::make_pair(false,
757  std::string(".reloc symbol offset is not "
758  "representable"));
759 
760  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
761  if (!SRE.getSymbol().isDefined())
762  return std::make_pair(false,
763  std::string("symbol used in the .reloc offset is "
764  "not defined"));
765 
766  if (SRE.getSymbol().isVariable())
767  return std::make_pair(false,
768  std::string("symbol used in the .reloc offset is "
769  "variable"));
770 
771  MCFragment *Fragment = SRE.getSymbol().getFragment();
772  // FIXME Support symbols with no DF. For example:
773  // .reloc .data, ENUM_VALUE, <some expr>
774  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
775  return std::make_pair(false,
776  std::string("symbol in offset has no data "
777  "fragment"));
778  RelocOffset = SRE.getSymbol().getOffset() + OffsetVal.getConstant();
779  DF = cast<MCDataFragment>(Fragment);
780  } else {
781  RelocOffset = Symbol.getOffset();
782  MCFragment *Fragment = Symbol.getFragment();
783  // FIXME Support symbols with no DF. For example:
784  // .reloc .data, ENUM_VALUE, <some expr>
785  if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
786  return std::make_pair(false,
787  std::string("symbol in offset has no data "
788  "fragment"));
789  DF = cast<MCDataFragment>(Fragment);
790  }
791  return None;
792 }
793 
796  const MCExpr *Expr, SMLoc Loc,
797  const MCSubtargetInfo &STI) {
798  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
799  if (!MaybeKind)
800  return std::make_pair(true, std::string("unknown relocation name"));
801 
802  MCFixupKind Kind = *MaybeKind;
803 
804  if (Expr == nullptr)
805  Expr =
806  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
807 
809  flushPendingLabels(DF, DF->getContents().size());
810 
811  MCValue OffsetVal;
812  if (!Offset.evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
813  return std::make_pair(false,
814  std::string(".reloc offset is not relocatable"));
815  if (OffsetVal.isAbsolute()) {
816  if (OffsetVal.getConstant() < 0)
817  return std::make_pair(false, std::string(".reloc offset is negative"));
818  DF->getFixups().push_back(
819  MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
820  return None;
821  }
822  if (OffsetVal.getSymB())
823  return std::make_pair(false,
824  std::string(".reloc offset is not representable"));
825 
826  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
827  const MCSymbol &Symbol = SRE.getSymbol();
828  if (Symbol.isDefined()) {
829  uint32_t SymbolOffset = 0;
831  Error = getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
832 
833  if (Error != None)
834  return Error;
835 
836  DF->getFixups().push_back(
837  MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
838  Expr, Kind, Loc));
839  return None;
840  }
841 
842  PendingFixups.emplace_back(
843  &SRE.getSymbol(), DF,
844  MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
845  return None;
846 }
847 
848 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
849  SMLoc Loc) {
851  flushPendingLabels(DF, DF->getContents().size());
852 
853  assert(getCurrentSectionOnly() && "need a section");
854  insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
855 }
856 
857 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
858  int64_t Expr, SMLoc Loc) {
859  int64_t IntNumValues;
860  // Do additional checking now if we can resolve the value.
861  if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
862  if (IntNumValues < 0) {
865  "'.fill' directive with negative repeat count has no effect");
866  return;
867  }
868  // Emit now if we can for better errors.
869  int64_t NonZeroSize = Size > 4 ? 4 : Size;
870  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
871  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
872  emitIntValue(Expr, NonZeroSize);
873  if (NonZeroSize < Size)
874  emitIntValue(0, Size - NonZeroSize);
875  }
876  return;
877  }
878 
879  // Otherwise emit as fragment.
881  flushPendingLabels(DF, DF->getContents().size());
882 
883  assert(getCurrentSectionOnly() && "need a section");
884  insert(new MCFillFragment(Expr, Size, NumValues, Loc));
885 }
886 
887 void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
888  SMLoc Loc, const MCSubtargetInfo &STI) {
889  // Emit an NOP fragment.
891  flushPendingLabels(DF, DF->getContents().size());
892 
893  assert(getCurrentSectionOnly() && "need a section");
894 
895  insert(new MCNopsFragment(NumBytes, ControlledNopLength, Loc, STI));
896 }
897 
899  getAssembler().addFileName(Filename);
900 }
901 
903  StringRef CompilerVerion,
904  StringRef TimeStamp,
905  StringRef Description) {
906  getAssembler().addFileName(Filename);
907  // TODO: add additional info to integrated assembler.
908 }
909 
912 }
913 
917 }
918 
921 
922  // If we are generating dwarf for assembly source files dump out the sections.
923  if (getContext().getGenDwarfForAssembly())
924  MCGenDwarfInfo::Emit(this);
925 
926  // Dump out the dwarf file & directory tables and line tables.
927  MCDwarfLineTable::emit(this, getAssembler().getDWARFLinetableParams());
928 
929  // Emit pseudo probes for the current module.
931 
932  // Update any remaining pending labels with empty data fragments.
934 
935  resolvePendingFixups();
936  getAssembler().Finish();
937 }
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:350
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:795
llvm::MCAssembler::getBackend
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:329
llvm::MCSection::isBundleLocked
bool isBundleLocked() const
Definition: MCSection.h:151
i
i
Definition: README.txt:29
llvm::MCDwarfFrameInfo::End
MCSymbol * End
Definition: MCDwarf.h:685
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:495
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:451
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:597
MCDwarf.h
llvm::MCObjectStreamer::emitFileDirective
void emitFileDirective(StringRef Filename) override
Switch to a new logical file.
Definition: MCObjectStreamer.cpp:898
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCAssembler::Finish
void Finish()
Finish - Do final processing and write the object to the output stream.
Definition: MCAssembler.cpp:935
llvm::MCRelaxableFragment
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:270
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:286
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:581
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:66
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:467
llvm::MCObjectStreamer::~MCObjectStreamer
~MCObjectStreamer()
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:644
llvm::MCContext::getCVContext
CodeViewContext & getCVContext()
Definition: MCContext.cpp:998
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:1141
llvm::MCDwarfCallFrameFragment
Definition: MCFragment.h:480
llvm::MCStreamer::getUseAssemblerInfoForParsing
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:298
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::MCDwarfFrameInfo::Begin
MCSymbol * Begin
Definition: MCDwarf.h:684
llvm::MCObjectStreamer::MCObjectStreamer
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition: MCObjectStreamer.cpp:27
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:131
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:683
MCCodeEmitter.h
llvm::MCStreamer::emitCFISections
virtual void emitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:445
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:145
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:171
llvm::AMDGPUISD::IF
@ IF
Definition: AMDGPUISelLowering.h:358
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:487
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:393
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:346
llvm::MCObjectStreamer::emitCFISections
void emitCFISections(bool EH, bool Debug) override
Definition: MCObjectStreamer.cpp:238
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:162
MCObjectFileInfo.h
llvm::MCObjectStreamer::emitLabelAtPos
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset)
Definition: MCObjectStreamer.cpp:322
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:1213
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1835
llvm::MCSymbol::getFragment
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:392
llvm::MCNopsFragment
Definition: MCFragment.h:370
buildSymbolDiff
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
Definition: MCObjectStreamer.cpp:508
llvm::MCObjectWriter::addAddrsigSymbol
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
Definition: MCObjectWriter.h:104
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:226
llvm::MCStreamer::setAllowAutoPadding
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:304
llvm::MCAsmInfo::getCodePointerSize
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:548
llvm::Optional< uint64_t >
llvm::MCObjectStreamer::visitUsedSymbol
void visitUsedSymbol(const MCSymbol &Sym) override
Definition: MCObjectStreamer.cpp:234
llvm::MCObjectStreamer::emitCVFileChecksumOffsetDirective
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
Definition: MCObjectStreamer.cpp:633
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:363
llvm::MCObjectStreamer::reset
void reset() override
state management
Definition: MCObjectStreamer.cpp:179
llvm::CodeViewContext::emitLineTableForFunction
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:327
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:673
llvm::MCFragment::FT_CVDefRange
@ FT_CVDefRange
Definition: MCFragment.h:48
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
llvm::MCSection::iterator
FragmentListType::iterator iterator
Definition: MCSection.h:64
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
MCObjectStreamer.h
emitDwarfSetLineAddr
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
Definition: MCObjectStreamer.cpp:519
llvm::MCFragment
Definition: MCFragment.h:30
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::MCGenDwarfInfo::Emit
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1138
llvm::MCAsmBackend
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
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:294
llvm::MCDwarfLineTableParams
Definition: MCDwarf.h:244
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:713
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:244
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:409
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:423
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:1234
absoluteSymbolDiff
static Optional< uint64_t > absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo)
Definition: MCObjectStreamer.cpp:152
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:182
llvm::MCValue::isAbsolute
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:49
llvm::MCObjectStreamer::emitBundleAlignMode
void emitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
Definition: MCObjectStreamer.cpp:483
false
Definition: StackSlotColoring.cpp:141
llvm::MCObjectStreamer
Streaming object file generation interface.
Definition: MCObjectStreamer.h:42
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:422
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:1051
llvm::MCObjectStreamer::emitPendingAssignments
void emitPendingAssignments(MCSymbol *Symbol)
Emits pending conditional assignments that depend on Symbol being emitted.
Definition: MCObjectStreamer.cpp:310
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:145
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:533
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:552
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:43
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:693
INT64_MAX
#define INT64_MAX
Definition: DataTypes.h:71
llvm::MCDwarfFrameEmitter::Emit
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1848
llvm::MCObjectStreamer::emitNops
void emitNops(int64_t NumBytes, int64_t ControlledNopLength, SMLoc Loc, const MCSubtargetInfo &STI) override
Definition: MCObjectStreamer.cpp:887
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
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:387
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::MCObjectStreamer::getCurrentFragment
MCFragment * getCurrentFragment() const
Definition: MCObjectStreamer.cpp:201
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:389
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:666
llvm::CodeViewContext::emitInlineLineTableForFunction
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:422
llvm::isIntN
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:427
llvm::None
const NoneType None
Definition: None.h:24
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:210
llvm::CodeViewContext::emitDefRange
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol * >> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:435
llvm::MCObjectWriter::emitAddrsigSection
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
Definition: MCObjectWriter.h:98
llvm::MCDwarfLineAddrFragment
Definition: MCFragment.h:456
llvm::MCContext::RemapDebugPaths
void RemapDebugPaths()
Definition: MCContext.cpp:893
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:50
llvm::MCStreamer::endSection
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:1248
llvm::MCAssembler
Definition: MCAssembler.h:73
llvm::MCAssembler::getEmitter
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:331
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
llvm::CodeViewContext::emitStringTable
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Definition: MCCodeView.cpp:171
uint64_t
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:447
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:669
llvm::MCObjectStreamer::emitCVFileChecksumsDirective
void emitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
Definition: MCObjectStreamer.cpp:629
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:348
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:248
llvm::MCObjectStreamer::emitBundleUnlock
void emitBundleUnlock() override
Ends a bundle-locked group.
Definition: MCObjectStreamer.cpp:491
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::MCStreamer::emitInstruction
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:1096
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:59
llvm::MCObjectStreamer::emitSLEB128Value
void emitSLEB128Value(const MCExpr *Value) override
Definition: MCObjectStreamer.cpp:349
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:94
llvm::MCAsmBackend::getFixupKind
virtual Optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
Definition: MCAsmBackend.cpp:77
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:1666
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:134
BundlingNotImplementedMsg
static const char *const BundlingNotImplementedMsg
Definition: MCObjectStreamer.cpp:479
llvm::MCFillFragment
Definition: MCFragment.h:343
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1053
llvm::MCAssembler::getRelaxAll
bool getRelaxAll() const
Definition: MCAssembler.h:357
llvm::MCFragment::FT_PseudoProbe
@ FT_PseudoProbe
Definition: MCFragment.h:49
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::MCOrgFragment
Definition: MCFragment.h:400
llvm::MCFragment::getKind
FragmentType getKind() const
Definition: MCFragment.h:93
llvm::MCSection::getVirtualSectionKind
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:89
llvm::MCStreamer::getNumFrameInfos
unsigned getNumFrameInfos()
Definition: MCStreamer.cpp:116
MCSection.h
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:128
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:225
MCAsmInfo.h
llvm::MCSection::setHasInstructions
void setHasInstructions(bool Value)
Definition: MCSection.h:161
llvm::MCSection::getAlignment
unsigned getAlignment() const
Definition: MCSection.h:140
llvm::MCObjectStreamer::changeSectionImpl
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
Definition: MCObjectStreamer.cpp:368
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:143
llvm::MCFragment::FT_Data
@ FT_Data
Definition: MCFragment.h:36
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:172
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:358
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:461
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:324
llvm::MCContext::clearDwarfLocSeen
void clearDwarfLocSeen()
Definition: MCContext.h:781
llvm::MCObjectStreamer::emitAddrsigSym
void emitAddrsigSym(const MCSymbol *Sym) override
Definition: MCObjectStreamer.cpp:914
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:848
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:124
llvm::MCSection::setAlignment
void setAlignment(Align Value)
Definition: MCSection.h:141
MCObjectWriter.h
llvm::MCFragment::FT_Dwarf
@ FT_Dwarf
Definition: MCFragment.h:42
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::MCInst::getLoc
SMLoc getLoc() const
Definition: MCInst.h:204
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
MCCodeView.h
std
Definition: BitVector.h:851
llvm::MCAssembler::addFileName
void addFileName(StringRef FileName)
Definition: MCAssembler.h:483
llvm::MCSection::hasInstructions
bool hasInstructions() const
Definition: MCSection.h:160
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:171
llvm::MCBinaryExpr::Sub
@ Sub
Subtraction.
Definition: MCExpr.h:506
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
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:368
llvm::MCStreamer::emitAbsoluteSymbolDiff
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:1122
llvm::MCObjectStreamer::emitULEB128Value
void emitULEB128Value(const MCExpr *Value) override
Definition: MCObjectStreamer.cpp:340
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:615
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:910
llvm::LCOMM::ByteAlignment
@ ByteAlignment
Definition: MCAsmInfo.h:50
llvm::MCFragment::FT_Relaxable
@ FT_Relaxable
Definition: MCFragment.h:40
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:324
llvm::MCAssembler::registerSection
bool registerSection(MCSection &Section)
Definition: MCAssembler.cpp:127
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:64
llvm::MCObjectStreamer::emitCVStringTableDirective
void emitCVStringTableDirective() override
This implements the CodeView '.cv_stringtable' assembler directive.
Definition: MCObjectStreamer.cpp:626
llvm::MCLEBFragment
Definition: MCFragment.h:427
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:637
llvm::MCObjectStreamer::flushPendingLabels
void flushPendingLabels()
Create a data fragment for any pending labels across all Sections and Subsections.
Definition: MCObjectStreamer.cpp:91
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:162
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:293
llvm::MCContext::getSourceManager
const SourceMgr * getSourceManager() const
Definition: MCContext.h:436
llvm::MCDwarfFrameEmitter::EmitAdvanceLoc
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1916
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:723
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:262
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:703
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
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:405
llvm::MCAssembler::getDWARFLinetableParams
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:335
llvm::MCObjectStreamer::finishImpl
void finishImpl() override
Streamer specific finalization.
Definition: MCObjectStreamer.cpp:919
llvm::MCObjectStreamer::emitFrames
void emitFrames(MCAsmBackend *MAB)
Definition: MCObjectStreamer.cpp:190
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:659
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
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:605
llvm::MCDwarfFrameInfo
Definition: MCDwarf.h:681
llvm::MCAssembler::isBundlingEnabled
bool isBundlingEnabled() const
Definition: MCAssembler.h:360
MCExpr.h
llvm::MCObjectFileInfo::getDwarfLineSection
MCSection * getDwarfLineSection() const
Definition: MCObjectFileInfo.h:279
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
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:733
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:149
llvm::CodeViewContext::emitFileChecksums
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:193
llvm::MCStreamer::reset
virtual void reset()
State management.
Definition: MCStreamer.cpp:102
llvm::MCObjectStreamer::emitDwarfAdvanceFrameAddr
void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
Definition: MCObjectStreamer.cpp:570
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
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:44
llvm::MCPseudoProbeTable::emit
static void emit(MCObjectStreamer *MCOS)
Definition: MCPseudoProbe.cpp:197
llvm::MCAssembler::getWriter
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:333