[Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
[oota-llvm.git] / lib / MC / MCAssembler.cpp
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/Statistic.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCAsmLayout.h"
16 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCDwarf.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCFixupKindInfo.h"
21 #include "llvm/MC/MCObjectWriter.h"
22 #include "llvm/MC/MCSection.h"
23 #include "llvm/MC/MCSymbol.h"
24 #include "llvm/MC/MCValue.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/LEB128.h"
28 #include "llvm/Support/TargetRegistry.h"
29 #include "llvm/Support/raw_ostream.h"
30
31 using namespace llvm;
32
33 #define DEBUG_TYPE "assembler"
34
35 namespace {
36 namespace stats {
37 STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
38 STATISTIC(EmittedRelaxableFragments,
39           "Number of emitted assembler fragments - relaxable");
40 STATISTIC(EmittedDataFragments,
41           "Number of emitted assembler fragments - data");
42 STATISTIC(EmittedCompactEncodedInstFragments,
43           "Number of emitted assembler fragments - compact encoded inst");
44 STATISTIC(EmittedAlignFragments,
45           "Number of emitted assembler fragments - align");
46 STATISTIC(EmittedFillFragments,
47           "Number of emitted assembler fragments - fill");
48 STATISTIC(EmittedOrgFragments,
49           "Number of emitted assembler fragments - org");
50 STATISTIC(evaluateFixup, "Number of evaluated fixups");
51 STATISTIC(FragmentLayouts, "Number of fragment layouts");
52 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
53 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
54 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
55 }
56 }
57
58 // FIXME FIXME FIXME: There are number of places in this file where we convert
59 // what is a 64-bit assembler value used for computation into a value in the
60 // object file, which may truncate it. We should detect that truncation where
61 // invalid and report errors back.
62
63 /* *** */
64
65 MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
66   : Assembler(Asm), LastValidFragment()
67  {
68   // Compute the section layout order. Virtual sections must go last.
69   for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
70     if (!it->getSection().isVirtualSection())
71       SectionOrder.push_back(&*it);
72   for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
73     if (it->getSection().isVirtualSection())
74       SectionOrder.push_back(&*it);
75 }
76
77 bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
78   const MCSectionData &SD = *F->getParent();
79   const MCFragment *LastValid = LastValidFragment.lookup(&SD);
80   if (!LastValid)
81     return false;
82   assert(LastValid->getParent() == F->getParent());
83   return F->getLayoutOrder() <= LastValid->getLayoutOrder();
84 }
85
86 void MCAsmLayout::invalidateFragmentsFrom(MCFragment *F) {
87   // If this fragment wasn't already valid, we don't need to do anything.
88   if (!isFragmentValid(F))
89     return;
90
91   // Otherwise, reset the last valid fragment to the previous fragment
92   // (if this is the first fragment, it will be NULL).
93   const MCSectionData &SD = *F->getParent();
94   LastValidFragment[&SD] = F->getPrevNode();
95 }
96
97 void MCAsmLayout::ensureValid(const MCFragment *F) const {
98   MCSectionData &SD = *F->getParent();
99
100   MCFragment *Cur = LastValidFragment[&SD];
101   if (!Cur)
102     Cur = &*SD.begin();
103   else
104     Cur = Cur->getNextNode();
105
106   // Advance the layout position until the fragment is valid.
107   while (!isFragmentValid(F)) {
108     assert(Cur && "Layout bookkeeping error");
109     const_cast<MCAsmLayout*>(this)->layoutFragment(Cur);
110     Cur = Cur->getNextNode();
111   }
112 }
113
114 uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
115   ensureValid(F);
116   assert(F->Offset != ~UINT64_C(0) && "Address not set!");
117   return F->Offset;
118 }
119
120 uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const {
121   const MCSymbol &S = SD->getSymbol();
122
123   // If this is a variable, then recursively evaluate now.
124   if (S.isVariable()) {
125     MCValue Target;
126     if (!S.getVariableValue()->EvaluateAsRelocatable(Target, this))
127       report_fatal_error("unable to evaluate offset for variable '" +
128                          S.getName() + "'");
129
130     // Verify that any used symbols are defined.
131     if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined())
132       report_fatal_error("unable to evaluate offset to undefined symbol '" +
133                          Target.getSymA()->getSymbol().getName() + "'");
134     if (Target.getSymB() && Target.getSymB()->getSymbol().isUndefined())
135       report_fatal_error("unable to evaluate offset to undefined symbol '" +
136                          Target.getSymB()->getSymbol().getName() + "'");
137
138     uint64_t Offset = Target.getConstant();
139     if (Target.getSymA())
140       Offset += getSymbolOffset(&Assembler.getSymbolData(
141                                   Target.getSymA()->getSymbol()));
142     if (Target.getSymB())
143       Offset -= getSymbolOffset(&Assembler.getSymbolData(
144                                   Target.getSymB()->getSymbol()));
145     return Offset;
146   }
147
148   assert(SD->getFragment() && "Invalid getOffset() on undefined symbol!");
149   return getFragmentOffset(SD->getFragment()) + SD->getOffset();
150 }
151
152 uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
153   // The size is the last fragment's end offset.
154   const MCFragment &F = SD->getFragmentList().back();
155   return getFragmentOffset(&F) + getAssembler().computeFragmentSize(*this, F);
156 }
157
158 uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
159   // Virtual sections have no file size.
160   if (SD->getSection().isVirtualSection())
161     return 0;
162
163   // Otherwise, the file size is the same as the address space size.
164   return getSectionAddressSize(SD);
165 }
166
167 uint64_t MCAsmLayout::computeBundlePadding(const MCFragment *F,
168                                            uint64_t FOffset, uint64_t FSize) {
169   uint64_t BundleSize = Assembler.getBundleAlignSize();
170   assert(BundleSize > 0 &&
171          "computeBundlePadding should only be called if bundling is enabled");
172   uint64_t BundleMask = BundleSize - 1;
173   uint64_t OffsetInBundle = FOffset & BundleMask;
174   uint64_t EndOfFragment = OffsetInBundle + FSize;
175
176   // There are two kinds of bundling restrictions:
177   //
178   // 1) For alignToBundleEnd(), add padding to ensure that the fragment will
179   //    *end* on a bundle boundary.
180   // 2) Otherwise, check if the fragment would cross a bundle boundary. If it
181   //    would, add padding until the end of the bundle so that the fragment
182   //    will start in a new one.
183   if (F->alignToBundleEnd()) {
184     // Three possibilities here:
185     //
186     // A) The fragment just happens to end at a bundle boundary, so we're good.
187     // B) The fragment ends before the current bundle boundary: pad it just
188     //    enough to reach the boundary.
189     // C) The fragment ends after the current bundle boundary: pad it until it
190     //    reaches the end of the next bundle boundary.
191     //
192     // Note: this code could be made shorter with some modulo trickery, but it's
193     // intentionally kept in its more explicit form for simplicity.
194     if (EndOfFragment == BundleSize)
195       return 0;
196     else if (EndOfFragment < BundleSize)
197       return BundleSize - EndOfFragment;
198     else { // EndOfFragment > BundleSize
199       return 2 * BundleSize - EndOfFragment;
200     }
201   } else if (EndOfFragment > BundleSize)
202     return BundleSize - OffsetInBundle;
203   else
204     return 0;
205 }
206
207 /* *** */
208
209 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
210 }
211
212 MCFragment::~MCFragment() {
213 }
214
215 MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent)
216   : Kind(_Kind), Parent(_Parent), Atom(nullptr), Offset(~UINT64_C(0))
217 {
218   if (Parent)
219     Parent->getFragmentList().push_back(this);
220 }
221
222 /* *** */
223
224 MCEncodedFragment::~MCEncodedFragment() {
225 }
226
227 /* *** */
228
229 MCEncodedFragmentWithFixups::~MCEncodedFragmentWithFixups() {
230 }
231
232 /* *** */
233
234 MCSectionData::MCSectionData() : Section(nullptr) {}
235
236 MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
237   : Section(&_Section),
238     Ordinal(~UINT32_C(0)),
239     Alignment(1),
240     BundleLockState(NotBundleLocked), BundleGroupBeforeFirstInst(false),
241     HasInstructions(false)
242 {
243   if (A)
244     A->getSectionList().push_back(this);
245 }
246
247 MCSectionData::iterator
248 MCSectionData::getSubsectionInsertionPoint(unsigned Subsection) {
249   if (Subsection == 0 && SubsectionFragmentMap.empty())
250     return end();
251
252   SmallVectorImpl<std::pair<unsigned, MCFragment *> >::iterator MI =
253     std::lower_bound(SubsectionFragmentMap.begin(), SubsectionFragmentMap.end(),
254                      std::make_pair(Subsection, (MCFragment *)nullptr));
255   bool ExactMatch = false;
256   if (MI != SubsectionFragmentMap.end()) {
257     ExactMatch = MI->first == Subsection;
258     if (ExactMatch)
259       ++MI;
260   }
261   iterator IP;
262   if (MI == SubsectionFragmentMap.end())
263     IP = end();
264   else
265     IP = MI->second;
266   if (!ExactMatch && Subsection != 0) {
267     // The GNU as documentation claims that subsections have an alignment of 4,
268     // although this appears not to be the case.
269     MCFragment *F = new MCDataFragment();
270     SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
271     getFragmentList().insert(IP, F);
272     F->setParent(this);
273   }
274   return IP;
275 }
276
277 /* *** */
278
279 MCSymbolData::MCSymbolData() : Symbol(nullptr) {}
280
281 MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
282                            uint64_t _Offset, MCAssembler *A)
283   : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
284     IsExternal(false), IsPrivateExtern(false),
285     CommonSize(0), SymbolSize(nullptr), CommonAlign(0),
286     Flags(0), Index(0)
287 {
288   if (A)
289     A->getSymbolList().push_back(this);
290 }
291
292 /* *** */
293
294 MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
295                          MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
296                          raw_ostream &OS_)
297   : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_),
298     OS(OS_), BundleAlignSize(0), RelaxAll(false), NoExecStack(false),
299     SubsectionsViaSymbols(false), ELFHeaderEFlags(0) {
300   VersionMinInfo.Major = 0; // Major version == 0 for "none specified"
301 }
302
303 MCAssembler::~MCAssembler() {
304 }
305
306 void MCAssembler::reset() {
307   Sections.clear();
308   Symbols.clear();
309   SectionMap.clear();
310   SymbolMap.clear();
311   IndirectSymbols.clear();
312   DataRegions.clear();
313   ThumbFuncs.clear();
314   RelaxAll = false;
315   NoExecStack = false;
316   SubsectionsViaSymbols = false;
317   ELFHeaderEFlags = 0;
318
319   // reset objects owned by us
320   getBackend().reset();
321   getEmitter().reset();
322   getWriter().reset();
323   getLOHContainer().reset();
324 }
325
326 bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
327   // Non-temporary labels should always be visible to the linker.
328   if (!Symbol.isTemporary())
329     return true;
330
331   // Absolute temporary labels are never visible.
332   if (!Symbol.isInSection())
333     return false;
334
335   // Otherwise, check if the section requires symbols even for temporary labels.
336   return getBackend().doesSectionRequireSymbols(Symbol.getSection());
337 }
338
339 const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
340   // Linker visible symbols define atoms.
341   if (isSymbolLinkerVisible(SD->getSymbol()))
342     return SD;
343
344   // Absolute and undefined symbols have no defining atom.
345   if (!SD->getFragment())
346     return nullptr;
347
348   // Non-linker visible symbols in sections which can't be atomized have no
349   // defining atom.
350   if (!getBackend().isSectionAtomizable(
351         SD->getFragment()->getParent()->getSection()))
352     return nullptr;
353
354   // Otherwise, return the atom for the containing fragment.
355   return SD->getFragment()->getAtom();
356 }
357
358 bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
359                                 const MCFixup &Fixup, const MCFragment *DF,
360                                 MCValue &Target, uint64_t &Value) const {
361   ++stats::evaluateFixup;
362
363   if (!Fixup.getValue()->EvaluateAsRelocatable(Target, &Layout))
364     getContext().FatalError(Fixup.getLoc(), "expected relocatable expression");
365
366   bool IsPCRel = Backend.getFixupKindInfo(
367     Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
368
369   bool IsResolved;
370   if (IsPCRel) {
371     if (Target.getSymB()) {
372       IsResolved = false;
373     } else if (!Target.getSymA()) {
374       IsResolved = false;
375     } else {
376       const MCSymbolRefExpr *A = Target.getSymA();
377       const MCSymbol &SA = A->getSymbol();
378       if (A->getKind() != MCSymbolRefExpr::VK_None ||
379           SA.AliasedSymbol().isUndefined()) {
380         IsResolved = false;
381       } else {
382         const MCSymbolData &DataA = getSymbolData(SA);
383         IsResolved =
384           getWriter().IsSymbolRefDifferenceFullyResolvedImpl(*this, DataA,
385                                                              *DF, false, true);
386       }
387     }
388   } else {
389     IsResolved = Target.isAbsolute();
390   }
391
392   Value = Target.getConstant();
393
394   if (const MCSymbolRefExpr *A = Target.getSymA()) {
395     const MCSymbol &Sym = A->getSymbol().AliasedSymbol();
396     if (Sym.isDefined())
397       Value += Layout.getSymbolOffset(&getSymbolData(Sym));
398   }
399   if (const MCSymbolRefExpr *B = Target.getSymB()) {
400     const MCSymbol &Sym = B->getSymbol().AliasedSymbol();
401     if (Sym.isDefined())
402       Value -= Layout.getSymbolOffset(&getSymbolData(Sym));
403   }
404
405
406   bool ShouldAlignPC = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
407                          MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
408   assert((ShouldAlignPC ? IsPCRel : true) &&
409     "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
410
411   if (IsPCRel) {
412     uint32_t Offset = Layout.getFragmentOffset(DF) + Fixup.getOffset();
413
414     // A number of ARM fixups in Thumb mode require that the effective PC
415     // address be determined as the 32-bit aligned version of the actual offset.
416     if (ShouldAlignPC) Offset &= ~0x3;
417     Value -= Offset;
418   }
419
420   // Let the backend adjust the fixup value if necessary, including whether
421   // we need a relocation.
422   Backend.processFixupValue(*this, Layout, Fixup, DF, Target, Value,
423                             IsResolved);
424
425   return IsResolved;
426 }
427
428 uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
429                                           const MCFragment &F) const {
430   switch (F.getKind()) {
431   case MCFragment::FT_Data:
432   case MCFragment::FT_Relaxable:
433   case MCFragment::FT_CompactEncodedInst:
434     return cast<MCEncodedFragment>(F).getContents().size();
435   case MCFragment::FT_Fill:
436     return cast<MCFillFragment>(F).getSize();
437
438   case MCFragment::FT_LEB:
439     return cast<MCLEBFragment>(F).getContents().size();
440
441   case MCFragment::FT_Align: {
442     const MCAlignFragment &AF = cast<MCAlignFragment>(F);
443     unsigned Offset = Layout.getFragmentOffset(&AF);
444     unsigned Size = OffsetToAlignment(Offset, AF.getAlignment());
445     // If we are padding with nops, force the padding to be larger than the
446     // minimum nop size.
447     if (Size > 0 && AF.hasEmitNops()) {
448       while (Size % getBackend().getMinimumNopSize())
449         Size += AF.getAlignment();
450     }
451     if (Size > AF.getMaxBytesToEmit())
452       return 0;
453     return Size;
454   }
455
456   case MCFragment::FT_Org: {
457     const MCOrgFragment &OF = cast<MCOrgFragment>(F);
458     int64_t TargetLocation;
459     if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, Layout))
460       report_fatal_error("expected assembly-time absolute expression");
461
462     // FIXME: We need a way to communicate this error.
463     uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
464     int64_t Size = TargetLocation - FragmentOffset;
465     if (Size < 0 || Size >= 0x40000000)
466       report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +
467                          "' (at offset '" + Twine(FragmentOffset) + "')");
468     return Size;
469   }
470
471   case MCFragment::FT_Dwarf:
472     return cast<MCDwarfLineAddrFragment>(F).getContents().size();
473   case MCFragment::FT_DwarfFrame:
474     return cast<MCDwarfCallFrameFragment>(F).getContents().size();
475   }
476
477   llvm_unreachable("invalid fragment kind");
478 }
479
480 void MCAsmLayout::layoutFragment(MCFragment *F) {
481   MCFragment *Prev = F->getPrevNode();
482
483   // We should never try to recompute something which is valid.
484   assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
485   // We should never try to compute the fragment layout if its predecessor
486   // isn't valid.
487   assert((!Prev || isFragmentValid(Prev)) &&
488          "Attempt to compute fragment before its predecessor!");
489
490   ++stats::FragmentLayouts;
491
492   // Compute fragment offset and size.
493   if (Prev)
494     F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
495   else
496     F->Offset = 0;
497   LastValidFragment[F->getParent()] = F;
498
499   // If bundling is enabled and this fragment has instructions in it, it has to
500   // obey the bundling restrictions. With padding, we'll have:
501   //
502   //
503   //        BundlePadding
504   //             |||
505   // -------------------------------------
506   //   Prev  |##########|       F        |
507   // -------------------------------------
508   //                    ^
509   //                    |
510   //                    F->Offset
511   //
512   // The fragment's offset will point to after the padding, and its computed
513   // size won't include the padding.
514   //
515   if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
516     assert(isa<MCEncodedFragment>(F) &&
517            "Only MCEncodedFragment implementations have instructions");
518     uint64_t FSize = Assembler.computeFragmentSize(*this, *F);
519
520     if (FSize > Assembler.getBundleAlignSize())
521       report_fatal_error("Fragment can't be larger than a bundle size");
522
523     uint64_t RequiredBundlePadding = computeBundlePadding(F, F->Offset, FSize);
524     if (RequiredBundlePadding > UINT8_MAX)
525       report_fatal_error("Padding cannot exceed 255 bytes");
526     F->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
527     F->Offset += RequiredBundlePadding;
528   }
529 }
530
531 /// \brief Write the contents of a fragment to the given object writer. Expects
532 ///        a MCEncodedFragment.
533 static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) {
534   const MCEncodedFragment &EF = cast<MCEncodedFragment>(F);
535   OW->WriteBytes(EF.getContents());
536 }
537
538 /// \brief Write the fragment \p F to the output file.
539 static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
540                           const MCFragment &F) {
541   MCObjectWriter *OW = &Asm.getWriter();
542
543   // FIXME: Embed in fragments instead?
544   uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
545
546   // Should NOP padding be written out before this fragment?
547   unsigned BundlePadding = F.getBundlePadding();
548   if (BundlePadding > 0) {
549     assert(Asm.isBundlingEnabled() &&
550            "Writing bundle padding with disabled bundling");
551     assert(F.hasInstructions() &&
552            "Writing bundle padding for a fragment without instructions");
553
554     unsigned TotalLength = BundlePadding + static_cast<unsigned>(FragmentSize);
555     if (F.alignToBundleEnd() && TotalLength > Asm.getBundleAlignSize()) {
556       // If the padding itself crosses a bundle boundary, it must be emitted
557       // in 2 pieces, since even nop instructions must not cross boundaries.
558       //             v--------------v   <- BundleAlignSize
559       //        v---------v             <- BundlePadding
560       // ----------------------------
561       // | Prev |####|####|    F    |
562       // ----------------------------
563       //        ^-------------------^   <- TotalLength
564       unsigned DistanceToBoundary = TotalLength - Asm.getBundleAlignSize();
565       if (!Asm.getBackend().writeNopData(DistanceToBoundary, OW))
566           report_fatal_error("unable to write NOP sequence of " +
567                              Twine(DistanceToBoundary) + " bytes");
568       BundlePadding -= DistanceToBoundary;
569     }
570     if (!Asm.getBackend().writeNopData(BundlePadding, OW))
571       report_fatal_error("unable to write NOP sequence of " +
572                          Twine(BundlePadding) + " bytes");
573   }
574
575   // This variable (and its dummy usage) is to participate in the assert at
576   // the end of the function.
577   uint64_t Start = OW->getStream().tell();
578   (void) Start;
579
580   ++stats::EmittedFragments;
581
582   switch (F.getKind()) {
583   case MCFragment::FT_Align: {
584     ++stats::EmittedAlignFragments;
585     const MCAlignFragment &AF = cast<MCAlignFragment>(F);
586     assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
587
588     uint64_t Count = FragmentSize / AF.getValueSize();
589
590     // FIXME: This error shouldn't actually occur (the front end should emit
591     // multiple .align directives to enforce the semantics it wants), but is
592     // severe enough that we want to report it. How to handle this?
593     if (Count * AF.getValueSize() != FragmentSize)
594       report_fatal_error("undefined .align directive, value size '" +
595                         Twine(AF.getValueSize()) +
596                         "' is not a divisor of padding size '" +
597                         Twine(FragmentSize) + "'");
598
599     // See if we are aligning with nops, and if so do that first to try to fill
600     // the Count bytes.  Then if that did not fill any bytes or there are any
601     // bytes left to fill use the Value and ValueSize to fill the rest.
602     // If we are aligning with nops, ask that target to emit the right data.
603     if (AF.hasEmitNops()) {
604       if (!Asm.getBackend().writeNopData(Count, OW))
605         report_fatal_error("unable to write nop sequence of " +
606                           Twine(Count) + " bytes");
607       break;
608     }
609
610     // Otherwise, write out in multiples of the value size.
611     for (uint64_t i = 0; i != Count; ++i) {
612       switch (AF.getValueSize()) {
613       default: llvm_unreachable("Invalid size!");
614       case 1: OW->Write8 (uint8_t (AF.getValue())); break;
615       case 2: OW->Write16(uint16_t(AF.getValue())); break;
616       case 4: OW->Write32(uint32_t(AF.getValue())); break;
617       case 8: OW->Write64(uint64_t(AF.getValue())); break;
618       }
619     }
620     break;
621   }
622
623   case MCFragment::FT_Data: 
624     ++stats::EmittedDataFragments;
625     writeFragmentContents(F, OW);
626     break;
627
628   case MCFragment::FT_Relaxable:
629     ++stats::EmittedRelaxableFragments;
630     writeFragmentContents(F, OW);
631     break;
632
633   case MCFragment::FT_CompactEncodedInst:
634     ++stats::EmittedCompactEncodedInstFragments;
635     writeFragmentContents(F, OW);
636     break;
637
638   case MCFragment::FT_Fill: {
639     ++stats::EmittedFillFragments;
640     const MCFillFragment &FF = cast<MCFillFragment>(F);
641
642     assert(FF.getValueSize() && "Invalid virtual align in concrete fragment!");
643
644     for (uint64_t i = 0, e = FF.getSize() / FF.getValueSize(); i != e; ++i) {
645       switch (FF.getValueSize()) {
646       default: llvm_unreachable("Invalid size!");
647       case 1: OW->Write8 (uint8_t (FF.getValue())); break;
648       case 2: OW->Write16(uint16_t(FF.getValue())); break;
649       case 4: OW->Write32(uint32_t(FF.getValue())); break;
650       case 8: OW->Write64(uint64_t(FF.getValue())); break;
651       }
652     }
653     break;
654   }
655
656   case MCFragment::FT_LEB: {
657     const MCLEBFragment &LF = cast<MCLEBFragment>(F);
658     OW->WriteBytes(LF.getContents().str());
659     break;
660   }
661
662   case MCFragment::FT_Org: {
663     ++stats::EmittedOrgFragments;
664     const MCOrgFragment &OF = cast<MCOrgFragment>(F);
665
666     for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
667       OW->Write8(uint8_t(OF.getValue()));
668
669     break;
670   }
671
672   case MCFragment::FT_Dwarf: {
673     const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
674     OW->WriteBytes(OF.getContents().str());
675     break;
676   }
677   case MCFragment::FT_DwarfFrame: {
678     const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
679     OW->WriteBytes(CF.getContents().str());
680     break;
681   }
682   }
683
684   assert(OW->getStream().tell() - Start == FragmentSize &&
685          "The stream should advance by fragment size");
686 }
687
688 void MCAssembler::writeSectionData(const MCSectionData *SD,
689                                    const MCAsmLayout &Layout) const {
690   // Ignore virtual sections.
691   if (SD->getSection().isVirtualSection()) {
692     assert(Layout.getSectionFileSize(SD) == 0 && "Invalid size for section!");
693
694     // Check that contents are only things legal inside a virtual section.
695     for (MCSectionData::const_iterator it = SD->begin(),
696            ie = SD->end(); it != ie; ++it) {
697       switch (it->getKind()) {
698       default: llvm_unreachable("Invalid fragment in virtual section!");
699       case MCFragment::FT_Data: {
700         // Check that we aren't trying to write a non-zero contents (or fixups)
701         // into a virtual section. This is to support clients which use standard
702         // directives to fill the contents of virtual sections.
703         const MCDataFragment &DF = cast<MCDataFragment>(*it);
704         assert(DF.fixup_begin() == DF.fixup_end() &&
705                "Cannot have fixups in virtual section!");
706         for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
707           assert(DF.getContents()[i] == 0 &&
708                  "Invalid data value for virtual section!");
709         break;
710       }
711       case MCFragment::FT_Align:
712         // Check that we aren't trying to write a non-zero value into a virtual
713         // section.
714         assert((cast<MCAlignFragment>(it)->getValueSize() == 0 ||
715                 cast<MCAlignFragment>(it)->getValue() == 0) &&
716                "Invalid align in virtual section!");
717         break;
718       case MCFragment::FT_Fill:
719         assert((cast<MCFillFragment>(it)->getValueSize() == 0 ||
720                 cast<MCFillFragment>(it)->getValue() == 0) &&
721                "Invalid fill in virtual section!");
722         break;
723       }
724     }
725
726     return;
727   }
728
729   uint64_t Start = getWriter().getStream().tell();
730   (void)Start;
731
732   for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end();
733        it != ie; ++it)
734     writeFragment(*this, Layout, *it);
735
736   assert(getWriter().getStream().tell() - Start ==
737          Layout.getSectionAddressSize(SD));
738 }
739
740 std::pair<uint64_t, bool> MCAssembler::handleFixup(const MCAsmLayout &Layout,
741                                                    MCFragment &F,
742                                                    const MCFixup &Fixup) {
743   // Evaluate the fixup.
744   MCValue Target;
745   uint64_t FixedValue;
746   bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
747                  MCFixupKindInfo::FKF_IsPCRel;
748   if (!evaluateFixup(Layout, Fixup, &F, Target, FixedValue)) {
749     // The fixup was unresolved, we need a relocation. Inform the object
750     // writer of the relocation, and give it an opportunity to adjust the
751     // fixup value if need be.
752     getWriter().RecordRelocation(*this, Layout, &F, Fixup, Target, IsPCRel,
753                                  FixedValue);
754   }
755   return std::make_pair(FixedValue, IsPCRel);
756 }
757
758 void MCAssembler::Finish() {
759   DEBUG_WITH_TYPE("mc-dump", {
760       llvm::errs() << "assembler backend - pre-layout\n--\n";
761       dump(); });
762
763   // Create the layout object.
764   MCAsmLayout Layout(*this);
765
766   // Create dummy fragments and assign section ordinals.
767   unsigned SectionIndex = 0;
768   for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
769     // Create dummy fragments to eliminate any empty sections, this simplifies
770     // layout.
771     if (it->getFragmentList().empty())
772       new MCDataFragment(it);
773
774     it->setOrdinal(SectionIndex++);
775   }
776
777   // Assign layout order indices to sections and fragments.
778   for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
779     MCSectionData *SD = Layout.getSectionOrder()[i];
780     SD->setLayoutOrder(i);
781
782     unsigned FragmentIndex = 0;
783     for (MCSectionData::iterator iFrag = SD->begin(), iFragEnd = SD->end();
784          iFrag != iFragEnd; ++iFrag)
785       iFrag->setLayoutOrder(FragmentIndex++);
786   }
787
788   // Layout until everything fits.
789   while (layoutOnce(Layout))
790     continue;
791
792   DEBUG_WITH_TYPE("mc-dump", {
793       llvm::errs() << "assembler backend - post-relaxation\n--\n";
794       dump(); });
795
796   // Finalize the layout, including fragment lowering.
797   finishLayout(Layout);
798
799   DEBUG_WITH_TYPE("mc-dump", {
800       llvm::errs() << "assembler backend - final-layout\n--\n";
801       dump(); });
802
803   uint64_t StartOffset = OS.tell();
804
805   // Allow the object writer a chance to perform post-layout binding (for
806   // example, to set the index fields in the symbol data).
807   getWriter().ExecutePostLayoutBinding(*this, Layout);
808
809   // Evaluate and apply the fixups, generating relocation entries as necessary.
810   for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
811     for (MCSectionData::iterator it2 = it->begin(),
812            ie2 = it->end(); it2 != ie2; ++it2) {
813       MCEncodedFragmentWithFixups *F =
814         dyn_cast<MCEncodedFragmentWithFixups>(it2);
815       if (F) {
816         for (MCEncodedFragmentWithFixups::fixup_iterator it3 = F->fixup_begin(),
817              ie3 = F->fixup_end(); it3 != ie3; ++it3) {
818           MCFixup &Fixup = *it3;
819           uint64_t FixedValue;
820           bool IsPCRel;
821           std::tie(FixedValue, IsPCRel) = handleFixup(Layout, *F, Fixup);
822           getBackend().applyFixup(Fixup, F->getContents().data(),
823                                   F->getContents().size(), FixedValue, IsPCRel);
824         }
825       }
826     }
827   }
828
829   // Write the object file.
830   getWriter().WriteObject(*this, Layout);
831
832   stats::ObjectBytes += OS.tell() - StartOffset;
833 }
834
835 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
836                                        const MCRelaxableFragment *DF,
837                                        const MCAsmLayout &Layout) const {
838   // If we cannot resolve the fixup value, it requires relaxation.
839   MCValue Target;
840   uint64_t Value;
841   if (!evaluateFixup(Layout, Fixup, DF, Target, Value))
842     return true;
843
844   return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout);
845 }
846
847 bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
848                                           const MCAsmLayout &Layout) const {
849   // If this inst doesn't ever need relaxation, ignore it. This occurs when we
850   // are intentionally pushing out inst fragments, or because we relaxed a
851   // previous instruction to one that doesn't need relaxation.
852   if (!getBackend().mayNeedRelaxation(F->getInst()))
853     return false;
854
855   for (MCRelaxableFragment::const_fixup_iterator it = F->fixup_begin(),
856        ie = F->fixup_end(); it != ie; ++it)
857     if (fixupNeedsRelaxation(*it, F, Layout))
858       return true;
859
860   return false;
861 }
862
863 bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
864                                    MCRelaxableFragment &F) {
865   if (!fragmentNeedsRelaxation(&F, Layout))
866     return false;
867
868   ++stats::RelaxedInstructions;
869
870   // FIXME-PERF: We could immediately lower out instructions if we can tell
871   // they are fully resolved, to avoid retesting on later passes.
872
873   // Relax the fragment.
874
875   MCInst Relaxed;
876   getBackend().relaxInstruction(F.getInst(), Relaxed);
877
878   // Encode the new instruction.
879   //
880   // FIXME-PERF: If it matters, we could let the target do this. It can
881   // probably do so more efficiently in many cases.
882   SmallVector<MCFixup, 4> Fixups;
883   SmallString<256> Code;
884   raw_svector_ostream VecOS(Code);
885   getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups, F.getSubtargetInfo());
886   VecOS.flush();
887
888   // Update the fragment.
889   F.setInst(Relaxed);
890   F.getContents() = Code;
891   F.getFixups() = Fixups;
892
893   return true;
894 }
895
896 bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
897   int64_t Value = 0;
898   uint64_t OldSize = LF.getContents().size();
899   bool IsAbs = LF.getValue().EvaluateAsAbsolute(Value, Layout);
900   (void)IsAbs;
901   assert(IsAbs);
902   SmallString<8> &Data = LF.getContents();
903   Data.clear();
904   raw_svector_ostream OSE(Data);
905   if (LF.isSigned())
906     encodeSLEB128(Value, OSE);
907   else
908     encodeULEB128(Value, OSE);
909   OSE.flush();
910   return OldSize != LF.getContents().size();
911 }
912
913 bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
914                                      MCDwarfLineAddrFragment &DF) {
915   MCContext &Context = Layout.getAssembler().getContext();
916   int64_t AddrDelta = 0;
917   uint64_t OldSize = DF.getContents().size();
918   bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
919   (void)IsAbs;
920   assert(IsAbs);
921   int64_t LineDelta;
922   LineDelta = DF.getLineDelta();
923   SmallString<8> &Data = DF.getContents();
924   Data.clear();
925   raw_svector_ostream OSE(Data);
926   MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OSE);
927   OSE.flush();
928   return OldSize != Data.size();
929 }
930
931 bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
932                                               MCDwarfCallFrameFragment &DF) {
933   MCContext &Context = Layout.getAssembler().getContext();
934   int64_t AddrDelta = 0;
935   uint64_t OldSize = DF.getContents().size();
936   bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
937   (void)IsAbs;
938   assert(IsAbs);
939   SmallString<8> &Data = DF.getContents();
940   Data.clear();
941   raw_svector_ostream OSE(Data);
942   MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
943   OSE.flush();
944   return OldSize != Data.size();
945 }
946
947 bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
948   // Holds the first fragment which needed relaxing during this layout. It will
949   // remain NULL if none were relaxed.
950   // When a fragment is relaxed, all the fragments following it should get
951   // invalidated because their offset is going to change.
952   MCFragment *FirstRelaxedFragment = nullptr;
953
954   // Attempt to relax all the fragments in the section.
955   for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) {
956     // Check if this is a fragment that needs relaxation.
957     bool RelaxedFrag = false;
958     switch(I->getKind()) {
959     default:
960       break;
961     case MCFragment::FT_Relaxable:
962       assert(!getRelaxAll() &&
963              "Did not expect a MCRelaxableFragment in RelaxAll mode");
964       RelaxedFrag = relaxInstruction(Layout, *cast<MCRelaxableFragment>(I));
965       break;
966     case MCFragment::FT_Dwarf:
967       RelaxedFrag = relaxDwarfLineAddr(Layout,
968                                        *cast<MCDwarfLineAddrFragment>(I));
969       break;
970     case MCFragment::FT_DwarfFrame:
971       RelaxedFrag =
972         relaxDwarfCallFrameFragment(Layout,
973                                     *cast<MCDwarfCallFrameFragment>(I));
974       break;
975     case MCFragment::FT_LEB:
976       RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
977       break;
978     }
979     if (RelaxedFrag && !FirstRelaxedFragment)
980       FirstRelaxedFragment = I;
981   }
982   if (FirstRelaxedFragment) {
983     Layout.invalidateFragmentsFrom(FirstRelaxedFragment);
984     return true;
985   }
986   return false;
987 }
988
989 bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
990   ++stats::RelaxationSteps;
991
992   bool WasRelaxed = false;
993   for (iterator it = begin(), ie = end(); it != ie; ++it) {
994     MCSectionData &SD = *it;
995     while (layoutSectionOnce(Layout, SD))
996       WasRelaxed = true;
997   }
998
999   return WasRelaxed;
1000 }
1001
1002 void MCAssembler::finishLayout(MCAsmLayout &Layout) {
1003   // The layout is done. Mark every fragment as valid.
1004   for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
1005     Layout.getFragmentOffset(&*Layout.getSectionOrder()[i]->rbegin());
1006   }
1007 }
1008
1009 // Debugging methods
1010
1011 namespace llvm {
1012
1013 raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) {
1014   OS << "<MCFixup" << " Offset:" << AF.getOffset()
1015      << " Value:" << *AF.getValue()
1016      << " Kind:" << AF.getKind() << ">";
1017   return OS;
1018 }
1019
1020 }
1021
1022 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1023 void MCFragment::dump() {
1024   raw_ostream &OS = llvm::errs();
1025
1026   OS << "<";
1027   switch (getKind()) {
1028   case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
1029   case MCFragment::FT_Data:  OS << "MCDataFragment"; break;
1030   case MCFragment::FT_CompactEncodedInst:
1031     OS << "MCCompactEncodedInstFragment"; break;
1032   case MCFragment::FT_Fill:  OS << "MCFillFragment"; break;
1033   case MCFragment::FT_Relaxable:  OS << "MCRelaxableFragment"; break;
1034   case MCFragment::FT_Org:   OS << "MCOrgFragment"; break;
1035   case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
1036   case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
1037   case MCFragment::FT_LEB:   OS << "MCLEBFragment"; break;
1038   }
1039
1040   OS << "<MCFragment " << (void*) this << " LayoutOrder:" << LayoutOrder
1041      << " Offset:" << Offset
1042      << " HasInstructions:" << hasInstructions() 
1043      << " BundlePadding:" << static_cast<unsigned>(getBundlePadding()) << ">";
1044
1045   switch (getKind()) {
1046   case MCFragment::FT_Align: {
1047     const MCAlignFragment *AF = cast<MCAlignFragment>(this);
1048     if (AF->hasEmitNops())
1049       OS << " (emit nops)";
1050     OS << "\n       ";
1051     OS << " Alignment:" << AF->getAlignment()
1052        << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize()
1053        << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">";
1054     break;
1055   }
1056   case MCFragment::FT_Data:  {
1057     const MCDataFragment *DF = cast<MCDataFragment>(this);
1058     OS << "\n       ";
1059     OS << " Contents:[";
1060     const SmallVectorImpl<char> &Contents = DF->getContents();
1061     for (unsigned i = 0, e = Contents.size(); i != e; ++i) {
1062       if (i) OS << ",";
1063       OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
1064     }
1065     OS << "] (" << Contents.size() << " bytes)";
1066
1067     if (DF->fixup_begin() != DF->fixup_end()) {
1068       OS << ",\n       ";
1069       OS << " Fixups:[";
1070       for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(),
1071              ie = DF->fixup_end(); it != ie; ++it) {
1072         if (it != DF->fixup_begin()) OS << ",\n                ";
1073         OS << *it;
1074       }
1075       OS << "]";
1076     }
1077     break;
1078   }
1079   case MCFragment::FT_CompactEncodedInst: {
1080     const MCCompactEncodedInstFragment *CEIF =
1081       cast<MCCompactEncodedInstFragment>(this);
1082     OS << "\n       ";
1083     OS << " Contents:[";
1084     const SmallVectorImpl<char> &Contents = CEIF->getContents();
1085     for (unsigned i = 0, e = Contents.size(); i != e; ++i) {
1086       if (i) OS << ",";
1087       OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
1088     }
1089     OS << "] (" << Contents.size() << " bytes)";
1090     break;
1091   }
1092   case MCFragment::FT_Fill:  {
1093     const MCFillFragment *FF = cast<MCFillFragment>(this);
1094     OS << " Value:" << FF->getValue() << " ValueSize:" << FF->getValueSize()
1095        << " Size:" << FF->getSize();
1096     break;
1097   }
1098   case MCFragment::FT_Relaxable:  {
1099     const MCRelaxableFragment *F = cast<MCRelaxableFragment>(this);
1100     OS << "\n       ";
1101     OS << " Inst:";
1102     F->getInst().dump_pretty(OS);
1103     break;
1104   }
1105   case MCFragment::FT_Org:  {
1106     const MCOrgFragment *OF = cast<MCOrgFragment>(this);
1107     OS << "\n       ";
1108     OS << " Offset:" << OF->getOffset() << " Value:" << OF->getValue();
1109     break;
1110   }
1111   case MCFragment::FT_Dwarf:  {
1112     const MCDwarfLineAddrFragment *OF = cast<MCDwarfLineAddrFragment>(this);
1113     OS << "\n       ";
1114     OS << " AddrDelta:" << OF->getAddrDelta()
1115        << " LineDelta:" << OF->getLineDelta();
1116     break;
1117   }
1118   case MCFragment::FT_DwarfFrame:  {
1119     const MCDwarfCallFrameFragment *CF = cast<MCDwarfCallFrameFragment>(this);
1120     OS << "\n       ";
1121     OS << " AddrDelta:" << CF->getAddrDelta();
1122     break;
1123   }
1124   case MCFragment::FT_LEB: {
1125     const MCLEBFragment *LF = cast<MCLEBFragment>(this);
1126     OS << "\n       ";
1127     OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned();
1128     break;
1129   }
1130   }
1131   OS << ">";
1132 }
1133
1134 void MCSectionData::dump() {
1135   raw_ostream &OS = llvm::errs();
1136
1137   OS << "<MCSectionData";
1138   OS << " Alignment:" << getAlignment()
1139      << " Fragments:[\n      ";
1140   for (iterator it = begin(), ie = end(); it != ie; ++it) {
1141     if (it != begin()) OS << ",\n      ";
1142     it->dump();
1143   }
1144   OS << "]>";
1145 }
1146
1147 void MCSymbolData::dump() {
1148   raw_ostream &OS = llvm::errs();
1149
1150   OS << "<MCSymbolData Symbol:" << getSymbol()
1151      << " Fragment:" << getFragment() << " Offset:" << getOffset()
1152      << " Flags:" << getFlags() << " Index:" << getIndex();
1153   if (isCommon())
1154     OS << " (common, size:" << getCommonSize()
1155        << " align: " << getCommonAlignment() << ")";
1156   if (isExternal())
1157     OS << " (external)";
1158   if (isPrivateExtern())
1159     OS << " (private extern)";
1160   OS << ">";
1161 }
1162
1163 void MCAssembler::dump() {
1164   raw_ostream &OS = llvm::errs();
1165
1166   OS << "<MCAssembler\n";
1167   OS << "  Sections:[\n    ";
1168   for (iterator it = begin(), ie = end(); it != ie; ++it) {
1169     if (it != begin()) OS << ",\n    ";
1170     it->dump();
1171   }
1172   OS << "],\n";
1173   OS << "  Symbols:[";
1174
1175   for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
1176     if (it != symbol_begin()) OS << ",\n           ";
1177     it->dump();
1178   }
1179   OS << "]>\n";
1180 }
1181 #endif
1182
1183 // anchors for MC*Fragment vtables
1184 void MCEncodedFragment::anchor() { }
1185 void MCEncodedFragmentWithFixups::anchor() { }
1186 void MCDataFragment::anchor() { }
1187 void MCCompactEncodedInstFragment::anchor() { }
1188 void MCRelaxableFragment::anchor() { }
1189 void MCAlignFragment::anchor() { }
1190 void MCFillFragment::anchor() { }
1191 void MCOrgFragment::anchor() { }
1192 void MCLEBFragment::anchor() { }
1193 void MCDwarfLineAddrFragment::anchor() { }
1194 void MCDwarfCallFrameFragment::anchor() { }