LLVM  13.0.0git
MCAssembler.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
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 
9 #include "llvm/MC/MCAssembler.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/Statistic.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/MC/MCAsmBackend.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCAsmLayout.h"
19 #include "llvm/MC/MCCodeEmitter.h"
20 #include "llvm/MC/MCCodeView.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCDwarf.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCFixup.h"
26 #include "llvm/MC/MCFragment.h"
27 #include "llvm/MC/MCInst.h"
28 #include "llvm/MC/MCObjectWriter.h"
29 #include "llvm/MC/MCSection.h"
30 #include "llvm/MC/MCSectionELF.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCValue.h"
33 #include "llvm/Support/Alignment.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/LEB128.h"
41 #include <cassert>
42 #include <cstdint>
43 #include <cstring>
44 #include <tuple>
45 #include <utility>
46 
47 using namespace llvm;
48 
49 #define DEBUG_TYPE "assembler"
50 
51 namespace {
52 namespace stats {
53 
54 STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
55 STATISTIC(EmittedRelaxableFragments,
56  "Number of emitted assembler fragments - relaxable");
57 STATISTIC(EmittedDataFragments,
58  "Number of emitted assembler fragments - data");
59 STATISTIC(EmittedCompactEncodedInstFragments,
60  "Number of emitted assembler fragments - compact encoded inst");
61 STATISTIC(EmittedAlignFragments,
62  "Number of emitted assembler fragments - align");
63 STATISTIC(EmittedFillFragments,
64  "Number of emitted assembler fragments - fill");
65 STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
66 STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
67 STATISTIC(evaluateFixup, "Number of evaluated fixups");
68 STATISTIC(FragmentLayouts, "Number of fragment layouts");
69 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
70 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
71 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
72 
73 } // end namespace stats
74 } // end anonymous namespace
75 
76 // FIXME FIXME FIXME: There are number of places in this file where we convert
77 // what is a 64-bit assembler value used for computation into a value in the
78 // object file, which may truncate it. We should detect that truncation where
79 // invalid and report errors back.
80 
81 /* *** */
82 
84  std::unique_ptr<MCAsmBackend> Backend,
85  std::unique_ptr<MCCodeEmitter> Emitter,
86  std::unique_ptr<MCObjectWriter> Writer)
87  : Context(Context), Backend(std::move(Backend)),
88  Emitter(std::move(Emitter)), Writer(std::move(Writer)),
89  BundleAlignSize(0), RelaxAll(false), SubsectionsViaSymbols(false),
90  IncrementalLinkerCompatible(false), ELFHeaderEFlags(0) {
91  VersionInfo.Major = 0; // Major version == 0 for "none specified"
92 }
93 
94 MCAssembler::~MCAssembler() = default;
95 
97  Sections.clear();
98  Symbols.clear();
99  IndirectSymbols.clear();
100  DataRegions.clear();
101  LinkerOptions.clear();
102  FileNames.clear();
103  ThumbFuncs.clear();
104  BundleAlignSize = 0;
105  RelaxAll = false;
106  SubsectionsViaSymbols = false;
107  IncrementalLinkerCompatible = false;
108  ELFHeaderEFlags = 0;
109  LOHContainer.reset();
110  VersionInfo.Major = 0;
111  VersionInfo.SDKVersion = VersionTuple();
112 
113  // reset objects owned by us
114  if (getBackendPtr())
115  getBackendPtr()->reset();
116  if (getEmitterPtr())
117  getEmitterPtr()->reset();
118  if (getWriterPtr())
119  getWriterPtr()->reset();
121 }
122 
124  if (Section.isRegistered())
125  return false;
126  Sections.push_back(&Section);
127  Section.setIsRegistered(true);
128  return true;
129 }
130 
132  if (ThumbFuncs.count(Symbol))
133  return true;
134 
135  if (!Symbol->isVariable())
136  return false;
137 
138  const MCExpr *Expr = Symbol->getVariableValue();
139 
140  MCValue V;
141  if (!Expr->evaluateAsRelocatable(V, nullptr, nullptr))
142  return false;
143 
144  if (V.getSymB() || V.getRefKind() != MCSymbolRefExpr::VK_None)
145  return false;
146 
147  const MCSymbolRefExpr *Ref = V.getSymA();
148  if (!Ref)
149  return false;
150 
151  if (Ref->getKind() != MCSymbolRefExpr::VK_None)
152  return false;
153 
154  const MCSymbol &Sym = Ref->getSymbol();
155  if (!isThumbFunc(&Sym))
156  return false;
157 
158  ThumbFuncs.insert(Symbol); // Cache it.
159  return true;
160 }
161 
163  // Non-temporary labels should always be visible to the linker.
164  if (!Symbol.isTemporary())
165  return true;
166 
167  if (Symbol.isUsedInReloc())
168  return true;
169 
170  return false;
171 }
172 
173 const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const {
174  // Linker visible symbols define atoms.
176  return &S;
177 
178  // Absolute and undefined symbols have no defining atom.
179  if (!S.isInSection())
180  return nullptr;
181 
182  // Non-linker visible symbols in sections which can't be atomized have no
183  // defining atom.
184  if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols(
185  *S.getFragment()->getParent()))
186  return nullptr;
187 
188  // Otherwise, return the atom for the containing fragment.
189  return S.getFragment()->getAtom();
190 }
191 
192 bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
193  const MCFixup &Fixup, const MCFragment *DF,
194  MCValue &Target, uint64_t &Value,
195  bool &WasForced) const {
196  ++stats::evaluateFixup;
197 
198  // FIXME: This code has some duplication with recordRelocation. We should
199  // probably merge the two into a single callback that tries to evaluate a
200  // fixup and records a relocation if one is needed.
201 
202  // On error claim to have completely evaluated the fixup, to prevent any
203  // further processing from being done.
204  const MCExpr *Expr = Fixup.getValue();
205  MCContext &Ctx = getContext();
206  Value = 0;
207  WasForced = false;
208  if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
209  Ctx.reportError(Fixup.getLoc(), "expected relocatable expression");
210  return true;
211  }
212  if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
213  if (RefB->getKind() != MCSymbolRefExpr::VK_None) {
214  Ctx.reportError(Fixup.getLoc(),
215  "unsupported subtraction of qualified symbol");
216  return true;
217  }
218  }
219 
220  assert(getBackendPtr() && "Expected assembler backend");
221  bool IsTarget = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
223 
224  if (IsTarget)
225  return getBackend().evaluateTargetFixup(*this, Layout, Fixup, DF, Target,
226  Value, WasForced);
227 
228  unsigned FixupFlags = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags;
229  bool IsPCRel = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
231 
232  bool IsResolved = false;
233  if (IsPCRel) {
234  if (Target.getSymB()) {
235  IsResolved = false;
236  } else if (!Target.getSymA()) {
237  IsResolved = false;
238  } else {
239  const MCSymbolRefExpr *A = Target.getSymA();
240  const MCSymbol &SA = A->getSymbol();
241  if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {
242  IsResolved = false;
243  } else if (auto *Writer = getWriterPtr()) {
244  IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) ||
245  Writer->isSymbolRefDifferenceFullyResolvedImpl(
246  *this, SA, *DF, false, true);
247  }
248  }
249  } else {
250  IsResolved = Target.isAbsolute();
251  }
252 
253  Value = Target.getConstant();
254 
255  if (const MCSymbolRefExpr *A = Target.getSymA()) {
256  const MCSymbol &Sym = A->getSymbol();
257  if (Sym.isDefined())
258  Value += Layout.getSymbolOffset(Sym);
259  }
260  if (const MCSymbolRefExpr *B = Target.getSymB()) {
261  const MCSymbol &Sym = B->getSymbol();
262  if (Sym.isDefined())
263  Value -= Layout.getSymbolOffset(Sym);
264  }
265 
266  bool ShouldAlignPC = getBackend().getFixupKindInfo(Fixup.getKind()).Flags &
268  assert((ShouldAlignPC ? IsPCRel : true) &&
269  "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
270 
271  if (IsPCRel) {
272  uint32_t Offset = Layout.getFragmentOffset(DF) + Fixup.getOffset();
273 
274  // A number of ARM fixups in Thumb mode require that the effective PC
275  // address be determined as the 32-bit aligned version of the actual offset.
276  if (ShouldAlignPC) Offset &= ~0x3;
277  Value -= Offset;
278  }
279 
280  // Let the backend force a relocation if needed.
281  if (IsResolved && getBackend().shouldForceRelocation(*this, Fixup, Target)) {
282  IsResolved = false;
283  WasForced = true;
284  }
285 
286  return IsResolved;
287 }
288 
290  const MCFragment &F) const {
291  assert(getBackendPtr() && "Requires assembler backend");
292  switch (F.getKind()) {
293  case MCFragment::FT_Data:
294  return cast<MCDataFragment>(F).getContents().size();
296  return cast<MCRelaxableFragment>(F).getContents().size();
298  return cast<MCCompactEncodedInstFragment>(F).getContents().size();
299  case MCFragment::FT_Fill: {
300  auto &FF = cast<MCFillFragment>(F);
301  int64_t NumValues = 0;
302  if (!FF.getNumValues().evaluateAsAbsolute(NumValues, Layout)) {
303  getContext().reportError(FF.getLoc(),
304  "expected assembly-time absolute expression");
305  return 0;
306  }
307  int64_t Size = NumValues * FF.getValueSize();
308  if (Size < 0) {
309  getContext().reportError(FF.getLoc(), "invalid number of bytes");
310  return 0;
311  }
312  return Size;
313  }
314 
315  case MCFragment::FT_Nops:
316  return cast<MCNopsFragment>(F).getNumBytes();
317 
318  case MCFragment::FT_LEB:
319  return cast<MCLEBFragment>(F).getContents().size();
320 
322  return cast<MCBoundaryAlignFragment>(F).getSize();
323 
325  return 4;
326 
327  case MCFragment::FT_Align: {
328  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
329  unsigned Offset = Layout.getFragmentOffset(&AF);
330  unsigned Size = offsetToAlignment(Offset, Align(AF.getAlignment()));
331 
332  // Insert extra Nops for code alignment if the target define
333  // shouldInsertExtraNopBytesForCodeAlign target hook.
334  if (AF.getParent()->UseCodeAlign() && AF.hasEmitNops() &&
335  getBackend().shouldInsertExtraNopBytesForCodeAlign(AF, Size))
336  return Size;
337 
338  // If we are padding with nops, force the padding to be larger than the
339  // minimum nop size.
340  if (Size > 0 && AF.hasEmitNops()) {
341  while (Size % getBackend().getMinimumNopSize())
342  Size += AF.getAlignment();
343  }
344  if (Size > AF.getMaxBytesToEmit())
345  return 0;
346  return Size;
347  }
348 
349  case MCFragment::FT_Org: {
350  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
351  MCValue Value;
352  if (!OF.getOffset().evaluateAsValue(Value, Layout)) {
354  "expected assembly-time absolute expression");
355  return 0;
356  }
357 
358  uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
359  int64_t TargetLocation = Value.getConstant();
360  if (const MCSymbolRefExpr *A = Value.getSymA()) {
361  uint64_t Val;
362  if (!Layout.getSymbolOffset(A->getSymbol(), Val)) {
363  getContext().reportError(OF.getLoc(), "expected absolute expression");
364  return 0;
365  }
366  TargetLocation += Val;
367  }
368  int64_t Size = TargetLocation - FragmentOffset;
369  if (Size < 0 || Size >= 0x40000000) {
371  OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
372  "' (at offset '" + Twine(FragmentOffset) + "')");
373  return 0;
374  }
375  return Size;
376  }
377 
379  return cast<MCDwarfLineAddrFragment>(F).getContents().size();
381  return cast<MCDwarfCallFrameFragment>(F).getContents().size();
383  return cast<MCCVInlineLineTableFragment>(F).getContents().size();
385  return cast<MCCVDefRangeFragment>(F).getContents().size();
387  return cast<MCPseudoProbeAddrFragment>(F).getContents().size();
389  llvm_unreachable("Should not have been added");
390  }
391 
392  llvm_unreachable("invalid fragment kind");
393 }
394 
396  MCFragment *Prev = F->getPrevNode();
397 
398  // We should never try to recompute something which is valid.
399  assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
400  // We should never try to compute the fragment layout if its predecessor
401  // isn't valid.
402  assert((!Prev || isFragmentValid(Prev)) &&
403  "Attempt to compute fragment before its predecessor!");
404 
405  assert(!F->IsBeingLaidOut && "Already being laid out!");
406  F->IsBeingLaidOut = true;
407 
408  ++stats::FragmentLayouts;
409 
410  // Compute fragment offset and size.
411  if (Prev)
412  F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
413  else
414  F->Offset = 0;
415  F->IsBeingLaidOut = false;
416  LastValidFragment[F->getParent()] = F;
417 
418  // If bundling is enabled and this fragment has instructions in it, it has to
419  // obey the bundling restrictions. With padding, we'll have:
420  //
421  //
422  // BundlePadding
423  // |||
424  // -------------------------------------
425  // Prev |##########| F |
426  // -------------------------------------
427  // ^
428  // |
429  // F->Offset
430  //
431  // The fragment's offset will point to after the padding, and its computed
432  // size won't include the padding.
433  //
434  // When the -mc-relax-all flag is used, we optimize bundling by writting the
435  // padding directly into fragments when the instructions are emitted inside
436  // the streamer. When the fragment is larger than the bundle size, we need to
437  // ensure that it's bundle aligned. This means that if we end up with
438  // multiple fragments, we must emit bundle padding between fragments.
439  //
440  // ".align N" is an example of a directive that introduces multiple
441  // fragments. We could add a special case to handle ".align N" by emitting
442  // within-fragment padding (which would produce less padding when N is less
443  // than the bundle size), but for now we don't.
444  //
445  if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
446  assert(isa<MCEncodedFragment>(F) &&
447  "Only MCEncodedFragment implementations have instructions");
448  MCEncodedFragment *EF = cast<MCEncodedFragment>(F);
449  uint64_t FSize = Assembler.computeFragmentSize(*this, *EF);
450 
451  if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize())
452  report_fatal_error("Fragment can't be larger than a bundle size");
453 
454  uint64_t RequiredBundlePadding =
455  computeBundlePadding(Assembler, EF, EF->Offset, FSize);
456  if (RequiredBundlePadding > UINT8_MAX)
457  report_fatal_error("Padding cannot exceed 255 bytes");
458  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
459  EF->Offset += RequiredBundlePadding;
460  }
461 }
462 
463 void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) {
464  bool New = !Symbol.isRegistered();
465  if (Created)
466  *Created = New;
467  if (New) {
468  Symbol.setIsRegistered(true);
469  Symbols.push_back(&Symbol);
470  }
471 }
472 
474  const MCEncodedFragment &EF,
475  uint64_t FSize) const {
476  assert(getBackendPtr() && "Expected assembler backend");
477  // Should NOP padding be written out before this fragment?
478  unsigned BundlePadding = EF.getBundlePadding();
479  if (BundlePadding > 0) {
481  "Writing bundle padding with disabled bundling");
482  assert(EF.hasInstructions() &&
483  "Writing bundle padding for a fragment without instructions");
484 
485  unsigned TotalLength = BundlePadding + static_cast<unsigned>(FSize);
486  if (EF.alignToBundleEnd() && TotalLength > getBundleAlignSize()) {
487  // If the padding itself crosses a bundle boundary, it must be emitted
488  // in 2 pieces, since even nop instructions must not cross boundaries.
489  // v--------------v <- BundleAlignSize
490  // v---------v <- BundlePadding
491  // ----------------------------
492  // | Prev |####|####| F |
493  // ----------------------------
494  // ^-------------------^ <- TotalLength
495  unsigned DistanceToBoundary = TotalLength - getBundleAlignSize();
496  if (!getBackend().writeNopData(OS, DistanceToBoundary))
497  report_fatal_error("unable to write NOP sequence of " +
498  Twine(DistanceToBoundary) + " bytes");
499  BundlePadding -= DistanceToBoundary;
500  }
501  if (!getBackend().writeNopData(OS, BundlePadding))
502  report_fatal_error("unable to write NOP sequence of " +
503  Twine(BundlePadding) + " bytes");
504  }
505 }
506 
507 /// Write the fragment \p F to the output file.
508 static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
509  const MCAsmLayout &Layout, const MCFragment &F) {
510  // FIXME: Embed in fragments instead?
511  uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
512 
513  support::endianness Endian = Asm.getBackend().Endian;
514 
515  if (const MCEncodedFragment *EF = dyn_cast<MCEncodedFragment>(&F))
516  Asm.writeFragmentPadding(OS, *EF, FragmentSize);
517 
518  // This variable (and its dummy usage) is to participate in the assert at
519  // the end of the function.
520  uint64_t Start = OS.tell();
521  (void) Start;
522 
523  ++stats::EmittedFragments;
524 
525  switch (F.getKind()) {
526  case MCFragment::FT_Align: {
527  ++stats::EmittedAlignFragments;
528  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
529  assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
530 
531  uint64_t Count = FragmentSize / AF.getValueSize();
532 
533  // FIXME: This error shouldn't actually occur (the front end should emit
534  // multiple .align directives to enforce the semantics it wants), but is
535  // severe enough that we want to report it. How to handle this?
536  if (Count * AF.getValueSize() != FragmentSize)
537  report_fatal_error("undefined .align directive, value size '" +
538  Twine(AF.getValueSize()) +
539  "' is not a divisor of padding size '" +
540  Twine(FragmentSize) + "'");
541 
542  // See if we are aligning with nops, and if so do that first to try to fill
543  // the Count bytes. Then if that did not fill any bytes or there are any
544  // bytes left to fill use the Value and ValueSize to fill the rest.
545  // If we are aligning with nops, ask that target to emit the right data.
546  if (AF.hasEmitNops()) {
547  if (!Asm.getBackend().writeNopData(OS, Count))
548  report_fatal_error("unable to write nop sequence of " +
549  Twine(Count) + " bytes");
550  break;
551  }
552 
553  // Otherwise, write out in multiples of the value size.
554  for (uint64_t i = 0; i != Count; ++i) {
555  switch (AF.getValueSize()) {
556  default: llvm_unreachable("Invalid size!");
557  case 1: OS << char(AF.getValue()); break;
558  case 2:
559  support::endian::write<uint16_t>(OS, AF.getValue(), Endian);
560  break;
561  case 4:
562  support::endian::write<uint32_t>(OS, AF.getValue(), Endian);
563  break;
564  case 8:
565  support::endian::write<uint64_t>(OS, AF.getValue(), Endian);
566  break;
567  }
568  }
569  break;
570  }
571 
572  case MCFragment::FT_Data:
573  ++stats::EmittedDataFragments;
574  OS << cast<MCDataFragment>(F).getContents();
575  break;
576 
578  ++stats::EmittedRelaxableFragments;
579  OS << cast<MCRelaxableFragment>(F).getContents();
580  break;
581 
583  ++stats::EmittedCompactEncodedInstFragments;
584  OS << cast<MCCompactEncodedInstFragment>(F).getContents();
585  break;
586 
587  case MCFragment::FT_Fill: {
588  ++stats::EmittedFillFragments;
589  const MCFillFragment &FF = cast<MCFillFragment>(F);
590  uint64_t V = FF.getValue();
591  unsigned VSize = FF.getValueSize();
592  const unsigned MaxChunkSize = 16;
593  char Data[MaxChunkSize];
594  assert(0 < VSize && VSize <= MaxChunkSize && "Illegal fragment fill size");
595  // Duplicate V into Data as byte vector to reduce number of
596  // writes done. As such, do endian conversion here.
597  for (unsigned I = 0; I != VSize; ++I) {
598  unsigned index = Endian == support::little ? I : (VSize - I - 1);
599  Data[I] = uint8_t(V >> (index * 8));
600  }
601  for (unsigned I = VSize; I < MaxChunkSize; ++I)
602  Data[I] = Data[I - VSize];
603 
604  // Set to largest multiple of VSize in Data.
605  const unsigned NumPerChunk = MaxChunkSize / VSize;
606  // Set ChunkSize to largest multiple of VSize in Data
607  const unsigned ChunkSize = VSize * NumPerChunk;
608 
609  // Do copies by chunk.
610  StringRef Ref(Data, ChunkSize);
611  for (uint64_t I = 0, E = FragmentSize / ChunkSize; I != E; ++I)
612  OS << Ref;
613 
614  // do remainder if needed.
615  unsigned TrailingCount = FragmentSize % ChunkSize;
616  if (TrailingCount)
617  OS.write(Data, TrailingCount);
618  break;
619  }
620 
621  case MCFragment::FT_Nops: {
622  ++stats::EmittedNopsFragments;
623  const MCNopsFragment &NF = cast<MCNopsFragment>(F);
624  int64_t NumBytes = NF.getNumBytes();
625  int64_t ControlledNopLength = NF.getControlledNopLength();
626  int64_t MaximumNopLength = Asm.getBackend().getMaximumNopSize();
627 
628  assert(NumBytes > 0 && "Expected positive NOPs fragment size");
629  assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
630 
631  if (ControlledNopLength > MaximumNopLength) {
632  Asm.getContext().reportError(NF.getLoc(),
633  "illegal NOP size " +
634  std::to_string(ControlledNopLength) +
635  ". (expected within [0, " +
636  std::to_string(MaximumNopLength) + "])");
637  // Clamp the NOP length as reportError does not stop the execution
638  // immediately.
639  ControlledNopLength = MaximumNopLength;
640  }
641 
642  // Use maximum value if the size of each NOP is not specified
643  if (!ControlledNopLength)
644  ControlledNopLength = MaximumNopLength;
645 
646  while (NumBytes) {
647  uint64_t NumBytesToEmit =
648  (uint64_t)std::min(NumBytes, ControlledNopLength);
649  assert(NumBytesToEmit && "try to emit empty NOP instruction");
650  if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit)) {
651  report_fatal_error("unable to write nop sequence of the remaining " +
652  Twine(NumBytesToEmit) + " bytes");
653  break;
654  }
655  NumBytes -= NumBytesToEmit;
656  }
657  break;
658  }
659 
660  case MCFragment::FT_LEB: {
661  const MCLEBFragment &LF = cast<MCLEBFragment>(F);
662  OS << LF.getContents();
663  break;
664  }
665 
667  if (!Asm.getBackend().writeNopData(OS, FragmentSize))
668  report_fatal_error("unable to write nop sequence of " +
669  Twine(FragmentSize) + " bytes");
670  break;
671  }
672 
674  const MCSymbolIdFragment &SF = cast<MCSymbolIdFragment>(F);
675  support::endian::write<uint32_t>(OS, SF.getSymbol()->getIndex(), Endian);
676  break;
677  }
678 
679  case MCFragment::FT_Org: {
680  ++stats::EmittedOrgFragments;
681  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
682 
683  for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
684  OS << char(OF.getValue());
685 
686  break;
687  }
688 
689  case MCFragment::FT_Dwarf: {
690  const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
691  OS << OF.getContents();
692  break;
693  }
695  const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
696  OS << CF.getContents();
697  break;
698  }
700  const auto &OF = cast<MCCVInlineLineTableFragment>(F);
701  OS << OF.getContents();
702  break;
703  }
705  const auto &DRF = cast<MCCVDefRangeFragment>(F);
706  OS << DRF.getContents();
707  break;
708  }
710  const MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(F);
711  OS << PF.getContents();
712  break;
713  }
715  llvm_unreachable("Should not have been added");
716  }
717 
718  assert(OS.tell() - Start == FragmentSize &&
719  "The stream should advance by fragment size");
720 }
721 
723  const MCAsmLayout &Layout) const {
724  assert(getBackendPtr() && "Expected assembler backend");
725 
726  // Ignore virtual sections.
727  if (Sec->isVirtualSection()) {
728  assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!");
729 
730  // Check that contents are only things legal inside a virtual section.
731  for (const MCFragment &F : *Sec) {
732  switch (F.getKind()) {
733  default: llvm_unreachable("Invalid fragment in virtual section!");
734  case MCFragment::FT_Data: {
735  // Check that we aren't trying to write a non-zero contents (or fixups)
736  // into a virtual section. This is to support clients which use standard
737  // directives to fill the contents of virtual sections.
738  const MCDataFragment &DF = cast<MCDataFragment>(F);
739  if (DF.fixup_begin() != DF.fixup_end())
740  getContext().reportError(SMLoc(), Sec->getVirtualSectionKind() +
741  " section '" + Sec->getName() +
742  "' cannot have fixups");
743  for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
744  if (DF.getContents()[i]) {
746  Sec->getVirtualSectionKind() +
747  " section '" + Sec->getName() +
748  "' cannot have non-zero initializers");
749  break;
750  }
751  break;
752  }
754  // Check that we aren't trying to write a non-zero value into a virtual
755  // section.
756  assert((cast<MCAlignFragment>(F).getValueSize() == 0 ||
757  cast<MCAlignFragment>(F).getValue() == 0) &&
758  "Invalid align in virtual section!");
759  break;
760  case MCFragment::FT_Fill:
761  assert((cast<MCFillFragment>(F).getValue() == 0) &&
762  "Invalid fill in virtual section!");
763  break;
764  case MCFragment::FT_Org:
765  break;
766  }
767  }
768 
769  return;
770  }
771 
772  uint64_t Start = OS.tell();
773  (void)Start;
774 
775  for (const MCFragment &F : *Sec)
776  writeFragment(OS, *this, Layout, F);
777 
778  assert(getContext().hadError() ||
779  OS.tell() - Start == Layout.getSectionAddressSize(Sec));
780 }
781 
782 std::tuple<MCValue, uint64_t, bool>
783 MCAssembler::handleFixup(const MCAsmLayout &Layout, MCFragment &F,
784  const MCFixup &Fixup) {
785  // Evaluate the fixup.
786  MCValue Target;
787  uint64_t FixedValue;
788  bool WasForced;
789  bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue,
790  WasForced);
791  if (!IsResolved) {
792  // The fixup was unresolved, we need a relocation. Inform the object
793  // writer of the relocation, and give it an opportunity to adjust the
794  // fixup value if need be.
795  if (Target.getSymA() && Target.getSymB() &&
796  getBackend().requiresDiffExpressionRelocations()) {
797  // The fixup represents the difference between two symbols, which the
798  // backend has indicated must be resolved at link time. Split up the fixup
799  // into two relocations, one for the add, and one for the sub, and emit
800  // both of these. The constant will be associated with the add half of the
801  // expression.
802  MCFixup FixupAdd = MCFixup::createAddFor(Fixup);
803  MCValue TargetAdd =
804  MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
805  getWriter().recordRelocation(*this, Layout, &F, FixupAdd, TargetAdd,
806  FixedValue);
807  MCFixup FixupSub = MCFixup::createSubFor(Fixup);
808  MCValue TargetSub = MCValue::get(Target.getSymB());
809  getWriter().recordRelocation(*this, Layout, &F, FixupSub, TargetSub,
810  FixedValue);
811  } else {
812  getWriter().recordRelocation(*this, Layout, &F, Fixup, Target,
813  FixedValue);
814  }
815  }
816  return std::make_tuple(Target, FixedValue, IsResolved);
817 }
818 
820  assert(getBackendPtr() && "Expected assembler backend");
821  DEBUG_WITH_TYPE("mc-dump", {
822  errs() << "assembler backend - pre-layout\n--\n";
823  dump(); });
824 
825  // Create dummy fragments and assign section ordinals.
826  unsigned SectionIndex = 0;
827  for (MCSection &Sec : *this) {
828  // Create dummy fragments to eliminate any empty sections, this simplifies
829  // layout.
830  if (Sec.getFragmentList().empty())
831  new MCDataFragment(&Sec);
832 
833  Sec.setOrdinal(SectionIndex++);
834  }
835 
836  // Assign layout order indices to sections and fragments.
837  for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
838  MCSection *Sec = Layout.getSectionOrder()[i];
839  Sec->setLayoutOrder(i);
840 
841  unsigned FragmentIndex = 0;
842  for (MCFragment &Frag : *Sec)
843  Frag.setLayoutOrder(FragmentIndex++);
844  }
845 
846  // Layout until everything fits.
847  while (layoutOnce(Layout)) {
848  if (getContext().hadError())
849  return;
850  // Size of fragments in one section can depend on the size of fragments in
851  // another. If any fragment has changed size, we have to re-layout (and
852  // as a result possibly further relax) all.
853  for (MCSection &Sec : *this)
854  Layout.invalidateFragmentsFrom(&*Sec.begin());
855  }
856 
857  DEBUG_WITH_TYPE("mc-dump", {
858  errs() << "assembler backend - post-relaxation\n--\n";
859  dump(); });
860 
861  // Finalize the layout, including fragment lowering.
862  finishLayout(Layout);
863 
864  DEBUG_WITH_TYPE("mc-dump", {
865  errs() << "assembler backend - final-layout\n--\n";
866  dump(); });
867 
868  // Allow the object writer a chance to perform post-layout binding (for
869  // example, to set the index fields in the symbol data).
870  getWriter().executePostLayoutBinding(*this, Layout);
871 
872  // Evaluate and apply the fixups, generating relocation entries as necessary.
873  for (MCSection &Sec : *this) {
874  for (MCFragment &Frag : Sec) {
876  MutableArrayRef<char> Contents;
877  const MCSubtargetInfo *STI = nullptr;
878 
879  // Process MCAlignFragment and MCEncodedFragmentWithFixups here.
880  switch (Frag.getKind()) {
881  default:
882  continue;
883  case MCFragment::FT_Align: {
884  MCAlignFragment &AF = cast<MCAlignFragment>(Frag);
885  // Insert fixup type for code alignment if the target define
886  // shouldInsertFixupForCodeAlign target hook.
887  if (Sec.UseCodeAlign() && AF.hasEmitNops())
888  getBackend().shouldInsertFixupForCodeAlign(*this, Layout, AF);
889  continue;
890  }
891  case MCFragment::FT_Data: {
892  MCDataFragment &DF = cast<MCDataFragment>(Frag);
893  Fixups = DF.getFixups();
894  Contents = DF.getContents();
895  STI = DF.getSubtargetInfo();
896  assert(!DF.hasInstructions() || STI != nullptr);
897  break;
898  }
900  MCRelaxableFragment &RF = cast<MCRelaxableFragment>(Frag);
901  Fixups = RF.getFixups();
902  Contents = RF.getContents();
903  STI = RF.getSubtargetInfo();
904  assert(!RF.hasInstructions() || STI != nullptr);
905  break;
906  }
908  MCCVDefRangeFragment &CF = cast<MCCVDefRangeFragment>(Frag);
909  Fixups = CF.getFixups();
910  Contents = CF.getContents();
911  break;
912  }
913  case MCFragment::FT_Dwarf: {
914  MCDwarfLineAddrFragment &DF = cast<MCDwarfLineAddrFragment>(Frag);
915  Fixups = DF.getFixups();
916  Contents = DF.getContents();
917  break;
918  }
920  MCDwarfCallFrameFragment &DF = cast<MCDwarfCallFrameFragment>(Frag);
921  Fixups = DF.getFixups();
922  Contents = DF.getContents();
923  break;
924  }
926  MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(Frag);
927  Fixups = PF.getFixups();
928  Contents = PF.getContents();
929  break;
930  }
931  }
932  for (const MCFixup &Fixup : Fixups) {
933  uint64_t FixedValue;
934  bool IsResolved;
935  MCValue Target;
936  std::tie(Target, FixedValue, IsResolved) =
937  handleFixup(Layout, Frag, Fixup);
938  getBackend().applyFixup(*this, Fixup, Target, Contents, FixedValue,
939  IsResolved, STI);
940  }
941  }
942  }
943 }
944 
946  // Create the layout object.
947  MCAsmLayout Layout(*this);
948  layout(Layout);
949 
950  // Write the object file.
951  stats::ObjectBytes += getWriter().writeObject(*this, Layout);
952 }
953 
954 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
955  const MCRelaxableFragment *DF,
956  const MCAsmLayout &Layout) const {
957  assert(getBackendPtr() && "Expected assembler backend");
958  MCValue Target;
959  uint64_t Value;
960  bool WasForced;
961  bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value, WasForced);
962  if (Target.getSymA() &&
963  Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8 &&
964  Fixup.getKind() == FK_Data_1)
965  return false;
966  return getBackend().fixupNeedsRelaxationAdvanced(Fixup, Resolved, Value, DF,
967  Layout, WasForced);
968 }
969 
970 bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
971  const MCAsmLayout &Layout) const {
972  assert(getBackendPtr() && "Expected assembler backend");
973  // If this inst doesn't ever need relaxation, ignore it. This occurs when we
974  // are intentionally pushing out inst fragments, or because we relaxed a
975  // previous instruction to one that doesn't need relaxation.
976  if (!getBackend().mayNeedRelaxation(F->getInst(), *F->getSubtargetInfo()))
977  return false;
978 
979  for (const MCFixup &Fixup : F->getFixups())
980  if (fixupNeedsRelaxation(Fixup, F, Layout))
981  return true;
982 
983  return false;
984 }
985 
986 bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
988  assert(getEmitterPtr() &&
989  "Expected CodeEmitter defined for relaxInstruction");
990  if (!fragmentNeedsRelaxation(&F, Layout))
991  return false;
992 
993  ++stats::RelaxedInstructions;
994 
995  // FIXME-PERF: We could immediately lower out instructions if we can tell
996  // they are fully resolved, to avoid retesting on later passes.
997 
998  // Relax the fragment.
999 
1000  MCInst Relaxed = F.getInst();
1001  getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
1002 
1003  // Encode the new instruction.
1004  //
1005  // FIXME-PERF: If it matters, we could let the target do this. It can
1006  // probably do so more efficiently in many cases.
1009  raw_svector_ostream VecOS(Code);
1010  getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, *F.getSubtargetInfo());
1011 
1012  // Update the fragment.
1013  F.setInst(Relaxed);
1014  F.getContents() = Code;
1015  F.getFixups() = Fixups;
1016 
1017  return true;
1018 }
1019 
1020 bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
1021  uint64_t OldSize = LF.getContents().size();
1022  int64_t Value;
1023  bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout);
1024  if (!Abs)
1025  report_fatal_error("sleb128 and uleb128 expressions must be absolute");
1027  Data.clear();
1029  // The compiler can generate EH table assembly that is impossible to assemble
1030  // without either adding padding to an LEB fragment or adding extra padding
1031  // to a later alignment fragment. To accommodate such tables, relaxation can
1032  // only increase an LEB fragment size here, not decrease it. See PR35809.
1033  if (LF.isSigned())
1034  encodeSLEB128(Value, OSE, OldSize);
1035  else
1036  encodeULEB128(Value, OSE, OldSize);
1037  return OldSize != LF.getContents().size();
1038 }
1039 
1040 /// Check if the branch crosses the boundary.
1041 ///
1042 /// \param StartAddr start address of the fused/unfused branch.
1043 /// \param Size size of the fused/unfused branch.
1044 /// \param BoundaryAlignment alignment requirement of the branch.
1045 /// \returns true if the branch cross the boundary.
1046 static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size,
1047  Align BoundaryAlignment) {
1048  uint64_t EndAddr = StartAddr + Size;
1049  return (StartAddr >> Log2(BoundaryAlignment)) !=
1050  ((EndAddr - 1) >> Log2(BoundaryAlignment));
1051 }
1052 
1053 /// Check if the branch is against the boundary.
1054 ///
1055 /// \param StartAddr start address of the fused/unfused branch.
1056 /// \param Size size of the fused/unfused branch.
1057 /// \param BoundaryAlignment alignment requirement of the branch.
1058 /// \returns true if the branch is against the boundary.
1059 static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size,
1060  Align BoundaryAlignment) {
1061  uint64_t EndAddr = StartAddr + Size;
1062  return (EndAddr & (BoundaryAlignment.value() - 1)) == 0;
1063 }
1064 
1065 /// Check if the branch needs padding.
1066 ///
1067 /// \param StartAddr start address of the fused/unfused branch.
1068 /// \param Size size of the fused/unfused branch.
1069 /// \param BoundaryAlignment alignment requirement of the branch.
1070 /// \returns true if the branch needs padding.
1071 static bool needPadding(uint64_t StartAddr, uint64_t Size,
1072  Align BoundaryAlignment) {
1073  return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) ||
1074  isAgainstBoundary(StartAddr, Size, BoundaryAlignment);
1075 }
1076 
1077 bool MCAssembler::relaxBoundaryAlign(MCAsmLayout &Layout,
1079  // BoundaryAlignFragment that doesn't need to align any fragment should not be
1080  // relaxed.
1081  if (!BF.getLastFragment())
1082  return false;
1083 
1084  uint64_t AlignedOffset = Layout.getFragmentOffset(&BF);
1085  uint64_t AlignedSize = 0;
1086  for (const MCFragment *F = BF.getLastFragment(); F != &BF;
1087  F = F->getPrevNode())
1088  AlignedSize += computeFragmentSize(Layout, *F);
1089 
1090  Align BoundaryAlignment = BF.getAlignment();
1091  uint64_t NewSize = needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
1092  ? offsetToAlignment(AlignedOffset, BoundaryAlignment)
1093  : 0U;
1094  if (NewSize == BF.getSize())
1095  return false;
1096  BF.setSize(NewSize);
1097  Layout.invalidateFragmentsFrom(&BF);
1098  return true;
1099 }
1100 
1101 bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
1103  MCContext &Context = Layout.getAssembler().getContext();
1104  uint64_t OldSize = DF.getContents().size();
1105  int64_t AddrDelta;
1106  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1107  assert(Abs && "We created a line delta with an invalid expression");
1108  (void)Abs;
1109  int64_t LineDelta;
1110  LineDelta = DF.getLineDelta();
1111  SmallVectorImpl<char> &Data = DF.getContents();
1112  Data.clear();
1114  DF.getFixups().clear();
1115 
1116  if (!getBackend().requiresDiffExpressionRelocations()) {
1117  MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta,
1118  AddrDelta, OSE);
1119  } else {
1120  uint32_t Offset;
1121  uint32_t Size;
1122  bool SetDelta;
1123  std::tie(Offset, Size, SetDelta) =
1124  MCDwarfLineAddr::fixedEncode(Context, LineDelta, AddrDelta, OSE);
1125  // Add Fixups for address delta or new address.
1126  const MCExpr *FixupExpr;
1127  if (SetDelta) {
1128  FixupExpr = &DF.getAddrDelta();
1129  } else {
1130  const MCBinaryExpr *ABE = cast<MCBinaryExpr>(&DF.getAddrDelta());
1131  FixupExpr = ABE->getLHS();
1132  }
1133  DF.getFixups().push_back(
1134  MCFixup::create(Offset, FixupExpr,
1135  MCFixup::getKindForSize(Size, false /*isPCRel*/)));
1136  }
1137 
1138  return OldSize != Data.size();
1139 }
1140 
1141 bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
1143  MCContext &Context = Layout.getAssembler().getContext();
1144  uint64_t OldSize = DF.getContents().size();
1145  int64_t AddrDelta;
1146  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1147  assert(Abs && "We created call frame with an invalid expression");
1148  (void) Abs;
1149  SmallVectorImpl<char> &Data = DF.getContents();
1150  Data.clear();
1152  DF.getFixups().clear();
1153 
1154  if (getBackend().requiresDiffExpressionRelocations()) {
1155  uint32_t Offset;
1156  uint32_t Size;
1157  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE, &Offset,
1158  &Size);
1159  if (Size) {
1160  DF.getFixups().push_back(MCFixup::create(
1161  Offset, &DF.getAddrDelta(),
1162  MCFixup::getKindForSizeInBits(Size /*In bits.*/, false /*isPCRel*/)));
1163  }
1164  } else {
1165  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
1166  }
1167 
1168  return OldSize != Data.size();
1169 }
1170 
1171 bool MCAssembler::relaxCVInlineLineTable(MCAsmLayout &Layout,
1173  unsigned OldSize = F.getContents().size();
1175  return OldSize != F.getContents().size();
1176 }
1177 
1178 bool MCAssembler::relaxCVDefRange(MCAsmLayout &Layout,
1180  unsigned OldSize = F.getContents().size();
1181  getContext().getCVContext().encodeDefRange(Layout, F);
1182  return OldSize != F.getContents().size();
1183 }
1184 
1185 bool MCAssembler::relaxPseudoProbeAddr(MCAsmLayout &Layout,
1187  uint64_t OldSize = PF.getContents().size();
1188  int64_t AddrDelta;
1189  bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1190  assert(Abs && "We created a pseudo probe with an invalid expression");
1191  (void)Abs;
1193  Data.clear();
1195  PF.getFixups().clear();
1196 
1197  // Relocations should not be needed in general except on RISC-V which we are
1198  // not targeted for now.
1199  assert(!getBackend().requiresDiffExpressionRelocations() &&
1200  "cannot relax relocations");
1201  // AddrDelta is a signed integer
1202  encodeSLEB128(AddrDelta, OSE, OldSize);
1203  return OldSize != Data.size();
1204 }
1205 
1206 bool MCAssembler::relaxFragment(MCAsmLayout &Layout, MCFragment &F) {
1207  switch(F.getKind()) {
1208  default:
1209  return false;
1211  assert(!getRelaxAll() &&
1212  "Did not expect a MCRelaxableFragment in RelaxAll mode");
1213  return relaxInstruction(Layout, cast<MCRelaxableFragment>(F));
1214  case MCFragment::FT_Dwarf:
1215  return relaxDwarfLineAddr(Layout, cast<MCDwarfLineAddrFragment>(F));
1217  return relaxDwarfCallFrameFragment(Layout,
1218  cast<MCDwarfCallFrameFragment>(F));
1219  case MCFragment::FT_LEB:
1220  return relaxLEB(Layout, cast<MCLEBFragment>(F));
1222  return relaxBoundaryAlign(Layout, cast<MCBoundaryAlignFragment>(F));
1224  return relaxCVInlineLineTable(Layout, cast<MCCVInlineLineTableFragment>(F));
1226  return relaxCVDefRange(Layout, cast<MCCVDefRangeFragment>(F));
1228  return relaxPseudoProbeAddr(Layout, cast<MCPseudoProbeAddrFragment>(F));
1229  }
1230 }
1231 
1232 bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
1233  // Holds the first fragment which needed relaxing during this layout. It will
1234  // remain NULL if none were relaxed.
1235  // When a fragment is relaxed, all the fragments following it should get
1236  // invalidated because their offset is going to change.
1237  MCFragment *FirstRelaxedFragment = nullptr;
1238 
1239  // Attempt to relax all the fragments in the section.
1240  for (MCFragment &Frag : Sec) {
1241  // Check if this is a fragment that needs relaxation.
1242  bool RelaxedFrag = relaxFragment(Layout, Frag);
1243  if (RelaxedFrag && !FirstRelaxedFragment)
1244  FirstRelaxedFragment = &Frag;
1245  }
1246  if (FirstRelaxedFragment) {
1247  Layout.invalidateFragmentsFrom(FirstRelaxedFragment);
1248  return true;
1249  }
1250  return false;
1251 }
1252 
1253 bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
1254  ++stats::RelaxationSteps;
1255 
1256  bool WasRelaxed = false;
1257  for (MCSection &Sec : *this) {
1258  while (layoutSectionOnce(Layout, Sec))
1259  WasRelaxed = true;
1260  }
1261 
1262  return WasRelaxed;
1263 }
1264 
1265 void MCAssembler::finishLayout(MCAsmLayout &Layout) {
1266  assert(getBackendPtr() && "Expected assembler backend");
1267  // The layout is done. Mark every fragment as valid.
1268  for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
1269  MCSection &Section = *Layout.getSectionOrder()[i];
1270  Layout.getFragmentOffset(&*Section.getFragmentList().rbegin());
1271  computeFragmentSize(Layout, *Section.getFragmentList().rbegin());
1272  }
1273  getBackend().finishLayout(*this, Layout);
1274 }
1275 
1276 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1278  raw_ostream &OS = errs();
1279 
1280  OS << "<MCAssembler\n";
1281  OS << " Sections:[\n ";
1282  for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
1283  if (it != begin()) OS << ",\n ";
1284  it->dump();
1285  }
1286  OS << "],\n";
1287  OS << " Symbols:[";
1288 
1289  for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
1290  if (it != symbol_begin()) OS << ",\n ";
1291  OS << "(";
1292  it->dump();
1293  OS << ", Index:" << it->getIndex() << ", ";
1294  OS << ")";
1295  }
1296  OS << "]>\n";
1297 }
1298 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCAssembler::getBackend
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:300
llvm::MCAssembler::begin
iterator begin()
Definition: MCAssembler.h:344
i
i
Definition: README.txt:29
writeFragment
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F)
Write the fragment F to the output file.
Definition: MCAssembler.cpp:508
llvm::MCFragment::FT_DwarfFrame
@ FT_DwarfFrame
Definition: MCFragment.h:44
llvm::raw_ostream::tell
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:132
llvm::MCAlignFragment::hasEmitNops
bool hasEmitNops() const
Definition: MCFragment.h:328
llvm::MCFixup::createSubFor
static MCFixup createSubFor(const MCFixup &Fixup)
Return a fixup corresponding to the sub half of a add/sub fixup pair for the given Fixup.
Definition: MCFixup.h:121
MCDwarf.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:499
MathExtras.h
llvm
Definition: AllocatorList.h:23
llvm::MCFragment::FT_BoundaryAlign
@ FT_BoundaryAlign
Definition: MCFragment.h:46
llvm::MCAssembler::Finish
void Finish()
Finish - Do final processing and write the object to the output stream.
Definition: MCAssembler.cpp:945
llvm::MCRelaxableFragment
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCExpr::evaluateAsValue
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:774
llvm::MCAsmBackend::getFixupKindInfo
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Definition: MCAsmBackend.cpp:74
llvm::MCCVInlineLineTableFragment
Fragment representing the binary annotations produced by the .cv_inline_linetable directive.
Definition: MCFragment.h:503
llvm::MCFixup::getKindForSizeInBits
static MCFixupKind getKindForSizeInBits(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size in bits.
Definition: MCFixup.h:157
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:463
llvm::MCContext::getCVContext
CodeViewContext & getCVContext()
Definition: MCContext.cpp:891
llvm::MCDwarfCallFrameFragment
Definition: MCFragment.h:468
llvm::MCFragment::FT_CVInlineLines
@ FT_CVInlineLines
Definition: MCFragment.h:48
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
StringRef.h
llvm::MCBoundaryAlignFragment::setSize
void setSize(uint64_t Value)
Definition: MCFragment.h:581
MCCodeEmitter.h
it
Reference model for inliner Oz decision policy Note this model is also referenced by test Transforms Inline ML tests if replacing it
Definition: README.txt:3
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:124
llvm::MCFixupKindInfo::FKF_Constant
@ FKF_Constant
This fixup kind should be resolved if defined.
Definition: MCFixupKindInfo.h:30
MCSectionELF.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Statistic.h
llvm::tgtok::Code
@ Code
Definition: TGLexer.h:50
llvm::MCFixup::create
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:97
llvm::MCNopsFragment::getLoc
SMLoc getLoc() const
Definition: MCFragment.h:381
ErrorHandling.h
MCFragment.h
llvm::MCSymbol::isUndefined
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:251
MCAssembler.h
llvm::MCAssembler::computeFragmentSize
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...
Definition: MCAssembler.cpp:289
llvm::MCNopsFragment
Definition: MCFragment.h:363
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:242
llvm::MCAssembler::reset
void reset()
Reuse an assembler instance.
Definition: MCAssembler.cpp:96
mayCrossBoundary
static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch crosses the boundary.
Definition: MCAssembler.cpp:1046
llvm::MCFragment::getParent
MCSection * getParent() const
Definition: MCFragment.h:96
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:732
llvm::MCAsmBackend::applyFixup
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
MCFixupKindInfo.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:183
llvm::MCEncodedFragmentWithFixups::getFixups
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:223
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:479
llvm::MCFixupKindInfo::FKF_IsAlignedDownTo32Bits
@ FKF_IsAlignedDownTo32Bits
Should this fixup kind force a 4-byte aligned effective PC value?
Definition: MCFixupKindInfo.h:22
llvm::MCFragment::FT_CVDefRange
@ FT_CVDefRange
Definition: MCFragment.h:49
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::MCAssembler::writeSectionData
void writeSectionData(raw_ostream &OS, const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents to OS.
Definition: MCAssembler.cpp:722
llvm::MCEncodedFragment::alignToBundleEnd
bool alignToBundleEnd() const
Should this fragment be placed at the end of an aligned bundle?
Definition: MCFragment.h:157
llvm::MCSection::getFragmentList
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:157
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCAssembler::isThumbFunc
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
Definition: MCAssembler.cpp:131
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:766
llvm::MCAsmBackend::finishLayout
virtual void finishLayout(MCAssembler const &Asm, MCAsmLayout &Layout) const
Give backend an opportunity to finish layout after relaxation.
Definition: MCAsmBackend.h:191
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::MCAlignFragment::getMaxBytesToEmit
unsigned getMaxBytesToEmit() const
Definition: MCFragment.h:326
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCBoundaryAlignFragment::getAlignment
Align getAlignment() const
Definition: MCFragment.h:583
llvm::MCAssembler::symbol_begin
symbol_iterator symbol_begin()
Definition: MCAssembler.h:355
DEBUG_WITH_TYPE
#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
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:141
MCAsmBackend.h
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCAsmLayout::invalidateFragmentsFrom
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:70
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::MCAlignFragment
Definition: MCFragment.h:295
SmallString.h
llvm::encodeSLEB128
unsigned 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
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::MCAssembler::getContext
MCContext & getContext() const
Definition: MCAssembler.h:292
llvm::CodeViewContext::encodeDefRange
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
Definition: MCCodeView.cpp:605
llvm::MCLEBFragment::getContents
SmallString< 8 > & getContents()
Definition: MCFragment.h:434
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
Twine.h
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:207
MCContext.h
llvm::MCSymbolIdFragment
Represents a symbol table index fragment.
Definition: MCFragment.h:486
llvm::MCSection::setLayoutOrder
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:138
MCSymbol.h
llvm::MCLOHContainer::reset
void reset()
Definition: MCLinkerOptimizationHint.h:176
MCInst.h
false
Definition: StackSlotColoring.cpp:142
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:220
llvm::report_fatal_error
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:140
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::MCOrgFragment::getLoc
SMLoc getLoc() const
Definition: MCFragment.h:408
llvm::MCAsmLayout::layoutFragment
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
Definition: MCAssembler.cpp:395
llvm::VersionTuple
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:27
llvm::MCExpr::evaluateKnownAbsolute
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Definition: MCExpr.cpp:557
llvm::MCObjectWriter::recordRelocation
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
llvm::MCAssembler::getEmitterPtr
MCCodeEmitter * getEmitterPtr() const
Definition: MCAssembler.h:296
llvm::MCAsmBackend::reset
virtual void reset()
lifetime management
Definition: MCAsmBackend.h:62
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MCFragment::hasInstructions
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:107
llvm::MCFixupKindInfo::Flags
unsigned Flags
Flags describing additional information on this fixup kind.
Definition: MCFixupKindInfo.h:45
llvm::MCFixup::createAddFor
static MCFixup createAddFor(const MCFixup &Fixup)
Return a fixup corresponding to the add half of a add/sub fixup pair for the given Fixup.
Definition: MCFixup.h:110
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::MCSymbol::getIndex
uint32_t getIndex() const
Get the (implementation defined) index.
Definition: MCSymbol.h:306
llvm::SmallString< 256 >
llvm::MCDwarfLineAddr::Encode
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:655
llvm::MCDwarfLineAddrFragment
Definition: MCFragment.h:444
llvm::MCAsmLayout::getSectionOrder
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:69
llvm::MCAsmLayout::getSectionFileSize
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:200
llvm::MCFragment::FT_LEB
@ FT_LEB
Definition: MCFragment.h:45
llvm::MCAssembler::getWriterPtr
MCObjectWriter * getWriterPtr() const
Definition: MCAssembler.h:298
llvm::MCEncodedFragment
Interface implemented by fragments that contain encoded instructions and/or data.
Definition: MCFragment.h:125
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCAssembler::getEmitter
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:302
llvm::MCAlignFragment::getValueSize
unsigned getValueSize() const
Definition: MCFragment.h:324
index
splat index
Definition: README_ALTIVEC.txt:181
llvm::MCPseudoProbeAddrFragment
Definition: MCFragment.h:597
llvm::MCFragment::FT_Org
@ FT_Org
Definition: MCFragment.h:42
llvm::MCValue::get
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:60
llvm::CodeViewContext::encodeInlineLineTable
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
Definition: MCCodeView.cpp:461
LEB128.h
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::MCEncodedFragment::setBundlePadding
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCFragment.h:169
llvm::MCFixupKindInfo::FKF_IsPCRel
@ FKF_IsPCRel
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
Definition: MCFixupKindInfo.h:19
llvm::MCAssembler::symbol_end
symbol_iterator symbol_end()
Definition: MCAssembler.h:358
llvm::MCAssembler::getBundleAlignSize
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:333
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MCBoundaryAlignFragment::getLastFragment
const MCFragment * getLastFragment() const
Definition: MCFragment.h:586
llvm::MCAssembler::isSymbolLinkerVisible
bool isSymbolLinkerVisible(const MCSymbol &SD) const
Check whether a particular symbol is visible to the linker and is required in the symbol table,...
Definition: MCAssembler.cpp:162
llvm::MCAssembler::MCAssembler
MCAssembler(MCContext &Context, std::unique_ptr< MCAsmBackend > Backend, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCObjectWriter > Writer)
Construct a new assembler instance.
Definition: MCAssembler.cpp:83
ArrayRef.h
llvm::MCAsmBackend::shouldInsertFixupForCodeAlign
virtual bool shouldInsertFixupForCodeAlign(MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF)
Hook which indicates if the target requires a fixup to be generated when handling an align directive ...
Definition: MCAsmBackend.h:107
llvm::MCAssembler::getAtom
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...
Definition: MCAssembler.cpp:173
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:1540
llvm::MCFillFragment
Definition: MCFragment.h:336
llvm::MCAsmBackend::fixupNeedsRelaxationAdvanced
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout, const bool WasForced) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
Definition: MCAsmBackend.cpp:113
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:946
llvm::MCFragment::FT_SymbolId
@ FT_SymbolId
Definition: MCFragment.h:47
llvm::MCAssembler::getRelaxAll
bool getRelaxAll() const
Definition: MCAssembler.h:328
llvm::MCFragment::FT_PseudoProbe
@ FT_PseudoProbe
Definition: MCFragment.h:50
llvm::MCAssembler::~MCAssembler
~MCAssembler()
llvm::FK_Data_1
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
llvm::MCPseudoProbeAddrFragment::getAddrDelta
const MCExpr & getAddrDelta() const
Definition: MCFragment.h:607
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::MCOrgFragment
Definition: MCFragment.h:388
llvm::MCFragment::FT_Align
@ FT_Align
Definition: MCFragment.h:36
llvm::MCFixupKindInfo::FKF_IsTarget
@ FKF_IsTarget
Should this fixup be evaluated in a target dependent manner?
Definition: MCFixupKindInfo.h:25
MCSection.h
llvm::MCSymbolRefExpr::VK_X86_ABS8
@ VK_X86_ABS8
Definition: MCExpr.h:226
llvm::MCFillFragment::getValue
uint64_t getValue() const
Definition: MCFragment.h:352
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
MCAsmInfo.h
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MCSection::isVirtualSection
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCLEBFragment::getValue
const MCExpr & getValue() const
Definition: MCFragment.h:430
llvm::MCFragment::FT_Data
@ FT_Data
Definition: MCFragment.h:37
llvm::MCAlignFragment::getValue
int64_t getValue() const
Definition: MCFragment.h:322
uint32_t
MCFixup.h
llvm::MCBoundaryAlignFragment::getSize
uint64_t getSize() const
Definition: MCFragment.h:580
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:169
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::MCSymbolIdFragment::getSymbol
const MCSymbol * getSymbol()
Definition: MCFragment.h:493
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::MCOrgFragment::getValue
uint8_t getValue() const
Definition: MCFragment.h:406
llvm::MCAsmLayout::getFragmentOffset
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Definition: MCFragment.cpp:96
MCAsmLayout.h
MCObjectWriter.h
llvm::MCFragment::FT_Dwarf
@ FT_Dwarf
Definition: MCFragment.h:43
llvm::MCAssembler::layout
void layout(MCAsmLayout &Layout)
Definition: MCAssembler.cpp:819
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
needPadding
static bool needPadding(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch needs padding.
Definition: MCAssembler.cpp:1071
Alignment.h
stats
Definition: MCAssembler.cpp:52
llvm::MCCodeEmitter::reset
virtual void reset()
Lifetime management.
Definition: MCCodeEmitter.h:31
MCCodeView.h
std
Definition: BitVector.h:838
EndianStream.h
llvm::MCObjectWriter::reset
virtual void reset()
lifetime management
Definition: MCObjectWriter.h:43
llvm::MCFragment::FT_Nops
@ FT_Nops
Definition: MCFragment.h:40
llvm::MCAsmBackend::evaluateTargetFixup
virtual bool evaluateTargetFixup(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, uint64_t &Value, bool &WasForced)
Definition: MCAsmBackend.h:113
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
isAgainstBoundary
static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch is against the boundary.
Definition: MCAssembler.cpp:1059
llvm::MCObjectWriter::executePostLayoutBinding
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...
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::MCAssembler::getLOHContainer
MCLOHContainer & getLOHContainer()
Definition: MCAssembler.h:431
llvm::MCEncodedFragment::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition: MCFragment.h:173
Casting.h
llvm::MCNopsFragment::getNumBytes
int64_t getNumBytes() const
Definition: MCFragment.h:378
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MCValue::getRefKind
uint32_t getRefKind() const
Definition: MCValue.h:47
llvm::MCAsmLayout::getSymbolOffset
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:148
llvm::MCEncodedFragment::getBundlePadding
uint8_t getBundlePadding() const
Get the padding size that must be inserted before this fragment.
Definition: MCFragment.h:165
llvm::MCAlignFragment::getAlignment
unsigned getAlignment() const
Definition: MCFragment.h:320
llvm::MCObjectWriter::writeObject
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
MCValue.h
llvm::MCFragment::FT_Relaxable
@ FT_Relaxable
Definition: MCFragment.h:41
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCAssembler::registerSection
bool registerSection(MCSection &Section)
Definition: MCAssembler.cpp:123
llvm::MCAssembler::end
iterator end()
Definition: MCAssembler.h:347
llvm::MCSection::begin
iterator begin()
Definition: MCSection.h:170
llvm::MCLEBFragment
Definition: MCFragment.h:415
llvm::computeBundlePadding
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCEncodedFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions,...
Definition: MCFragment.cpp:209
llvm::MCFragment::FT_Fill
@ FT_Fill
Definition: MCFragment.h:39
SmallVector.h
llvm::MCSection::UseCodeAlign
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
llvm::MCDwarfFrameEmitter::EncodeAdvanceLoc
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS, uint32_t *Offset=nullptr, uint32_t *Size=nullptr)
Definition: MCDwarf.cpp:1929
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:62
llvm::MCAssembler::dump
void dump() const
Definition: MCAssembler.cpp:1277
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:647
llvm::encodeULEB128
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::SmallVectorImpl< char >
llvm::MCAssembler::writeFragmentPadding
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
Definition: MCAssembler.cpp:473
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCFillFragment::getValueSize
uint8_t getValueSize() const
Definition: MCFragment.h:353
llvm::MCAsmLayout::getAssembler
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:50
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::MCAssembler::getBackendPtr
MCAsmBackend * getBackendPtr() const
Definition: MCAssembler.h:294
llvm::MCFragment::FT_Dummy
@ FT_Dummy
Definition: MCFragment.h:51
llvm::pointee_iterator
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:296
llvm::MCContext::hadError
bool hadError()
Definition: MCContext.h:803
llvm::MCAsmLayout::getSectionAddressSize
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:194
llvm::MCAssembler::getDWARFLinetableParams
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:306
raw_ostream.h
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
llvm::MCAssembler::isBundlingEnabled
bool isBundlingEnabled() const
Definition: MCAssembler.h:331
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:81
llvm::MCCVDefRangeFragment
Fragment representing the .cv_def_range directive.
Definition: MCFragment.h:536
llvm::offsetToAlignment
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition: Alignment.h:196
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::MCOrgFragment::getOffset
const MCExpr & getOffset() const
Definition: MCFragment.h:404
llvm::MCLEBFragment::isSigned
bool isSigned() const
Definition: MCFragment.h:432
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::MCDwarfLineAddr::fixedEncode
static std::tuple< uint32_t, uint32_t, bool > fixedEncode(MCContext &Context, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas using fixed length operands.
Definition: MCDwarf.cpp:738
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
llvm::MCEncodedFragmentWithContents::getContents
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:197
llvm::MCFragment::FT_CompactEncodedInst
@ FT_CompactEncodedInst
Definition: MCFragment.h:38
llvm::MCNopsFragment::getControlledNopLength
int64_t getControlledNopLength() const
Definition: MCFragment.h:379
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::MCBinaryExpr::getLHS
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:626
llvm::MCSection::setOrdinal
void setOrdinal(unsigned Value)
Definition: MCSection.h:135
llvm::MCBoundaryAlignFragment
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition: MCFragment.h:566
llvm::MCAssembler::getWriter
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:304