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