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"
29 #include "../Target/X86/X86FixupKinds.h"
34 STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
36 // FIXME FIXME FIXME: There are number of places in this file where we convert
37 // what is a 64-bit assembler value used for computation into a value in the
38 // object file, which may truncate it. We should detect that truncation where
39 // invalid and report errors back.
43 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
46 MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent)
49 FileSize(~UINT64_C(0))
52 Parent->getFragmentList().push_back(this);
55 MCFragment::~MCFragment() {
58 uint64_t MCFragment::getAddress() const {
59 assert(getParent() && "Missing Section!");
60 return getParent()->getAddress() + Offset;
65 MCSectionData::MCSectionData() : Section(0) {}
67 MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
70 Address(~UINT64_C(0)),
72 FileSize(~UINT64_C(0)),
73 HasInstructions(false)
76 A->getSectionList().push_back(this);
81 MCSymbolData::MCSymbolData() : Symbol(0) {}
83 MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
84 uint64_t _Offset, MCAssembler *A)
85 : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
86 IsExternal(false), IsPrivateExtern(false),
87 CommonSize(0), CommonAlign(0), Flags(0), Index(0)
90 A->getSymbolList().push_back(this);
95 MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
96 MCCodeEmitter &_Emitter, raw_ostream &_OS)
97 : Context(_Context), Backend(_Backend), Emitter(_Emitter),
98 OS(_OS), SubsectionsViaSymbols(false)
102 MCAssembler::~MCAssembler() {
105 static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
106 const MCAsmFixup &Fixup,
107 const MCDataFragment *DF,
108 const MCValue Target,
109 const MCSection *BaseSection) {
110 // The effective fixup address is
111 // addr(atom(A)) + offset(A)
112 // - addr(atom(B)) - offset(B)
113 // - addr(<base symbol>) + <fixup offset from base symbol>
114 // and the offsets are not relocatable, so the fixup is fully resolved when
115 // addr(atom(A)) - addr(atom(B)) - addr(<base symbol>)) == 0.
117 // The simple (Darwin, except on x86_64) way of dealing with this was to
118 // assume that any reference to a temporary symbol *must* be a temporary
119 // symbol in the same atom, unless the sections differ. Therefore, any PCrel
120 // relocation to a temporary symbol (in the same section) is fully
121 // resolved. This also works in conjunction with absolutized .set, which
122 // requires the compiler to use .set to absolutize the differences between
123 // symbols which the compiler knows to be assembly time constants, so we don't
124 // need to worry about consider symbol differences fully resolved.
126 // Non-relative fixups are only resolved if constant.
128 return Target.isAbsolute();
130 // Otherwise, relative fixups are only resolved if not a difference and the
131 // target is a temporary in the same section.
132 if (Target.isAbsolute() || Target.getSymB())
135 const MCSymbol *A = &Target.getSymA()->getSymbol();
136 if (!A->isTemporary() || !A->isInSection() ||
137 &A->getSection() != BaseSection)
143 static bool isScatteredFixupFullyResolved(const MCAssembler &Asm,
144 const MCAsmFixup &Fixup,
145 const MCDataFragment *DF,
146 const MCValue Target,
147 const MCSymbolData *BaseSymbol) {
148 // The effective fixup address is
149 // addr(atom(A)) + offset(A)
150 // - addr(atom(B)) - offset(B)
151 // - addr(BaseSymbol) + <fixup offset from base symbol>
152 // and the offsets are not relocatable, so the fixup is fully resolved when
153 // addr(atom(A)) - addr(atom(B)) - addr(BaseSymbol) == 0.
155 // Note that "false" is almost always conservatively correct (it means we emit
156 // a relocation which is unnecessary), except when it would force us to emit a
157 // relocation which the target cannot encode.
159 const MCSymbolData *A_Base = 0, *B_Base = 0;
160 if (const MCSymbolRefExpr *A = Target.getSymA()) {
161 // Modified symbol references cannot be resolved.
162 if (A->getKind() != MCSymbolRefExpr::VK_None)
165 A_Base = Asm.getAtom(&Asm.getSymbolData(A->getSymbol()));
170 if (const MCSymbolRefExpr *B = Target.getSymB()) {
171 // Modified symbol references cannot be resolved.
172 if (B->getKind() != MCSymbolRefExpr::VK_None)
175 B_Base = Asm.getAtom(&Asm.getSymbolData(B->getSymbol()));
180 // If there is no base, A and B have to be the same atom for this fixup to be
183 return A_Base == B_Base;
185 // Otherwise, B must be missing and A must be the base.
186 return !B_Base && BaseSymbol == A_Base;
189 bool MCAssembler::isSymbolLinkerVisible(const MCSymbolData *SD) const {
190 // Non-temporary labels should always be visible to the linker.
191 if (!SD->getSymbol().isTemporary())
194 // Absolute temporary labels are never visible.
195 if (!SD->getFragment())
198 // Otherwise, check if the section requires symbols even for temporary labels.
199 return getBackend().doesSectionRequireSymbols(
200 SD->getFragment()->getParent()->getSection());
203 const MCSymbolData *MCAssembler::getAtomForAddress(const MCSectionData *Section,
204 uint64_t Address) const {
205 const MCSymbolData *Best = 0;
206 for (MCAssembler::const_symbol_iterator it = symbol_begin(),
207 ie = symbol_end(); it != ie; ++it) {
208 // Ignore non-linker visible symbols.
209 if (!isSymbolLinkerVisible(it))
212 // Ignore symbols not in the same section.
213 if (!it->getFragment() || it->getFragment()->getParent() != Section)
216 // Otherwise, find the closest symbol preceding this address (ties are
217 // resolved in favor of the last defined symbol).
218 if (it->getAddress() <= Address &&
219 (!Best || it->getAddress() >= Best->getAddress()))
226 const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
227 // Linker visible symbols define atoms.
228 if (isSymbolLinkerVisible(SD))
231 // Absolute and undefined symbols have no defining atom.
232 if (!SD->getFragment())
235 // Otherwise, search by address.
236 return getAtomForAddress(SD->getFragment()->getParent(), SD->getAddress());
239 bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout, MCAsmFixup &Fixup,
241 MCValue &Target, uint64_t &Value) const {
242 if (!Fixup.Value->EvaluateAsRelocatable(Target, &Layout))
243 llvm_report_error("expected relocatable expression");
245 // FIXME: How do non-scattered symbols work in ELF? I presume the linker
246 // doesn't support small relocations, but then under what criteria does the
247 // assembler allow symbol differences?
249 Value = Target.getConstant();
252 Emitter.getFixupKindInfo(Fixup.Kind).Flags & MCFixupKindInfo::FKF_IsPCRel;
253 bool IsResolved = true;
254 if (const MCSymbolRefExpr *A = Target.getSymA()) {
255 if (A->getSymbol().isDefined())
256 Value += getSymbolData(A->getSymbol()).getAddress();
260 if (const MCSymbolRefExpr *B = Target.getSymB()) {
261 if (B->getSymbol().isDefined())
262 Value -= getSymbolData(B->getSymbol()).getAddress();
267 // If we are using scattered symbols, determine whether this value is actually
268 // resolved; scattering may cause atoms to move.
269 if (IsResolved && getBackend().hasScatteredSymbols()) {
270 if (getBackend().hasReliableSymbolDifference()) {
271 // If this is a PCrel relocation, find the base atom (identified by its
272 // symbol) that the fixup value is relative to.
273 const MCSymbolData *BaseSymbol = 0;
275 BaseSymbol = getAtomForAddress(
276 DF->getParent(), DF->getAddress() + Fixup.Offset);
282 IsResolved = isScatteredFixupFullyResolved(*this, Fixup, DF, Target,
285 const MCSection *BaseSection = 0;
287 BaseSection = &DF->getParent()->getSection();
289 IsResolved = isScatteredFixupFullyResolvedSimple(*this, Fixup, DF, Target,
295 Value -= DF->getAddress() + Fixup.Offset;
300 void MCAssembler::LayoutSection(MCSectionData &SD,
301 MCAsmLayout &Layout) {
302 uint64_t Address = SD.getAddress();
304 for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
307 F.setOffset(Address - SD.getAddress());
309 // Evaluate fragment size.
310 switch (F.getKind()) {
311 case MCFragment::FT_Align: {
312 MCAlignFragment &AF = cast<MCAlignFragment>(F);
314 uint64_t Size = OffsetToAlignment(Address, AF.getAlignment());
315 if (Size > AF.getMaxBytesToEmit())
318 AF.setFileSize(Size);
322 case MCFragment::FT_Data:
323 case MCFragment::FT_Fill:
324 F.setFileSize(F.getMaxFileSize());
327 case MCFragment::FT_Org: {
328 MCOrgFragment &OF = cast<MCOrgFragment>(F);
330 int64_t TargetLocation;
331 if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout))
332 llvm_report_error("expected assembly-time absolute expression");
334 // FIXME: We need a way to communicate this error.
335 int64_t Offset = TargetLocation - F.getOffset();
337 llvm_report_error("invalid .org offset '" + Twine(TargetLocation) +
338 "' (at offset '" + Twine(F.getOffset()) + "'");
340 F.setFileSize(Offset);
344 case MCFragment::FT_ZeroFill: {
345 MCZeroFillFragment &ZFF = cast<MCZeroFillFragment>(F);
347 // Align the fragment offset; it is safe to adjust the offset freely since
348 // this is only in virtual sections.
349 Address = RoundUpToAlignment(Address, ZFF.getAlignment());
350 F.setOffset(Address - SD.getAddress());
352 // FIXME: This is misnamed.
353 F.setFileSize(ZFF.getSize());
358 Address += F.getFileSize();
361 // Set the section sizes.
362 SD.setSize(Address - SD.getAddress());
363 if (getBackend().isVirtualSection(SD.getSection()))
366 SD.setFileSize(Address - SD.getAddress());
369 /// WriteNopData - Write optimal nops to the output file for the \arg Count
370 /// bytes. This returns the number of bytes written. It may return 0 if
371 /// the \arg Count is more than the maximum optimal nops.
373 /// FIXME this is X86 32-bit specific and should move to a better place.
374 static uint64_t WriteNopData(uint64_t Count, MCObjectWriter *OW) {
375 static const uint8_t Nops[16][16] = {
383 {0x0f, 0x1f, 0x40, 0x00},
384 // nopl 0(%[re]ax,%[re]ax,1)
385 {0x0f, 0x1f, 0x44, 0x00, 0x00},
386 // nopw 0(%[re]ax,%[re]ax,1)
387 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
389 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
390 // nopl 0L(%[re]ax,%[re]ax,1)
391 {0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
392 // nopw 0L(%[re]ax,%[re]ax,1)
393 {0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
394 // nopw %cs:0L(%[re]ax,%[re]ax,1)
395 {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
396 // nopl 0(%[re]ax,%[re]ax,1)
397 // nopw 0(%[re]ax,%[re]ax,1)
398 {0x0f, 0x1f, 0x44, 0x00, 0x00,
399 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
400 // nopw 0(%[re]ax,%[re]ax,1)
401 // nopw 0(%[re]ax,%[re]ax,1)
402 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
403 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
404 // nopw 0(%[re]ax,%[re]ax,1)
405 // nopl 0L(%[re]ax) */
406 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
407 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
410 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
411 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
413 // nopl 0L(%[re]ax,%[re]ax,1)
414 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
415 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}
421 for (uint64_t i = 0; i < Count; i++)
422 OW->Write8(uint8_t(Nops[Count - 1][i]));
427 /// WriteFragmentData - Write the \arg F data to the output file.
428 static void WriteFragmentData(const MCFragment &F, MCObjectWriter *OW) {
429 uint64_t Start = OW->getStream().tell();
434 // FIXME: Embed in fragments instead?
435 switch (F.getKind()) {
436 case MCFragment::FT_Align: {
437 MCAlignFragment &AF = cast<MCAlignFragment>(F);
438 uint64_t Count = AF.getFileSize() / AF.getValueSize();
440 // FIXME: This error shouldn't actually occur (the front end should emit
441 // multiple .align directives to enforce the semantics it wants), but is
442 // severe enough that we want to report it. How to handle this?
443 if (Count * AF.getValueSize() != AF.getFileSize())
444 llvm_report_error("undefined .align directive, value size '" +
445 Twine(AF.getValueSize()) +
446 "' is not a divisor of padding size '" +
447 Twine(AF.getFileSize()) + "'");
449 // See if we are aligning with nops, and if so do that first to try to fill
450 // the Count bytes. Then if that did not fill any bytes or there are any
451 // bytes left to fill use the the Value and ValueSize to fill the rest.
452 if (AF.getEmitNops()) {
453 uint64_t NopByteCount = WriteNopData(Count, OW);
454 Count -= NopByteCount;
457 for (uint64_t i = 0; i != Count; ++i) {
458 switch (AF.getValueSize()) {
460 assert(0 && "Invalid size!");
461 case 1: OW->Write8 (uint8_t (AF.getValue())); break;
462 case 2: OW->Write16(uint16_t(AF.getValue())); break;
463 case 4: OW->Write32(uint32_t(AF.getValue())); break;
464 case 8: OW->Write64(uint64_t(AF.getValue())); break;
470 case MCFragment::FT_Data: {
471 OW->WriteBytes(cast<MCDataFragment>(F).getContents().str());
475 case MCFragment::FT_Fill: {
476 MCFillFragment &FF = cast<MCFillFragment>(F);
477 for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
478 switch (FF.getValueSize()) {
480 assert(0 && "Invalid size!");
481 case 1: OW->Write8 (uint8_t (FF.getValue())); break;
482 case 2: OW->Write16(uint16_t(FF.getValue())); break;
483 case 4: OW->Write32(uint32_t(FF.getValue())); break;
484 case 8: OW->Write64(uint64_t(FF.getValue())); break;
490 case MCFragment::FT_Org: {
491 MCOrgFragment &OF = cast<MCOrgFragment>(F);
493 for (uint64_t i = 0, e = OF.getFileSize(); i != e; ++i)
494 OW->Write8(uint8_t(OF.getValue()));
499 case MCFragment::FT_ZeroFill: {
500 assert(0 && "Invalid zero fill fragment in concrete section!");
505 assert(OW->getStream().tell() - Start == F.getFileSize());
508 void MCAssembler::WriteSectionData(const MCSectionData *SD,
509 MCObjectWriter *OW) const {
510 // Ignore virtual sections.
511 if (getBackend().isVirtualSection(SD->getSection())) {
512 assert(SD->getFileSize() == 0);
516 uint64_t Start = OW->getStream().tell();
519 for (MCSectionData::const_iterator it = SD->begin(),
520 ie = SD->end(); it != ie; ++it)
521 WriteFragmentData(*it, OW);
523 // Add section padding.
524 assert(SD->getFileSize() >= SD->getSize() && "Invalid section sizes!");
525 OW->WriteZeros(SD->getFileSize() - SD->getSize());
527 assert(OW->getStream().tell() - Start == SD->getFileSize());
530 void MCAssembler::Finish() {
531 DEBUG_WITH_TYPE("mc-dump", {
532 llvm::errs() << "assembler backend - pre-layout\n--\n";
535 // Layout until everything fits.
536 MCAsmLayout Layout(*this);
537 while (LayoutOnce(Layout))
540 DEBUG_WITH_TYPE("mc-dump", {
541 llvm::errs() << "assembler backend - post-layout\n--\n";
544 llvm::OwningPtr<MCObjectWriter> Writer(getBackend().createObjectWriter(OS));
546 llvm_report_error("unable to create object writer!");
548 // Allow the object writer a chance to perform post-layout binding (for
549 // example, to set the index fields in the symbol data).
550 Writer->ExecutePostLayoutBinding(*this);
552 // Evaluate and apply the fixups, generating relocation entries as necessary.
553 for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
554 for (MCSectionData::iterator it2 = it->begin(),
555 ie2 = it->end(); it2 != ie2; ++it2) {
556 MCDataFragment *DF = dyn_cast<MCDataFragment>(it2);
560 for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
561 ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
562 MCAsmFixup &Fixup = *it3;
564 // Evaluate the fixup.
567 if (!EvaluateFixup(Layout, Fixup, DF, Target, FixedValue)) {
568 // The fixup was unresolved, we need a relocation. Inform the object
569 // writer of the relocation, and give it an opportunity to adjust the
570 // fixup value if need be.
571 Writer->RecordRelocation(*this, *DF, Fixup, Target, FixedValue);
574 getBackend().ApplyFixup(Fixup, *DF, FixedValue);
579 // Write the object file.
580 Writer->WriteObject(*this);
584 bool MCAssembler::FixupNeedsRelaxation(MCAsmFixup &Fixup, MCDataFragment *DF,
585 const MCAsmLayout &Layout) const {
586 // Currently we only need to relax X86::reloc_pcrel_1byte.
587 if (unsigned(Fixup.Kind) != X86::reloc_pcrel_1byte)
590 // If we cannot resolve the fixup value, it requires relaxation.
593 if (!EvaluateFixup(Layout, Fixup, DF, Target, Value))
596 // Otherwise, relax if the value is too big for a (signed) i8.
597 return int64_t(Value) != int64_t(int8_t(Value));
600 bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
601 // Layout the concrete sections and fragments.
602 uint64_t Address = 0;
603 MCSectionData *Prev = 0;
604 for (iterator it = begin(), ie = end(); it != ie; ++it) {
605 MCSectionData &SD = *it;
607 // Skip virtual sections.
608 if (getBackend().isVirtualSection(SD.getSection()))
611 // Align this section if necessary by adding padding bytes to the previous
613 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) {
614 assert(Prev && "Missing prev section!");
615 Prev->setFileSize(Prev->getFileSize() + Pad);
619 // Layout the section fragments and its size.
620 SD.setAddress(Address);
621 LayoutSection(SD, Layout);
622 Address += SD.getFileSize();
627 // Layout the virtual sections.
628 for (iterator it = begin(), ie = end(); it != ie; ++it) {
629 MCSectionData &SD = *it;
631 if (!getBackend().isVirtualSection(SD.getSection()))
634 // Align this section if necessary by adding padding bytes to the previous
636 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment()))
639 SD.setAddress(Address);
640 LayoutSection(SD, Layout);
641 Address += SD.getSize();
644 // Scan the fixups in order and relax any that don't fit.
645 for (iterator it = begin(), ie = end(); it != ie; ++it) {
646 MCSectionData &SD = *it;
648 for (MCSectionData::iterator it2 = SD.begin(),
649 ie2 = SD.end(); it2 != ie2; ++it2) {
650 MCDataFragment *DF = dyn_cast<MCDataFragment>(it2);
654 for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
655 ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
656 MCAsmFixup &Fixup = *it3;
658 // Check whether we need to relax this fixup.
659 if (!FixupNeedsRelaxation(Fixup, DF, Layout))
662 // Relax the instruction.
664 // FIXME: This is a huge temporary hack which just looks for x86
665 // branches; the only thing we need to relax on x86 is
666 // 'X86::reloc_pcrel_1byte'. Once we have MCInst fragments, this will be
667 // replaced by a TargetAsmBackend hook (most likely tblgen'd) to relax
668 // an individual MCInst.
669 SmallVectorImpl<char> &C = DF->getContents();
670 uint64_t PrevOffset = Fixup.Offset;
674 if (unsigned(C[Fixup.Offset-1]) >= 0x70 &&
675 unsigned(C[Fixup.Offset-1]) <= 0x7f) {
676 C[Fixup.Offset] = C[Fixup.Offset-1] + 0x10;
677 C[Fixup.Offset-1] = char(0x0f);
682 } else if (C[Fixup.Offset-1] == char(0xeb)) {
683 C[Fixup.Offset-1] = char(0xe9);
687 llvm_unreachable("unknown 1 byte pcrel instruction!");
689 Fixup.Value = MCBinaryExpr::Create(
690 MCBinaryExpr::Sub, Fixup.Value,
691 MCConstantExpr::Create(3, getContext()),
693 C.insert(C.begin() + Fixup.Offset, Amt, char(0));
694 Fixup.Kind = MCFixupKind(X86::reloc_pcrel_4byte);
696 // Update the remaining fixups, which have slid.
698 // FIXME: This is bad for performance, but will be eliminated by the
699 // move to MCInst specific fragments.
701 for (; it3 != ie3; ++it3)
704 // Update all the symbols for this fragment, which may have slid.
706 // FIXME: This is really really bad for performance, but will be
707 // eliminated by the move to MCInst specific fragments.
708 for (MCAssembler::symbol_iterator it = symbol_begin(),
709 ie = symbol_end(); it != ie; ++it) {
710 MCSymbolData &SD = *it;
712 if (it->getFragment() != DF)
715 if (SD.getOffset() > PrevOffset)
716 SD.setOffset(SD.getOffset() + Amt);
721 // FIXME: This is O(N^2), but will be eliminated once we have a smart
722 // MCAsmLayout object.
735 raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
736 OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << *AF.Value
737 << " Kind:" << AF.Kind << ">";
743 void MCFragment::dump() {
744 raw_ostream &OS = llvm::errs();
746 OS << "<MCFragment " << (void*) this << " Offset:" << Offset
747 << " FileSize:" << FileSize;
752 void MCAlignFragment::dump() {
753 raw_ostream &OS = llvm::errs();
755 OS << "<MCAlignFragment ";
756 this->MCFragment::dump();
758 OS << " Alignment:" << getAlignment()
759 << " Value:" << getValue() << " ValueSize:" << getValueSize()
760 << " MaxBytesToEmit:" << getMaxBytesToEmit() << ">";
763 void MCDataFragment::dump() {
764 raw_ostream &OS = llvm::errs();
766 OS << "<MCDataFragment ";
767 this->MCFragment::dump();
770 for (unsigned i = 0, e = getContents().size(); i != e; ++i) {
772 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
774 OS << "] (" << getContents().size() << " bytes)";
776 if (!getFixups().empty()) {
779 for (fixup_iterator it = fixup_begin(), ie = fixup_end(); it != ie; ++it) {
780 if (it != fixup_begin()) OS << ",\n ";
789 void MCFillFragment::dump() {
790 raw_ostream &OS = llvm::errs();
792 OS << "<MCFillFragment ";
793 this->MCFragment::dump();
795 OS << " Value:" << getValue() << " ValueSize:" << getValueSize()
796 << " Count:" << getCount() << ">";
799 void MCOrgFragment::dump() {
800 raw_ostream &OS = llvm::errs();
802 OS << "<MCOrgFragment ";
803 this->MCFragment::dump();
805 OS << " Offset:" << getOffset() << " Value:" << getValue() << ">";
808 void MCZeroFillFragment::dump() {
809 raw_ostream &OS = llvm::errs();
811 OS << "<MCZeroFillFragment ";
812 this->MCFragment::dump();
814 OS << " Size:" << getSize() << " Alignment:" << getAlignment() << ">";
817 void MCSectionData::dump() {
818 raw_ostream &OS = llvm::errs();
820 OS << "<MCSectionData";
821 OS << " Alignment:" << getAlignment() << " Address:" << Address
822 << " Size:" << Size << " FileSize:" << FileSize
823 << " Fragments:[\n ";
824 for (iterator it = begin(), ie = end(); it != ie; ++it) {
825 if (it != begin()) OS << ",\n ";
831 void MCSymbolData::dump() {
832 raw_ostream &OS = llvm::errs();
834 OS << "<MCSymbolData Symbol:" << getSymbol()
835 << " Fragment:" << getFragment() << " Offset:" << getOffset()
836 << " Flags:" << getFlags() << " Index:" << getIndex();
838 OS << " (common, size:" << getCommonSize()
839 << " align: " << getCommonAlignment() << ")";
842 if (isPrivateExtern())
843 OS << " (private extern)";
847 void MCAssembler::dump() {
848 raw_ostream &OS = llvm::errs();
850 OS << "<MCAssembler\n";
851 OS << " Sections:[\n ";
852 for (iterator it = begin(), ie = end(); it != ie; ++it) {
853 if (it != begin()) OS << ",\n ";
859 for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
860 if (it != symbol_begin()) OS << ",\n ";