1 //===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "assembler"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCAsmLayout.h"
13 #include "llvm/MC/MCCodeEmitter.h"
14 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCObjectWriter.h"
16 #include "llvm/MC/MCSymbol.h"
17 #include "llvm/MC/MCValue.h"
18 #include "llvm/ADT/OwningPtr.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Target/TargetRegistry.h"
26 #include "llvm/Target/TargetAsmBackend.h"
33 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
34 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
35 STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
36 STATISTIC(EvaluateFixup, "Number of evaluated fixups");
37 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
41 // FIXME FIXME FIXME: There are number of places in this file where we convert
42 // what is a 64-bit assembler value used for computation into a value in the
43 // object file, which may truncate it. We should detect that truncation where
44 // invalid and report errors back.
48 uint64_t MCAsmLayout::getFragmentAddress(const MCFragment *F) const {
49 return F->getAddress();
52 uint64_t MCAsmLayout::getSymbolAddress(const MCSymbolData *SD) const {
53 return SD->getAddress();
56 uint64_t MCAsmLayout::getSectionAddress(const MCSectionData *SD) const {
57 return SD->getAddress();
60 void MCAsmLayout::setSectionAddress(MCSectionData *SD, uint64_t Value) {
61 SD->setAddress(Value);
66 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
69 MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent)
72 FileSize(~UINT64_C(0))
75 Parent->getFragmentList().push_back(this);
78 MCFragment::~MCFragment() {
81 uint64_t MCFragment::getAddress() const {
82 assert(getParent() && "Missing Section!");
83 return getParent()->getAddress() + Offset;
88 MCSectionData::MCSectionData() : Section(0) {}
90 MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
93 Address(~UINT64_C(0)),
95 FileSize(~UINT64_C(0)),
96 HasInstructions(false)
99 A->getSectionList().push_back(this);
104 MCSymbolData::MCSymbolData() : Symbol(0) {}
106 MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
107 uint64_t _Offset, MCAssembler *A)
108 : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
109 IsExternal(false), IsPrivateExtern(false),
110 CommonSize(0), CommonAlign(0), Flags(0), Index(0)
113 A->getSymbolList().push_back(this);
118 MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
119 MCCodeEmitter &_Emitter, raw_ostream &_OS)
120 : Context(_Context), Backend(_Backend), Emitter(_Emitter),
121 OS(_OS), SubsectionsViaSymbols(false)
125 MCAssembler::~MCAssembler() {
128 static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
129 const MCAsmFixup &Fixup,
130 const MCValue Target,
131 const MCSection *BaseSection) {
132 // The effective fixup address is
133 // addr(atom(A)) + offset(A)
134 // - addr(atom(B)) - offset(B)
135 // - addr(<base symbol>) + <fixup offset from base symbol>
136 // and the offsets are not relocatable, so the fixup is fully resolved when
137 // addr(atom(A)) - addr(atom(B)) - addr(<base symbol>)) == 0.
139 // The simple (Darwin, except on x86_64) way of dealing with this was to
140 // assume that any reference to a temporary symbol *must* be a temporary
141 // symbol in the same atom, unless the sections differ. Therefore, any PCrel
142 // relocation to a temporary symbol (in the same section) is fully
143 // resolved. This also works in conjunction with absolutized .set, which
144 // requires the compiler to use .set to absolutize the differences between
145 // symbols which the compiler knows to be assembly time constants, so we don't
146 // need to worry about consider symbol differences fully resolved.
148 // Non-relative fixups are only resolved if constant.
150 return Target.isAbsolute();
152 // Otherwise, relative fixups are only resolved if not a difference and the
153 // target is a temporary in the same section.
154 if (Target.isAbsolute() || Target.getSymB())
157 const MCSymbol *A = &Target.getSymA()->getSymbol();
158 if (!A->isTemporary() || !A->isInSection() ||
159 &A->getSection() != BaseSection)
165 static bool isScatteredFixupFullyResolved(const MCAssembler &Asm,
166 const MCAsmLayout &Layout,
167 const MCAsmFixup &Fixup,
168 const MCValue Target,
169 const MCSymbolData *BaseSymbol) {
170 // The effective fixup address is
171 // addr(atom(A)) + offset(A)
172 // - addr(atom(B)) - offset(B)
173 // - addr(BaseSymbol) + <fixup offset from base symbol>
174 // and the offsets are not relocatable, so the fixup is fully resolved when
175 // addr(atom(A)) - addr(atom(B)) - addr(BaseSymbol) == 0.
177 // Note that "false" is almost always conservatively correct (it means we emit
178 // a relocation which is unnecessary), except when it would force us to emit a
179 // relocation which the target cannot encode.
181 const MCSymbolData *A_Base = 0, *B_Base = 0;
182 if (const MCSymbolRefExpr *A = Target.getSymA()) {
183 // Modified symbol references cannot be resolved.
184 if (A->getKind() != MCSymbolRefExpr::VK_None)
187 A_Base = Asm.getAtom(Layout, &Asm.getSymbolData(A->getSymbol()));
192 if (const MCSymbolRefExpr *B = Target.getSymB()) {
193 // Modified symbol references cannot be resolved.
194 if (B->getKind() != MCSymbolRefExpr::VK_None)
197 B_Base = Asm.getAtom(Layout, &Asm.getSymbolData(B->getSymbol()));
202 // If there is no base, A and B have to be the same atom for this fixup to be
205 return A_Base == B_Base;
207 // Otherwise, B must be missing and A must be the base.
208 return !B_Base && BaseSymbol == A_Base;
211 bool MCAssembler::isSymbolLinkerVisible(const MCSymbolData *SD) const {
212 // Non-temporary labels should always be visible to the linker.
213 if (!SD->getSymbol().isTemporary())
216 // Absolute temporary labels are never visible.
217 if (!SD->getFragment())
220 // Otherwise, check if the section requires symbols even for temporary labels.
221 return getBackend().doesSectionRequireSymbols(
222 SD->getFragment()->getParent()->getSection());
225 // FIXME-PERF: This routine is really slow.
226 const MCSymbolData *MCAssembler::getAtomForAddress(const MCAsmLayout &Layout,
227 const MCSectionData *Section,
228 uint64_t Address) const {
229 const MCSymbolData *Best = 0;
230 uint64_t BestAddress = 0;
232 for (MCAssembler::const_symbol_iterator it = symbol_begin(),
233 ie = symbol_end(); it != ie; ++it) {
234 // Ignore non-linker visible symbols.
235 if (!isSymbolLinkerVisible(it))
238 // Ignore symbols not in the same section.
239 if (!it->getFragment() || it->getFragment()->getParent() != Section)
242 // Otherwise, find the closest symbol preceding this address (ties are
243 // resolved in favor of the last defined symbol).
244 uint64_t SymbolAddress = Layout.getSymbolAddress(it);
245 if (SymbolAddress <= Address && (!Best || SymbolAddress >= BestAddress)) {
247 BestAddress = SymbolAddress;
254 // FIXME-PERF: This routine is really slow.
255 const MCSymbolData *MCAssembler::getAtom(const MCAsmLayout &Layout,
256 const MCSymbolData *SD) const {
257 // Linker visible symbols define atoms.
258 if (isSymbolLinkerVisible(SD))
261 // Absolute and undefined symbols have no defining atom.
262 if (!SD->getFragment())
265 // Otherwise, search by address.
266 return getAtomForAddress(Layout, SD->getFragment()->getParent(),
267 Layout.getSymbolAddress(SD));
270 bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
271 const MCAsmFixup &Fixup, const MCFragment *DF,
272 MCValue &Target, uint64_t &Value) const {
273 ++stats::EvaluateFixup;
275 if (!Fixup.Value->EvaluateAsRelocatable(Target, &Layout))
276 llvm_report_error("expected relocatable expression");
278 // FIXME: How do non-scattered symbols work in ELF? I presume the linker
279 // doesn't support small relocations, but then under what criteria does the
280 // assembler allow symbol differences?
282 Value = Target.getConstant();
285 Emitter.getFixupKindInfo(Fixup.Kind).Flags & MCFixupKindInfo::FKF_IsPCRel;
286 bool IsResolved = true;
287 if (const MCSymbolRefExpr *A = Target.getSymA()) {
288 if (A->getSymbol().isDefined())
289 Value += Layout.getSymbolAddress(&getSymbolData(A->getSymbol()));
293 if (const MCSymbolRefExpr *B = Target.getSymB()) {
294 if (B->getSymbol().isDefined())
295 Value -= Layout.getSymbolAddress(&getSymbolData(B->getSymbol()));
300 // If we are using scattered symbols, determine whether this value is actually
301 // resolved; scattering may cause atoms to move.
302 if (IsResolved && getBackend().hasScatteredSymbols()) {
303 if (getBackend().hasReliableSymbolDifference()) {
304 // If this is a PCrel relocation, find the base atom (identified by its
305 // symbol) that the fixup value is relative to.
306 const MCSymbolData *BaseSymbol = 0;
308 BaseSymbol = getAtomForAddress(
309 Layout, DF->getParent(), Layout.getFragmentAddress(DF)+Fixup.Offset);
315 IsResolved = isScatteredFixupFullyResolved(*this, Layout, Fixup, Target,
318 const MCSection *BaseSection = 0;
320 BaseSection = &DF->getParent()->getSection();
322 IsResolved = isScatteredFixupFullyResolvedSimple(*this, Fixup, Target,
328 Value -= Layout.getFragmentAddress(DF) + Fixup.Offset;
333 void MCAssembler::LayoutSection(MCSectionData &SD,
334 MCAsmLayout &Layout) {
335 uint64_t Address, StartAddress = Address = Layout.getSectionAddress(&SD);
337 for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
340 F.setOffset(Address - StartAddress);
342 // Evaluate fragment size.
343 switch (F.getKind()) {
344 case MCFragment::FT_Align: {
345 MCAlignFragment &AF = cast<MCAlignFragment>(F);
347 uint64_t Size = OffsetToAlignment(Address, AF.getAlignment());
348 if (Size > AF.getMaxBytesToEmit())
351 AF.setFileSize(Size);
355 case MCFragment::FT_Data:
356 F.setFileSize(cast<MCDataFragment>(F).getContents().size());
359 case MCFragment::FT_Fill: {
360 MCFillFragment &FF = cast<MCFillFragment>(F);
361 F.setFileSize(FF.getValueSize() * FF.getCount());
365 case MCFragment::FT_Inst:
366 F.setFileSize(cast<MCInstFragment>(F).getInstSize());
369 case MCFragment::FT_Org: {
370 MCOrgFragment &OF = cast<MCOrgFragment>(F);
372 int64_t TargetLocation;
373 if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout))
374 llvm_report_error("expected assembly-time absolute expression");
376 // FIXME: We need a way to communicate this error.
377 int64_t Offset = TargetLocation - F.getOffset();
379 llvm_report_error("invalid .org offset '" + Twine(TargetLocation) +
380 "' (at offset '" + Twine(F.getOffset()) + "'");
382 F.setFileSize(Offset);
386 case MCFragment::FT_ZeroFill: {
387 MCZeroFillFragment &ZFF = cast<MCZeroFillFragment>(F);
389 // Align the fragment offset; it is safe to adjust the offset freely since
390 // this is only in virtual sections.
391 Address = RoundUpToAlignment(Address, ZFF.getAlignment());
392 F.setOffset(Address - StartAddress);
394 // FIXME: This is misnamed.
395 F.setFileSize(ZFF.getSize());
400 Address += F.getFileSize();
403 // Set the section sizes.
404 SD.setSize(Address - StartAddress);
405 if (getBackend().isVirtualSection(SD.getSection()))
408 SD.setFileSize(Address - StartAddress);
411 /// WriteFragmentData - Write the \arg F data to the output file.
412 static void WriteFragmentData(const MCAssembler &Asm, const MCFragment &F,
413 MCObjectWriter *OW) {
414 uint64_t Start = OW->getStream().tell();
417 ++stats::EmittedFragments;
419 // FIXME: Embed in fragments instead?
420 switch (F.getKind()) {
421 case MCFragment::FT_Align: {
422 MCAlignFragment &AF = cast<MCAlignFragment>(F);
423 uint64_t Count = AF.getFileSize() / AF.getValueSize();
425 // FIXME: This error shouldn't actually occur (the front end should emit
426 // multiple .align directives to enforce the semantics it wants), but is
427 // severe enough that we want to report it. How to handle this?
428 if (Count * AF.getValueSize() != AF.getFileSize())
429 llvm_report_error("undefined .align directive, value size '" +
430 Twine(AF.getValueSize()) +
431 "' is not a divisor of padding size '" +
432 Twine(AF.getFileSize()) + "'");
434 // See if we are aligning with nops, and if so do that first to try to fill
435 // the Count bytes. Then if that did not fill any bytes or there are any
436 // bytes left to fill use the the Value and ValueSize to fill the rest.
437 // If we are aligning with nops, ask that target to emit the right data.
438 if (AF.getEmitNops()) {
439 if (!Asm.getBackend().WriteNopData(Count, OW))
440 llvm_report_error("unable to write nop sequence of " +
441 Twine(Count) + " bytes");
445 // Otherwise, write out in multiples of the value size.
446 for (uint64_t i = 0; i != Count; ++i) {
447 switch (AF.getValueSize()) {
449 assert(0 && "Invalid size!");
450 case 1: OW->Write8 (uint8_t (AF.getValue())); break;
451 case 2: OW->Write16(uint16_t(AF.getValue())); break;
452 case 4: OW->Write32(uint32_t(AF.getValue())); break;
453 case 8: OW->Write64(uint64_t(AF.getValue())); break;
459 case MCFragment::FT_Data: {
460 MCDataFragment &DF = cast<MCDataFragment>(F);
461 assert(DF.getFileSize() == DF.getContents().size() && "Invalid size!");
462 OW->WriteBytes(DF.getContents().str());
466 case MCFragment::FT_Fill: {
467 MCFillFragment &FF = cast<MCFillFragment>(F);
468 for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
469 switch (FF.getValueSize()) {
471 assert(0 && "Invalid size!");
472 case 1: OW->Write8 (uint8_t (FF.getValue())); break;
473 case 2: OW->Write16(uint16_t(FF.getValue())); break;
474 case 4: OW->Write32(uint32_t(FF.getValue())); break;
475 case 8: OW->Write64(uint64_t(FF.getValue())); break;
481 case MCFragment::FT_Inst:
482 llvm_unreachable("unexpected inst fragment after lowering");
485 case MCFragment::FT_Org: {
486 MCOrgFragment &OF = cast<MCOrgFragment>(F);
488 for (uint64_t i = 0, e = OF.getFileSize(); i != e; ++i)
489 OW->Write8(uint8_t(OF.getValue()));
494 case MCFragment::FT_ZeroFill: {
495 assert(0 && "Invalid zero fill fragment in concrete section!");
500 assert(OW->getStream().tell() - Start == F.getFileSize());
503 void MCAssembler::WriteSectionData(const MCSectionData *SD,
504 MCObjectWriter *OW) const {
505 // Ignore virtual sections.
506 if (getBackend().isVirtualSection(SD->getSection())) {
507 assert(SD->getFileSize() == 0);
511 uint64_t Start = OW->getStream().tell();
514 for (MCSectionData::const_iterator it = SD->begin(),
515 ie = SD->end(); it != ie; ++it)
516 WriteFragmentData(*this, *it, OW);
518 // Add section padding.
519 assert(SD->getFileSize() >= SD->getSize() && "Invalid section sizes!");
520 OW->WriteZeros(SD->getFileSize() - SD->getSize());
522 assert(OW->getStream().tell() - Start == SD->getFileSize());
525 void MCAssembler::Finish() {
526 DEBUG_WITH_TYPE("mc-dump", {
527 llvm::errs() << "assembler backend - pre-layout\n--\n";
530 // Layout until everything fits.
531 MCAsmLayout Layout(*this);
532 while (LayoutOnce(Layout))
535 DEBUG_WITH_TYPE("mc-dump", {
536 llvm::errs() << "assembler backend - post-relaxation\n--\n";
539 // Finalize the layout, including fragment lowering.
540 FinishLayout(Layout);
542 DEBUG_WITH_TYPE("mc-dump", {
543 llvm::errs() << "assembler backend - final-layout\n--\n";
546 uint64_t StartOffset = OS.tell();
547 llvm::OwningPtr<MCObjectWriter> Writer(getBackend().createObjectWriter(OS));
549 llvm_report_error("unable to create object writer!");
551 // Allow the object writer a chance to perform post-layout binding (for
552 // example, to set the index fields in the symbol data).
553 Writer->ExecutePostLayoutBinding(*this);
555 // Evaluate and apply the fixups, generating relocation entries as necessary.
556 for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
557 for (MCSectionData::iterator it2 = it->begin(),
558 ie2 = it->end(); it2 != ie2; ++it2) {
559 MCDataFragment *DF = dyn_cast<MCDataFragment>(it2);
563 for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
564 ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
565 MCAsmFixup &Fixup = *it3;
567 // Evaluate the fixup.
570 if (!EvaluateFixup(Layout, Fixup, DF, Target, FixedValue)) {
571 // The fixup was unresolved, we need a relocation. Inform the object
572 // writer of the relocation, and give it an opportunity to adjust the
573 // fixup value if need be.
574 Writer->RecordRelocation(*this, Layout, DF, Fixup, Target,FixedValue);
577 getBackend().ApplyFixup(Fixup, *DF, FixedValue);
582 // Write the object file.
583 Writer->WriteObject(*this, Layout);
586 stats::ObjectBytes += OS.tell() - StartOffset;
589 bool MCAssembler::FixupNeedsRelaxation(const MCAsmFixup &Fixup,
590 const MCFragment *DF,
591 const MCAsmLayout &Layout) const {
592 // If we cannot resolve the fixup value, it requires relaxation.
595 if (!EvaluateFixup(Layout, Fixup, DF, Target, Value))
598 // Otherwise, relax if the value is too big for a (signed) i8.
599 return int64_t(Value) != int64_t(int8_t(Value));
602 bool MCAssembler::FragmentNeedsRelaxation(const MCInstFragment *IF,
603 const MCAsmLayout &Layout) const {
604 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
605 // are intentionally pushing out inst fragments, or because we relaxed a
606 // previous instruction to one that doesn't need relaxation.
607 if (!getBackend().MayNeedRelaxation(IF->getInst(), IF->getFixups()))
610 for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(),
611 ie = IF->fixup_end(); it != ie; ++it)
612 if (FixupNeedsRelaxation(*it, IF, Layout))
618 bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
619 ++stats::RelaxationSteps;
621 // Layout the concrete sections and fragments.
622 uint64_t Address = 0;
623 MCSectionData *Prev = 0;
624 for (iterator it = begin(), ie = end(); it != ie; ++it) {
625 MCSectionData &SD = *it;
627 // Skip virtual sections.
628 if (getBackend().isVirtualSection(SD.getSection()))
631 // Align this section if necessary by adding padding bytes to the previous
633 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) {
634 assert(Prev && "Missing prev section!");
635 Prev->setFileSize(Prev->getFileSize() + Pad);
639 // Layout the section fragments and its size.
640 Layout.setSectionAddress(&SD, Address);
641 LayoutSection(SD, Layout);
642 Address += SD.getFileSize();
647 // Layout the virtual sections.
648 for (iterator it = begin(), ie = end(); it != ie; ++it) {
649 MCSectionData &SD = *it;
651 if (!getBackend().isVirtualSection(SD.getSection()))
654 // Align this section if necessary by adding padding bytes to the previous
656 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment()))
659 Layout.setSectionAddress(&SD, Address);
660 LayoutSection(SD, Layout);
661 Address += SD.getSize();
664 // Scan for fragments that need relaxation.
665 for (iterator it = begin(), ie = end(); it != ie; ++it) {
666 MCSectionData &SD = *it;
668 for (MCSectionData::iterator it2 = SD.begin(),
669 ie2 = SD.end(); it2 != ie2; ++it2) {
670 // Check if this is an instruction fragment that needs relaxation.
671 MCInstFragment *IF = dyn_cast<MCInstFragment>(it2);
672 if (!IF || !FragmentNeedsRelaxation(IF, Layout))
675 ++stats::RelaxedInstructions;
677 // FIXME-PERF: We could immediately lower out instructions if we can tell
678 // they are fully resolved, to avoid retesting on later passes.
680 // Relax the fragment.
683 getBackend().RelaxInstruction(IF, Relaxed);
685 // Encode the new instruction.
687 // FIXME-PERF: If it matters, we could let the target do this. It can
688 // probably do so more efficiently in many cases.
689 SmallVector<MCFixup, 4> Fixups;
690 SmallString<256> Code;
691 raw_svector_ostream VecOS(Code);
692 getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups);
695 // Update the instruction fragment.
696 IF->setInst(Relaxed);
697 IF->getCode() = Code;
698 IF->getFixups().clear();
699 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
700 MCFixup &F = Fixups[i];
701 IF->getFixups().push_back(MCAsmFixup(F.getOffset(), *F.getValue(),
707 // FIXME-PERF: This is O(N^2), but will be eliminated once we have a
708 // smart MCAsmLayout object.
716 void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
717 // Lower out any instruction fragments, to simplify the fixup application and
720 // FIXME-PERF: We don't have to do this, but the assumption is that it is
721 // cheap (we will mostly end up eliminating fragments and appending on to data
722 // fragments), so the extra complexity downstream isn't worth it. Evaluate
724 for (iterator it = begin(), ie = end(); it != ie; ++it) {
725 MCSectionData &SD = *it;
727 for (MCSectionData::iterator it2 = SD.begin(),
728 ie2 = SD.end(); it2 != ie2; ++it2) {
729 MCInstFragment *IF = dyn_cast<MCInstFragment>(it2);
733 // Create a new data fragment for the instruction.
735 // FIXME-PERF: Reuse previous data fragment if possible.
736 MCDataFragment *DF = new MCDataFragment();
737 SD.getFragmentList().insert(it2, DF);
739 // Update the data fragments layout data.
740 DF->setParent(IF->getParent());
741 DF->setOffset(IF->getOffset());
742 DF->setFileSize(IF->getInstSize());
744 // Copy in the data and the fixups.
745 DF->getContents().append(IF->getCode().begin(), IF->getCode().end());
746 for (unsigned i = 0, e = IF->getFixups().size(); i != e; ++i)
747 DF->getFixups().push_back(IF->getFixups()[i]);
749 // Delete the instruction fragment and update the iterator.
750 SD.getFragmentList().erase(IF);
760 raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
761 OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << *AF.Value
762 << " Kind:" << AF.Kind << ">";
768 void MCFragment::dump() {
769 raw_ostream &OS = llvm::errs();
771 OS << "<MCFragment " << (void*) this << " Offset:" << Offset
772 << " FileSize:" << FileSize;
777 void MCAlignFragment::dump() {
778 raw_ostream &OS = llvm::errs();
780 OS << "<MCAlignFragment ";
781 this->MCFragment::dump();
783 OS << " Alignment:" << getAlignment()
784 << " Value:" << getValue() << " ValueSize:" << getValueSize()
785 << " MaxBytesToEmit:" << getMaxBytesToEmit() << ">";
788 void MCDataFragment::dump() {
789 raw_ostream &OS = llvm::errs();
791 OS << "<MCDataFragment ";
792 this->MCFragment::dump();
795 for (unsigned i = 0, e = getContents().size(); i != e; ++i) {
797 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
799 OS << "] (" << getContents().size() << " bytes)";
801 if (!getFixups().empty()) {
804 for (fixup_iterator it = fixup_begin(), ie = fixup_end(); it != ie; ++it) {
805 if (it != fixup_begin()) OS << ",\n ";
814 void MCFillFragment::dump() {
815 raw_ostream &OS = llvm::errs();
817 OS << "<MCFillFragment ";
818 this->MCFragment::dump();
820 OS << " Value:" << getValue() << " ValueSize:" << getValueSize()
821 << " Count:" << getCount() << ">";
824 void MCInstFragment::dump() {
825 raw_ostream &OS = llvm::errs();
827 OS << "<MCInstFragment ";
828 this->MCFragment::dump();
831 getInst().dump_pretty(OS);
835 void MCOrgFragment::dump() {
836 raw_ostream &OS = llvm::errs();
838 OS << "<MCOrgFragment ";
839 this->MCFragment::dump();
841 OS << " Offset:" << getOffset() << " Value:" << getValue() << ">";
844 void MCZeroFillFragment::dump() {
845 raw_ostream &OS = llvm::errs();
847 OS << "<MCZeroFillFragment ";
848 this->MCFragment::dump();
850 OS << " Size:" << getSize() << " Alignment:" << getAlignment() << ">";
853 void MCSectionData::dump() {
854 raw_ostream &OS = llvm::errs();
856 OS << "<MCSectionData";
857 OS << " Alignment:" << getAlignment() << " Address:" << Address
858 << " Size:" << Size << " FileSize:" << FileSize
859 << " Fragments:[\n ";
860 for (iterator it = begin(), ie = end(); it != ie; ++it) {
861 if (it != begin()) OS << ",\n ";
867 void MCSymbolData::dump() {
868 raw_ostream &OS = llvm::errs();
870 OS << "<MCSymbolData Symbol:" << getSymbol()
871 << " Fragment:" << getFragment() << " Offset:" << getOffset()
872 << " Flags:" << getFlags() << " Index:" << getIndex();
874 OS << " (common, size:" << getCommonSize()
875 << " align: " << getCommonAlignment() << ")";
878 if (isPrivateExtern())
879 OS << " (private extern)";
883 void MCAssembler::dump() {
884 raw_ostream &OS = llvm::errs();
886 OS << "<MCAssembler\n";
887 OS << " Sections:[\n ";
888 for (iterator it = begin(), ie = end(); it != ie; ++it) {
889 if (it != begin()) OS << ",\n ";
895 for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
896 if (it != symbol_begin()) OS << ",\n ";