LLVM  6.0.0svn
MCAssembler.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/Statistic.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/MC/MCAsmBackend.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCAsmLayout.h"
20 #include "llvm/MC/MCCodeEmitter.h"
21 #include "llvm/MC/MCCodeView.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCDwarf.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCFixup.h"
27 #include "llvm/MC/MCFragment.h"
28 #include "llvm/MC/MCInst.h"
29 #include "llvm/MC/MCObjectWriter.h"
30 #include "llvm/MC/MCSection.h"
31 #include "llvm/MC/MCSectionELF.h"
32 #include "llvm/MC/MCSymbol.h"
33 #include "llvm/MC/MCValue.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/LEB128.h"
40 #include <cassert>
41 #include <cstdint>
42 #include <cstring>
43 #include <tuple>
44 #include <utility>
45 
46 using namespace llvm;
47 
48 #define DEBUG_TYPE "assembler"
49 
50 namespace {
51 namespace stats {
52 
53 STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
54 STATISTIC(EmittedRelaxableFragments,
55  "Number of emitted assembler fragments - relaxable");
56 STATISTIC(EmittedDataFragments,
57  "Number of emitted assembler fragments - data");
58 STATISTIC(EmittedCompactEncodedInstFragments,
59  "Number of emitted assembler fragments - compact encoded inst");
60 STATISTIC(EmittedAlignFragments,
61  "Number of emitted assembler fragments - align");
62 STATISTIC(EmittedFillFragments,
63  "Number of emitted assembler fragments - fill");
64 STATISTIC(EmittedOrgFragments,
65  "Number of emitted assembler fragments - org");
66 STATISTIC(evaluateFixup, "Number of evaluated fixups");
67 STATISTIC(FragmentLayouts, "Number of fragment layouts");
68 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
69 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
70 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
71 
72 } // end namespace stats
73 } // end anonymous namespace
74 
75 // FIXME FIXME FIXME: There are number of places in this file where we convert
76 // what is a 64-bit assembler value used for computation into a value in the
77 // object file, which may truncate it. We should detect that truncation where
78 // invalid and report errors back.
79 
80 /* *** */
81 
83  MCCodeEmitter &Emitter, MCObjectWriter &Writer)
84  : Context(Context), Backend(Backend), Emitter(Emitter), Writer(Writer),
85  BundleAlignSize(0), RelaxAll(false), SubsectionsViaSymbols(false),
86  IncrementalLinkerCompatible(false), ELFHeaderEFlags(0) {
87  VersionMinInfo.Major = 0; // Major version == 0 for "none specified"
88 }
89 
90 MCAssembler::~MCAssembler() = default;
91 
93  Sections.clear();
94  Symbols.clear();
95  IndirectSymbols.clear();
96  DataRegions.clear();
97  LinkerOptions.clear();
98  FileNames.clear();
99  ThumbFuncs.clear();
100  BundleAlignSize = 0;
101  RelaxAll = false;
102  SubsectionsViaSymbols = false;
103  IncrementalLinkerCompatible = false;
104  ELFHeaderEFlags = 0;
105  LOHContainer.reset();
106  VersionMinInfo.Major = 0;
107 
108  // reset objects owned by us
109  getBackend().reset();
110  getEmitter().reset();
111  getWriter().reset();
113 }
114 
116  if (Section.isRegistered())
117  return false;
118  Sections.push_back(&Section);
119  Section.setIsRegistered(true);
120  return true;
121 }
122 
124  if (ThumbFuncs.count(Symbol))
125  return true;
126 
127  if (!Symbol->isVariable())
128  return false;
129 
130  const MCExpr *Expr = Symbol->getVariableValue();
131 
132  MCValue V;
133  if (!Expr->evaluateAsRelocatable(V, nullptr, nullptr))
134  return false;
135 
136  if (V.getSymB() || V.getRefKind() != MCSymbolRefExpr::VK_None)
137  return false;
138 
139  const MCSymbolRefExpr *Ref = V.getSymA();
140  if (!Ref)
141  return false;
142 
143  if (Ref->getKind() != MCSymbolRefExpr::VK_None)
144  return false;
145 
146  const MCSymbol &Sym = Ref->getSymbol();
147  if (!isThumbFunc(&Sym))
148  return false;
149 
150  ThumbFuncs.insert(Symbol); // Cache it.
151  return true;
152 }
153 
155  // Non-temporary labels should always be visible to the linker.
156  if (!Symbol.isTemporary())
157  return true;
158 
159  // Absolute temporary labels are never visible.
160  if (!Symbol.isInSection())
161  return false;
162 
163  if (Symbol.isUsedInReloc())
164  return true;
165 
166  return false;
167 }
168 
169 const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const {
170  // Linker visible symbols define atoms.
171  if (isSymbolLinkerVisible(S))
172  return &S;
173 
174  // Absolute and undefined symbols have no defining atom.
175  if (!S.isInSection())
176  return nullptr;
177 
178  // Non-linker visible symbols in sections which can't be atomized have no
179  // defining atom.
181  *S.getFragment()->getParent()))
182  return nullptr;
183 
184  // Otherwise, return the atom for the containing fragment.
185  return S.getFragment()->getAtom();
186 }
187 
188 bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
189  const MCFixup &Fixup, const MCFragment *DF,
190  MCValue &Target, uint64_t &Value) const {
191  ++stats::evaluateFixup;
192 
193  // FIXME: This code has some duplication with recordRelocation. We should
194  // probably merge the two into a single callback that tries to evaluate a
195  // fixup and records a relocation if one is needed.
196 
197  // On error claim to have completely evaluated the fixup, to prevent any
198  // further processing from being done.
199  const MCExpr *Expr = Fixup.getValue();
200  MCContext &Ctx = getContext();
201  Value = 0;
202  if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
203  Ctx.reportError(Fixup.getLoc(), "expected relocatable expression");
204  return true;
205  }
206  if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
207  if (RefB->getKind() != MCSymbolRefExpr::VK_None) {
208  Ctx.reportError(Fixup.getLoc(),
209  "unsupported subtraction of qualified symbol");
210  return true;
211  }
212  }
213 
214  bool IsPCRel = Backend.getFixupKindInfo(
216 
217  bool IsResolved;
218  if (IsPCRel) {
219  if (Target.getSymB()) {
220  IsResolved = false;
221  } else if (!Target.getSymA()) {
222  IsResolved = false;
223  } else {
224  const MCSymbolRefExpr *A = Target.getSymA();
225  const MCSymbol &SA = A->getSymbol();
226  if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {
227  IsResolved = false;
228  } else {
230  *this, SA, *DF, false, true);
231  }
232  }
233  } else {
234  IsResolved = Target.isAbsolute();
235  }
236 
237  Value = Target.getConstant();
238 
239  if (const MCSymbolRefExpr *A = Target.getSymA()) {
240  const MCSymbol &Sym = A->getSymbol();
241  if (Sym.isDefined())
242  Value += Layout.getSymbolOffset(Sym);
243  }
244  if (const MCSymbolRefExpr *B = Target.getSymB()) {
245  const MCSymbol &Sym = B->getSymbol();
246  if (Sym.isDefined())
247  Value -= Layout.getSymbolOffset(Sym);
248  }
249 
250  bool ShouldAlignPC = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
252  assert((ShouldAlignPC ? IsPCRel : true) &&
253  "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
254 
255  if (IsPCRel) {
256  uint32_t Offset = Layout.getFragmentOffset(DF) + Fixup.getOffset();
257 
258  // A number of ARM fixups in Thumb mode require that the effective PC
259  // address be determined as the 32-bit aligned version of the actual offset.
260  if (ShouldAlignPC) Offset &= ~0x3;
261  Value -= Offset;
262  }
263 
264  // Let the backend force a relocation if needed.
265  if (IsResolved && Backend.shouldForceRelocation(*this, Fixup, Target))
266  IsResolved = false;
267 
268  return IsResolved;
269 }
270 
272  const MCFragment &F) const {
273  switch (F.getKind()) {
274  case MCFragment::FT_Data:
275  return cast<MCDataFragment>(F).getContents().size();
277  return cast<MCRelaxableFragment>(F).getContents().size();
279  return cast<MCCompactEncodedInstFragment>(F).getContents().size();
280  case MCFragment::FT_Fill:
281  return cast<MCFillFragment>(F).getSize();
282 
283  case MCFragment::FT_LEB:
284  return cast<MCLEBFragment>(F).getContents().size();
285 
287  return 4;
288 
289  case MCFragment::FT_Align: {
290  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
291  unsigned Offset = Layout.getFragmentOffset(&AF);
292  unsigned Size = OffsetToAlignment(Offset, AF.getAlignment());
293  // If we are padding with nops, force the padding to be larger than the
294  // minimum nop size.
295  if (Size > 0 && AF.hasEmitNops()) {
296  while (Size % getBackend().getMinimumNopSize())
297  Size += AF.getAlignment();
298  }
299  if (Size > AF.getMaxBytesToEmit())
300  return 0;
301  return Size;
302  }
303 
304  case MCFragment::FT_Org: {
305  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
306  MCValue Value;
307  if (!OF.getOffset().evaluateAsValue(Value, Layout)) {
309  "expected assembly-time absolute expression");
310  return 0;
311  }
312 
313  uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
314  int64_t TargetLocation = Value.getConstant();
315  if (const MCSymbolRefExpr *A = Value.getSymA()) {
316  uint64_t Val;
317  if (!Layout.getSymbolOffset(A->getSymbol(), Val)) {
318  getContext().reportError(OF.getLoc(), "expected absolute expression");
319  return 0;
320  }
321  TargetLocation += Val;
322  }
323  int64_t Size = TargetLocation - FragmentOffset;
324  if (Size < 0 || Size >= 0x40000000) {
326  OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
327  "' (at offset '" + Twine(FragmentOffset) + "')");
328  return 0;
329  }
330  return Size;
331  }
332 
334  return cast<MCDwarfLineAddrFragment>(F).getContents().size();
336  return cast<MCDwarfCallFrameFragment>(F).getContents().size();
338  return cast<MCCVInlineLineTableFragment>(F).getContents().size();
340  return cast<MCCVDefRangeFragment>(F).getContents().size();
342  llvm_unreachable("Should not have been added");
343  }
344 
345  llvm_unreachable("invalid fragment kind");
346 }
347 
349  MCFragment *Prev = F->getPrevNode();
350 
351  // We should never try to recompute something which is valid.
352  assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
353  // We should never try to compute the fragment layout if its predecessor
354  // isn't valid.
355  assert((!Prev || isFragmentValid(Prev)) &&
356  "Attempt to compute fragment before its predecessor!");
357 
358  ++stats::FragmentLayouts;
359 
360  // Compute fragment offset and size.
361  if (Prev)
362  F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
363  else
364  F->Offset = 0;
365  LastValidFragment[F->getParent()] = F;
366 
367  // If bundling is enabled and this fragment has instructions in it, it has to
368  // obey the bundling restrictions. With padding, we'll have:
369  //
370  //
371  // BundlePadding
372  // |||
373  // -------------------------------------
374  // Prev |##########| F |
375  // -------------------------------------
376  // ^
377  // |
378  // F->Offset
379  //
380  // The fragment's offset will point to after the padding, and its computed
381  // size won't include the padding.
382  //
383  // When the -mc-relax-all flag is used, we optimize bundling by writting the
384  // padding directly into fragments when the instructions are emitted inside
385  // the streamer. When the fragment is larger than the bundle size, we need to
386  // ensure that it's bundle aligned. This means that if we end up with
387  // multiple fragments, we must emit bundle padding between fragments.
388  //
389  // ".align N" is an example of a directive that introduces multiple
390  // fragments. We could add a special case to handle ".align N" by emitting
391  // within-fragment padding (which would produce less padding when N is less
392  // than the bundle size), but for now we don't.
393  //
394  if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
395  assert(isa<MCEncodedFragment>(F) &&
396  "Only MCEncodedFragment implementations have instructions");
397  uint64_t FSize = Assembler.computeFragmentSize(*this, *F);
398 
399  if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize())
400  report_fatal_error("Fragment can't be larger than a bundle size");
401 
402  uint64_t RequiredBundlePadding = computeBundlePadding(Assembler, F,
403  F->Offset, FSize);
404  if (RequiredBundlePadding > UINT8_MAX)
405  report_fatal_error("Padding cannot exceed 255 bytes");
406  F->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
407  F->Offset += RequiredBundlePadding;
408  }
409 }
410 
411 void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) {
412  bool New = !Symbol.isRegistered();
413  if (Created)
414  *Created = New;
415  if (New) {
416  Symbol.setIsRegistered(true);
417  Symbols.push_back(&Symbol);
418  }
419 }
420 
421 void MCAssembler::writeFragmentPadding(const MCFragment &F, uint64_t FSize,
422  MCObjectWriter *OW) const {
423  // Should NOP padding be written out before this fragment?
424  unsigned BundlePadding = F.getBundlePadding();
425  if (BundlePadding > 0) {
427  "Writing bundle padding with disabled bundling");
428  assert(F.hasInstructions() &&
429  "Writing bundle padding for a fragment without instructions");
430 
431  unsigned TotalLength = BundlePadding + static_cast<unsigned>(FSize);
432  if (F.alignToBundleEnd() && TotalLength > getBundleAlignSize()) {
433  // If the padding itself crosses a bundle boundary, it must be emitted
434  // in 2 pieces, since even nop instructions must not cross boundaries.
435  // v--------------v <- BundleAlignSize
436  // v---------v <- BundlePadding
437  // ----------------------------
438  // | Prev |####|####| F |
439  // ----------------------------
440  // ^-------------------^ <- TotalLength
441  unsigned DistanceToBoundary = TotalLength - getBundleAlignSize();
442  if (!getBackend().writeNopData(DistanceToBoundary, OW))
443  report_fatal_error("unable to write NOP sequence of " +
444  Twine(DistanceToBoundary) + " bytes");
445  BundlePadding -= DistanceToBoundary;
446  }
447  if (!getBackend().writeNopData(BundlePadding, OW))
448  report_fatal_error("unable to write NOP sequence of " +
449  Twine(BundlePadding) + " bytes");
450  }
451 }
452 
453 /// \brief Write the fragment \p F to the output file.
454 static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
455  const MCFragment &F) {
456  MCObjectWriter *OW = &Asm.getWriter();
457 
458  // FIXME: Embed in fragments instead?
459  uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
460 
461  Asm.writeFragmentPadding(F, FragmentSize, OW);
462 
463  // This variable (and its dummy usage) is to participate in the assert at
464  // the end of the function.
465  uint64_t Start = OW->getStream().tell();
466  (void) Start;
467 
468  ++stats::EmittedFragments;
469 
470  switch (F.getKind()) {
471  case MCFragment::FT_Align: {
472  ++stats::EmittedAlignFragments;
473  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
474  assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
475 
476  uint64_t Count = FragmentSize / AF.getValueSize();
477 
478  // FIXME: This error shouldn't actually occur (the front end should emit
479  // multiple .align directives to enforce the semantics it wants), but is
480  // severe enough that we want to report it. How to handle this?
481  if (Count * AF.getValueSize() != FragmentSize)
482  report_fatal_error("undefined .align directive, value size '" +
483  Twine(AF.getValueSize()) +
484  "' is not a divisor of padding size '" +
485  Twine(FragmentSize) + "'");
486 
487  // See if we are aligning with nops, and if so do that first to try to fill
488  // the Count bytes. Then if that did not fill any bytes or there are any
489  // bytes left to fill use the Value and ValueSize to fill the rest.
490  // If we are aligning with nops, ask that target to emit the right data.
491  if (AF.hasEmitNops()) {
492  if (!Asm.getBackend().writeNopData(Count, OW))
493  report_fatal_error("unable to write nop sequence of " +
494  Twine(Count) + " bytes");
495  break;
496  }
497 
498  // Otherwise, write out in multiples of the value size.
499  for (uint64_t i = 0; i != Count; ++i) {
500  switch (AF.getValueSize()) {
501  default: llvm_unreachable("Invalid size!");
502  case 1: OW->write8 (uint8_t (AF.getValue())); break;
503  case 2: OW->write16(uint16_t(AF.getValue())); break;
504  case 4: OW->write32(uint32_t(AF.getValue())); break;
505  case 8: OW->write64(uint64_t(AF.getValue())); break;
506  }
507  }
508  break;
509  }
510 
511  case MCFragment::FT_Data:
512  ++stats::EmittedDataFragments;
513  OW->writeBytes(cast<MCDataFragment>(F).getContents());
514  break;
515 
517  ++stats::EmittedRelaxableFragments;
518  OW->writeBytes(cast<MCRelaxableFragment>(F).getContents());
519  break;
520 
522  ++stats::EmittedCompactEncodedInstFragments;
523  OW->writeBytes(cast<MCCompactEncodedInstFragment>(F).getContents());
524  break;
525 
526  case MCFragment::FT_Fill: {
527  ++stats::EmittedFillFragments;
528  const MCFillFragment &FF = cast<MCFillFragment>(F);
529  uint8_t V = FF.getValue();
530  const unsigned MaxChunkSize = 16;
531  char Data[MaxChunkSize];
532  memcpy(Data, &V, 1);
533  for (unsigned I = 1; I < MaxChunkSize; ++I)
534  Data[I] = Data[0];
535 
536  uint64_t Size = FF.getSize();
537  for (unsigned ChunkSize = MaxChunkSize; ChunkSize; ChunkSize /= 2) {
538  StringRef Ref(Data, ChunkSize);
539  for (uint64_t I = 0, E = Size / ChunkSize; I != E; ++I)
540  OW->writeBytes(Ref);
541  Size = Size % ChunkSize;
542  }
543  break;
544  }
545 
546  case MCFragment::FT_LEB: {
547  const MCLEBFragment &LF = cast<MCLEBFragment>(F);
548  OW->writeBytes(LF.getContents());
549  break;
550  }
551 
552  case MCFragment::FT_SafeSEH: {
553  const MCSafeSEHFragment &SF = cast<MCSafeSEHFragment>(F);
554  OW->write32(SF.getSymbol()->getIndex());
555  break;
556  }
557 
558  case MCFragment::FT_Org: {
559  ++stats::EmittedOrgFragments;
560  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
561 
562  for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
563  OW->write8(uint8_t(OF.getValue()));
564 
565  break;
566  }
567 
568  case MCFragment::FT_Dwarf: {
569  const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
570  OW->writeBytes(OF.getContents());
571  break;
572  }
574  const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
575  OW->writeBytes(CF.getContents());
576  break;
577  }
579  const auto &OF = cast<MCCVInlineLineTableFragment>(F);
580  OW->writeBytes(OF.getContents());
581  break;
582  }
584  const auto &DRF = cast<MCCVDefRangeFragment>(F);
585  OW->writeBytes(DRF.getContents());
586  break;
587  }
589  llvm_unreachable("Should not have been added");
590  }
591 
592  assert(OW->getStream().tell() - Start == FragmentSize &&
593  "The stream should advance by fragment size");
594 }
595 
597  const MCAsmLayout &Layout) const {
598  // Ignore virtual sections.
599  if (Sec->isVirtualSection()) {
600  assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!");
601 
602  // Check that contents are only things legal inside a virtual section.
603  for (const MCFragment &F : *Sec) {
604  switch (F.getKind()) {
605  default: llvm_unreachable("Invalid fragment in virtual section!");
606  case MCFragment::FT_Data: {
607  // Check that we aren't trying to write a non-zero contents (or fixups)
608  // into a virtual section. This is to support clients which use standard
609  // directives to fill the contents of virtual sections.
610  const MCDataFragment &DF = cast<MCDataFragment>(F);
611  if (DF.fixup_begin() != DF.fixup_end())
612  report_fatal_error("cannot have fixups in virtual section!");
613  for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
614  if (DF.getContents()[i]) {
615  if (auto *ELFSec = dyn_cast<const MCSectionELF>(Sec))
616  report_fatal_error("non-zero initializer found in section '" +
617  ELFSec->getSectionName() + "'");
618  else
619  report_fatal_error("non-zero initializer found in virtual section");
620  }
621  break;
622  }
624  // Check that we aren't trying to write a non-zero value into a virtual
625  // section.
626  assert((cast<MCAlignFragment>(F).getValueSize() == 0 ||
627  cast<MCAlignFragment>(F).getValue() == 0) &&
628  "Invalid align in virtual section!");
629  break;
630  case MCFragment::FT_Fill:
631  assert((cast<MCFillFragment>(F).getValue() == 0) &&
632  "Invalid fill in virtual section!");
633  break;
634  }
635  }
636 
637  return;
638  }
639 
640  uint64_t Start = getWriter().getStream().tell();
641  (void)Start;
642 
643  for (const MCFragment &F : *Sec)
644  writeFragment(*this, Layout, F);
645 
646  assert(getWriter().getStream().tell() - Start ==
647  Layout.getSectionAddressSize(Sec));
648 }
649 
650 std::tuple<MCValue, uint64_t, bool>
651 MCAssembler::handleFixup(const MCAsmLayout &Layout, MCFragment &F,
652  const MCFixup &Fixup) {
653  // Evaluate the fixup.
654  MCValue Target;
655  uint64_t FixedValue;
656  bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue);
657  if (!IsResolved) {
658  // The fixup was unresolved, we need a relocation. Inform the object
659  // writer of the relocation, and give it an opportunity to adjust the
660  // fixup value if need be.
661  getWriter().recordRelocation(*this, Layout, &F, Fixup, Target, FixedValue);
662  }
663  return std::make_tuple(Target, FixedValue, IsResolved);
664 }
665 
667  DEBUG_WITH_TYPE("mc-dump", {
668  errs() << "assembler backend - pre-layout\n--\n";
669  dump(); });
670 
671  // Create dummy fragments and assign section ordinals.
672  unsigned SectionIndex = 0;
673  for (MCSection &Sec : *this) {
674  // Create dummy fragments to eliminate any empty sections, this simplifies
675  // layout.
676  if (Sec.getFragmentList().empty())
677  new MCDataFragment(&Sec);
678 
679  Sec.setOrdinal(SectionIndex++);
680  }
681 
682  // Assign layout order indices to sections and fragments.
683  for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
684  MCSection *Sec = Layout.getSectionOrder()[i];
685  Sec->setLayoutOrder(i);
686 
687  unsigned FragmentIndex = 0;
688  for (MCFragment &Frag : *Sec)
689  Frag.setLayoutOrder(FragmentIndex++);
690  }
691 
692  // Layout until everything fits.
693  while (layoutOnce(Layout))
694  if (getContext().hadError())
695  return;
696 
697  DEBUG_WITH_TYPE("mc-dump", {
698  errs() << "assembler backend - post-relaxation\n--\n";
699  dump(); });
700 
701  // Finalize the layout, including fragment lowering.
702  finishLayout(Layout);
703 
704  DEBUG_WITH_TYPE("mc-dump", {
705  errs() << "assembler backend - final-layout\n--\n";
706  dump(); });
707 
708  // Allow the object writer a chance to perform post-layout binding (for
709  // example, to set the index fields in the symbol data).
710  getWriter().executePostLayoutBinding(*this, Layout);
711 
712  // Evaluate and apply the fixups, generating relocation entries as necessary.
713  for (MCSection &Sec : *this) {
714  for (MCFragment &Frag : Sec) {
715  // Data and relaxable fragments both have fixups. So only process
716  // those here.
717  // FIXME: Is there a better way to do this? MCEncodedFragmentWithFixups
718  // being templated makes this tricky.
719  if (isa<MCEncodedFragment>(&Frag) &&
720  isa<MCCompactEncodedInstFragment>(&Frag))
721  continue;
722  if (!isa<MCEncodedFragment>(&Frag) && !isa<MCCVDefRangeFragment>(&Frag))
723  continue;
725  MutableArrayRef<char> Contents;
726  if (auto *FragWithFixups = dyn_cast<MCDataFragment>(&Frag)) {
727  Fixups = FragWithFixups->getFixups();
728  Contents = FragWithFixups->getContents();
729  } else if (auto *FragWithFixups = dyn_cast<MCRelaxableFragment>(&Frag)) {
730  Fixups = FragWithFixups->getFixups();
731  Contents = FragWithFixups->getContents();
732  } else if (auto *FragWithFixups = dyn_cast<MCCVDefRangeFragment>(&Frag)) {
733  Fixups = FragWithFixups->getFixups();
734  Contents = FragWithFixups->getContents();
735  } else
736  llvm_unreachable("Unknown fragment with fixups!");
737  for (const MCFixup &Fixup : Fixups) {
738  uint64_t FixedValue;
739  bool IsResolved;
740  MCValue Target;
741  std::tie(Target, FixedValue, IsResolved) =
742  handleFixup(Layout, Frag, Fixup);
743  getBackend().applyFixup(*this, Fixup, Target, Contents, FixedValue,
744  IsResolved);
745  }
746  }
747  }
748 }
749 
751  // Create the layout object.
752  MCAsmLayout Layout(*this);
753  layout(Layout);
754 
755  raw_ostream &OS = getWriter().getStream();
756  uint64_t StartOffset = OS.tell();
757 
758  // Write the object file.
759  getWriter().writeObject(*this, Layout);
760 
761  stats::ObjectBytes += OS.tell() - StartOffset;
762 }
763 
764 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
765  const MCRelaxableFragment *DF,
766  const MCAsmLayout &Layout) const {
767  MCValue Target;
768  uint64_t Value;
769  bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value);
770  if (Target.getSymA() &&
772  Fixup.getKind() == FK_Data_1)
773  return false;
774  return getBackend().fixupNeedsRelaxationAdvanced(Fixup, Resolved, Value, DF,
775  Layout);
776 }
777 
778 bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
779  const MCAsmLayout &Layout) const {
780  // If this inst doesn't ever need relaxation, ignore it. This occurs when we
781  // are intentionally pushing out inst fragments, or because we relaxed a
782  // previous instruction to one that doesn't need relaxation.
783  if (!getBackend().mayNeedRelaxation(F->getInst()))
784  return false;
785 
786  for (const MCFixup &Fixup : F->getFixups())
787  if (fixupNeedsRelaxation(Fixup, F, Layout))
788  return true;
789 
790  return false;
791 }
792 
793 bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
794  MCRelaxableFragment &F) {
795  if (!fragmentNeedsRelaxation(&F, Layout))
796  return false;
797 
798  ++stats::RelaxedInstructions;
799 
800  // FIXME-PERF: We could immediately lower out instructions if we can tell
801  // they are fully resolved, to avoid retesting on later passes.
802 
803  // Relax the fragment.
804 
805  MCInst Relaxed;
807 
808  // Encode the new instruction.
809  //
810  // FIXME-PERF: If it matters, we could let the target do this. It can
811  // probably do so more efficiently in many cases.
813  SmallString<256> Code;
814  raw_svector_ostream VecOS(Code);
815  getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, F.getSubtargetInfo());
816 
817  // Update the fragment.
818  F.setInst(Relaxed);
819  F.getContents() = Code;
820  F.getFixups() = Fixups;
821 
822  return true;
823 }
824 
825 bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
826  uint64_t OldSize = LF.getContents().size();
827  int64_t Value;
828  bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout);
829  if (!Abs)
830  report_fatal_error("sleb128 and uleb128 expressions must be absolute");
832  Data.clear();
833  raw_svector_ostream OSE(Data);
834  if (LF.isSigned())
835  encodeSLEB128(Value, OSE);
836  else
837  encodeULEB128(Value, OSE);
838  return OldSize != LF.getContents().size();
839 }
840 
841 bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
843  MCContext &Context = Layout.getAssembler().getContext();
844  uint64_t OldSize = DF.getContents().size();
845  int64_t AddrDelta;
846  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
847  assert(Abs && "We created a line delta with an invalid expression");
848  (void) Abs;
849  int64_t LineDelta;
850  LineDelta = DF.getLineDelta();
852  Data.clear();
853  raw_svector_ostream OSE(Data);
854  MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta,
855  AddrDelta, OSE);
856  return OldSize != Data.size();
857 }
858 
859 bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
861  MCContext &Context = Layout.getAssembler().getContext();
862  uint64_t OldSize = DF.getContents().size();
863  int64_t AddrDelta;
864  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
865  assert(Abs && "We created call frame with an invalid expression");
866  (void) Abs;
868  Data.clear();
869  raw_svector_ostream OSE(Data);
870  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
871  return OldSize != Data.size();
872 }
873 
874 bool MCAssembler::relaxCVInlineLineTable(MCAsmLayout &Layout,
876  unsigned OldSize = F.getContents().size();
878  return OldSize != F.getContents().size();
879 }
880 
881 bool MCAssembler::relaxCVDefRange(MCAsmLayout &Layout,
883  unsigned OldSize = F.getContents().size();
884  getContext().getCVContext().encodeDefRange(Layout, F);
885  return OldSize != F.getContents().size();
886 }
887 
888 bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
889  // Holds the first fragment which needed relaxing during this layout. It will
890  // remain NULL if none were relaxed.
891  // When a fragment is relaxed, all the fragments following it should get
892  // invalidated because their offset is going to change.
893  MCFragment *FirstRelaxedFragment = nullptr;
894 
895  // Attempt to relax all the fragments in the section.
896  for (MCSection::iterator I = Sec.begin(), IE = Sec.end(); I != IE; ++I) {
897  // Check if this is a fragment that needs relaxation.
898  bool RelaxedFrag = false;
899  switch(I->getKind()) {
900  default:
901  break;
903  assert(!getRelaxAll() &&
904  "Did not expect a MCRelaxableFragment in RelaxAll mode");
905  RelaxedFrag = relaxInstruction(Layout, *cast<MCRelaxableFragment>(I));
906  break;
908  RelaxedFrag = relaxDwarfLineAddr(Layout,
909  *cast<MCDwarfLineAddrFragment>(I));
910  break;
912  RelaxedFrag =
913  relaxDwarfCallFrameFragment(Layout,
914  *cast<MCDwarfCallFrameFragment>(I));
915  break;
916  case MCFragment::FT_LEB:
917  RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
918  break;
920  RelaxedFrag =
921  relaxCVInlineLineTable(Layout, *cast<MCCVInlineLineTableFragment>(I));
922  break;
924  RelaxedFrag = relaxCVDefRange(Layout, *cast<MCCVDefRangeFragment>(I));
925  break;
926  }
927  if (RelaxedFrag && !FirstRelaxedFragment)
928  FirstRelaxedFragment = &*I;
929  }
930  if (FirstRelaxedFragment) {
931  Layout.invalidateFragmentsFrom(FirstRelaxedFragment);
932  return true;
933  }
934  return false;
935 }
936 
937 bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
938  ++stats::RelaxationSteps;
939 
940  bool WasRelaxed = false;
941  for (iterator it = begin(), ie = end(); it != ie; ++it) {
942  MCSection &Sec = *it;
943  while (layoutSectionOnce(Layout, Sec))
944  WasRelaxed = true;
945  }
946 
947  return WasRelaxed;
948 }
949 
950 void MCAssembler::finishLayout(MCAsmLayout &Layout) {
951  // The layout is done. Mark every fragment as valid.
952  for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
953  MCSection &Section = *Layout.getSectionOrder()[i];
954  Layout.getFragmentOffset(&*Section.rbegin());
955  computeFragmentSize(Layout, *Section.rbegin());
956  }
957  getBackend().finishLayout(*this, Layout);
958 }
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:283
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
Definition: MCCodeView.cpp:519
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint32_t getIndex() const
Get the (implementation defined) index.
Definition: MCSymbol.h:311
bool alignToBundleEnd() const
Should this fragment be placed at the end of an aligned bundle?
Definition: MCFragment.h:116
LLVMContext & Context
struct fuzzer::@309 Flags
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:295
raw_pwrite_stream & getStream()
void write64(uint64_t Value)
This represents an "assembler immediate".
Definition: MCValue.h:40
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:175
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
VariantKind getKind() const
Definition: MCExpr.h:320
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
iterator begin()
Definition: MCAssembler.h:303
SmallString< 8 > & getContents()
Definition: MCFragment.h:521
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:124
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
virtual void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
int64_t getValue() const
Definition: MCFragment.h:310
virtual void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file.
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:52
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:493
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
FragmentType getKind() const
Definition: MCFragment.h:100
STATISTIC(NumFunctions, "Total number of functions")
F(f)
const MCSubtargetInfo & getSubtargetInfo()
Definition: MCFragment.h:272
const MCExpr & getOffset() const
Definition: MCFragment.h:363
void dump() const
Definition: MCFragment.cpp:450
bool isBundlingEnabled() const
Definition: MCAssembler.h:290
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void write8(uint8_t Value)
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:437
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:66
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:292
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:64
MCContext & getContext() const
Definition: MCAssembler.h:257
int64_t getConstant() const
Definition: MCValue.h:46
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:48
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:265
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
bool isSymbolLinkerVisible(const MCSymbol &SD) const
Check whether a particular symbol is visible to the linker and is required in the symbol table...
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:261
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.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool registerSection(MCSection &Section)
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:165
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:263
SMLoc getLoc() const
Definition: MCFragment.h:367
void writeSectionData(const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents using the given object writer.
Context object for machine code objects.
Definition: MCContext.h:59
const MCExpr & getAddrDelta() const
Definition: MCFragment.h:432
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:594
virtual bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target)
Hook to check if a relocation is needed for some target specific reason.
Definition: MCAsmBackend.h:64
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, " "relax all fixups in the emitted object file"))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
const MCExpr & getAddrDelta() const
Definition: MCFragment.h:460
reverse_iterator rbegin()
Definition: MCSection.h:162
const MCSymbol * getSymbol()
Definition: MCFragment.h:482
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:51
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
iterator end()
Definition: MCAssembler.h:306
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:181
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
virtual unsigned getMinimumNopSize() const
Returns the minimum size of a nop in bytes on this target.
Definition: MCAsmBackend.h:115
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const =0
Write an (optimal) nop sequence of Count bytes to the given output.
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
Definition: MCCodeView.cpp:386
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:255
void encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:77
void write32(uint32_t Value)
uint8_t getValue() const
Definition: MCFragment.h:337
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Definition: MCExpr.cpp:431
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291
virtual void reset()
Lifetime management.
Definition: MCCodeEmitter.h:32
cl::opt< bool > IncrementalLinkerCompatible("incremental-linker-compatible", cl::desc("When used with filetype=obj, " "emit an object file which can be used with an incremental linker"))
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:51
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
virtual void reset()
lifetime management
bool isRegistered() const
Definition: MCSection.h:140
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:206
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
Definition: MCFragment.cpp:129
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:63
const MCSymbol * getAtom(const MCSymbol &S) const
Find the symbol which defines the atom containing the given symbol, or null if there is no such symbo...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:220
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:47
void encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:23
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:572
Should this fixup kind force a 4-byte aligned effective PC value?
const MCSymbol * getAtom() const
Definition: MCFragment.h:105
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:66
void setIsRegistered(bool Value)
Definition: MCSection.h:141
uint32_t getOffset() const
Definition: MCFixup.h:95
Fragment representing the .cv_def_range directive.
Definition: MCFragment.h:532
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A one-byte fixup.
Definition: MCFixup.h:24
void layout(MCAsmLayout &Layout)
const MCExpr & getValue() const
Definition: MCFragment.h:394
void write16(uint16_t Value)
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Definition: MCFragment.cpp:77
PowerPC TLS Dynamic Call Fixup
void setOrdinal(unsigned Value)
Definition: MCSection.h:121
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions, where FOffset is the fragment&#39;s offset in its section and FSize is the fragment&#39;s size.
Definition: MCFragment.cpp:190
MCAssembler(MCContext &Context, MCAsmBackend &Backend, MCCodeEmitter &Emitter, MCObjectWriter &Writer)
Construct a new assembler instance.
Definition: MCAssembler.cpp:82
SMLoc getLoc() const
Definition: MCFixup.h:112
void writeFragmentPadding(const MCFragment &F, uint64_t FSize, MCObjectWriter *OW) const
Write the necessary bundle padding to the given object writer.
Iterator for intrusive lists based on ilist_node.
unsigned getMaxBytesToEmit() const
Definition: MCFragment.h:314
bool hasEmitNops() const
Definition: MCFragment.h:316
bool isInSection(bool SetUsed=true) const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:255
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:259
const MCSymbol & getSymbol() const
Definition: MCExpr.h:318
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:260
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:383
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
bool isRegistered() const
Definition: MCSymbol.h:210
An iterator type that allows iterating over the pointees via some other iterator. ...
Definition: iterator.h:289
static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F)
Write the fragment F to the output file.
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS)
Definition: MCDwarf.cpp:1584
MCLOHContainer & getLOHContainer()
Definition: MCAssembler.h:390
bool getRelaxAll() const
Definition: MCAssembler.h:287
Target - Wrapper for Target specific information.
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCSection * getParent() const
Definition: MCFragment.h:102
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:113
SmallString< 8 > & getContents()
Definition: MCFragment.h:462
void setIsRegistered(bool Value) const
Definition: MCSymbol.h:211
Fragment representing the binary annotations produced by the .cv_inline_linetable directive...
Definition: MCFragment.h:494
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isUsedInReloc() const
Definition: MCSymbol.h:214
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCFragment.h:128
unsigned getValueSize() const
Definition: MCFragment.h:312
unsigned getAlignment() const
Definition: MCFragment.h:308
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
uint64_t getSize() const
Definition: MCFragment.h:338
int64_t getLineDelta() const
Definition: MCFragment.h:430
const MCInst & getInst() const
Definition: MCFragment.h:269
#define I(x, y, z)
Definition: MD5.cpp:58
bool isDefined(bool SetUsed=true) const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:249
bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables...
Definition: MCExpr.cpp:602
uint64_t computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const
Compute the effective fragment size assuming it is laid out at the given SectionAddress and FragmentO...
SmallString< 8 > & getContents()
Definition: MCFragment.h:398
void writeBytes(const SmallVectorImpl< char > &ByteVec, unsigned ZeroFillSize=0)
uint32_t getRefKind() const
Definition: MCValue.h:49
CodeViewContext & getCVContext()
Definition: MCContext.cpp:562
void reset()
Reuse an assembler instance.
Definition: MCAssembler.cpp:92
Fragment for data and encoded instructions.
Definition: MCFragment.h:224
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:181
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
Definition: MCSymbol.h:300
bool isSigned() const
Definition: MCFragment.h:396
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition: MathExtras.h:719
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:98
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
const MCExpr * getValue() const
Definition: MCFixup.h:98
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
iterator end()
Definition: MCSection.h:159
uint8_t getValue() const
Definition: MCFragment.h:365
SmallString< 8 > & getContents()
Definition: MCFragment.h:434
virtual void reset()
lifetime management
Definition: MCAsmBackend.h:45
void Finish()
Finish - Do final processing and write the object to the output stream.
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:143
virtual void finishLayout(MCAssembler const &Asm, MCAsmLayout &Layout) const
Give backend an opportunity to finish layout after relaxation.
Definition: MCAsmBackend.h:124
void setInst(const MCInst &Value)
Definition: MCFragment.h:270
MCFixupKind getKind() const
Definition: MCFixup.h:93
iterator begin()
Definition: MCSection.h:156
uint8_t getBundlePadding() const
Get the padding size that must be inserted before this fragment.
Definition: MCFragment.h:124