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/MCSectionMachO.h"
13 #include "llvm/Target/TargetMachOWriterInfo.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/raw_ostream.h"
24 class MachObjectWriter;
26 STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
28 static void WriteFileData(raw_ostream &OS, const MCSectionData &SD,
29 MachObjectWriter &MOW);
31 class MachObjectWriter {
32 // See <mach-o/loader.h>.
34 Header_Magic32 = 0xFEEDFACE,
35 Header_Magic64 = 0xFEEDFACF
38 static const unsigned Header32Size = 28;
39 static const unsigned Header64Size = 32;
40 static const unsigned SegmentLoadCommand32Size = 56;
41 static const unsigned Section32Size = 68;
42 static const unsigned SymtabLoadCommandSize = 24;
43 static const unsigned DysymtabLoadCommandSize = 80;
44 static const unsigned Nlist32Size = 12;
50 enum LoadCommandType {
56 // See <mach-o/nlist.h>.
63 enum SymbolTypeFlags {
64 // If any of these bits are set, then the entry is a stab entry number (see
65 // <mach-o/stab.h>. Otherwise the other masks apply.
66 STF_StabsEntryMask = 0xe0,
70 STF_PrivateExtern = 0x10
73 /// MachSymbolData - Helper struct for containing some precomputed information
75 struct MachSymbolData {
76 MCSymbolData *SymbolData;
80 // Support lexicographic sorting.
81 bool operator<(const MachSymbolData &RHS) const {
82 const std::string &Name = SymbolData->getSymbol().getName();
83 return Name < RHS.SymbolData->getSymbol().getName();
91 MachObjectWriter(raw_ostream &_OS, bool _IsLSB = true)
92 : OS(_OS), IsLSB(_IsLSB) {
95 /// @name Helper Methods
98 void Write8(uint8_t Value) {
102 void Write16(uint16_t Value) {
104 Write8(uint8_t(Value >> 0));
105 Write8(uint8_t(Value >> 8));
107 Write8(uint8_t(Value >> 8));
108 Write8(uint8_t(Value >> 0));
112 void Write32(uint32_t Value) {
114 Write16(uint16_t(Value >> 0));
115 Write16(uint16_t(Value >> 16));
117 Write16(uint16_t(Value >> 16));
118 Write16(uint16_t(Value >> 0));
122 void Write64(uint64_t Value) {
124 Write32(uint32_t(Value >> 0));
125 Write32(uint32_t(Value >> 32));
127 Write32(uint32_t(Value >> 32));
128 Write32(uint32_t(Value >> 0));
132 void WriteZeros(unsigned N) {
133 const char Zeros[16] = { 0 };
135 for (unsigned i = 0, e = N / 16; i != e; ++i)
136 OS << StringRef(Zeros, 16);
138 OS << StringRef(Zeros, N % 16);
141 void WriteString(const StringRef &Str, unsigned ZeroFillSize = 0) {
144 WriteZeros(ZeroFillSize - Str.size());
149 void WriteHeader32(unsigned NumLoadCommands, unsigned LoadCommandsSize) {
150 // struct mach_header (28 bytes)
152 uint64_t Start = OS.tell();
155 Write32(Header_Magic32);
157 // FIXME: Support cputype.
158 Write32(TargetMachOWriterInfo::HDR_CPU_TYPE_I386);
160 // FIXME: Support cpusubtype.
161 Write32(TargetMachOWriterInfo::HDR_CPU_SUBTYPE_I386_ALL);
165 // Object files have a single load command, the segment.
166 Write32(NumLoadCommands);
167 Write32(LoadCommandsSize);
170 assert(OS.tell() - Start == Header32Size);
173 /// WriteSegmentLoadCommand32 - Write a 32-bit segment load command.
175 /// \arg NumSections - The number of sections in this segment.
176 /// \arg SectionDataSize - The total size of the sections.
177 void WriteSegmentLoadCommand32(unsigned NumSections,
178 uint64_t SectionDataStartOffset,
179 uint64_t SectionDataSize) {
180 // struct segment_command (56 bytes)
182 uint64_t Start = OS.tell();
185 Write32(LCT_Segment);
186 Write32(SegmentLoadCommand32Size + NumSections * Section32Size);
189 Write32(0); // vmaddr
190 Write32(SectionDataSize); // vmsize
191 Write32(SectionDataStartOffset); // file offset
192 Write32(SectionDataSize); // file size
193 Write32(0x7); // maxprot
194 Write32(0x7); // initprot
195 Write32(NumSections);
198 assert(OS.tell() - Start == SegmentLoadCommand32Size);
201 void WriteSection32(const MCSectionData &SD, uint64_t FileOffset) {
202 // struct section (68 bytes)
204 uint64_t Start = OS.tell();
207 // FIXME: cast<> support!
208 const MCSectionMachO &Section =
209 static_cast<const MCSectionMachO&>(SD.getSection());
210 WriteString(Section.getSectionName(), 16);
211 WriteString(Section.getSegmentName(), 16);
212 Write32(0); // address
213 Write32(SD.getFileSize()); // size
216 assert(isPowerOf2_32(SD.getAlignment()) && "Invalid alignment!");
217 Write32(Log2_32(SD.getAlignment()));
218 Write32(0); // file offset of relocation entries
219 Write32(0); // number of relocation entrions
220 Write32(Section.getTypeAndAttributes());
221 Write32(0); // reserved1
222 Write32(Section.getStubSize()); // reserved2
224 assert(OS.tell() - Start == Section32Size);
227 void WriteSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols,
228 uint32_t StringTableOffset,
229 uint32_t StringTableSize) {
230 // struct symtab_command (24 bytes)
232 uint64_t Start = OS.tell();
236 Write32(SymtabLoadCommandSize);
237 Write32(SymbolOffset);
239 Write32(StringTableOffset);
240 Write32(StringTableSize);
242 assert(OS.tell() - Start == SymtabLoadCommandSize);
245 void WriteDysymtabLoadCommand(uint32_t FirstLocalSymbol,
246 uint32_t NumLocalSymbols,
247 uint32_t FirstExternalSymbol,
248 uint32_t NumExternalSymbols,
249 uint32_t FirstUndefinedSymbol,
250 uint32_t NumUndefinedSymbols,
251 uint32_t IndirectSymbolOffset,
252 uint32_t NumIndirectSymbols) {
253 // struct dysymtab_command (80 bytes)
255 uint64_t Start = OS.tell();
258 Write32(LCT_Dysymtab);
259 Write32(DysymtabLoadCommandSize);
260 Write32(FirstLocalSymbol);
261 Write32(NumLocalSymbols);
262 Write32(FirstExternalSymbol);
263 Write32(NumExternalSymbols);
264 Write32(FirstUndefinedSymbol);
265 Write32(NumUndefinedSymbols);
266 Write32(0); // tocoff
268 Write32(0); // modtaboff
269 Write32(0); // nmodtab
270 Write32(0); // extrefsymoff
271 Write32(0); // nextrefsyms
272 Write32(IndirectSymbolOffset);
273 Write32(NumIndirectSymbols);
274 Write32(0); // extreloff
275 Write32(0); // nextrel
276 Write32(0); // locreloff
277 Write32(0); // nlocrel
279 assert(OS.tell() - Start == DysymtabLoadCommandSize);
282 void WriteNlist32(MachSymbolData &MSD) {
283 MCSymbol &Symbol = MSD.SymbolData->getSymbol();
286 // Set the N_TYPE bits. See <mach-o/nlist.h>.
288 // FIXME: Are the prebound or indirect fields possible here?
289 if (Symbol.isUndefined())
290 Type = STT_Undefined;
291 else if (Symbol.isAbsolute())
296 // FIXME: Set STAB bits.
298 if (MSD.SymbolData->isPrivateExtern())
299 Type |= STF_PrivateExtern;
302 if (MSD.SymbolData->isExternal() || Symbol.isUndefined())
303 Type |= STF_External;
305 // struct nlist (12 bytes)
307 Write32(MSD.StringIndex);
309 Write8(MSD.SectionIndex);
311 // The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
313 Write16(MSD.SymbolData->getFlags() & 0xFFFF);
315 Write32(0); // FIXME: Value
318 void BindIndirectSymbols(MCAssembler &Asm) {
319 // This is the point where 'as' creates actual symbols for indirect symbols
320 // (in the following two passes). It would be easier for us to do this
321 // sooner when we see the attribute, but that makes getting the order in the
322 // symbol table much more complicated than it is worth.
324 // FIXME: Revisit this when the dust settles.
326 // FIXME: This should not be needed.
327 DenseMap<MCSymbol*, MCSymbolData *> SymbolMap;
329 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
330 ie = Asm.symbol_end(); it != ie; ++it)
331 SymbolMap[&it->getSymbol()] = it;
333 // Bind non lazy symbol pointers first.
334 for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
335 ie = Asm.indirect_symbol_end(); it != ie; ++it) {
336 // FIXME: cast<> support!
337 const MCSectionMachO &Section =
338 static_cast<const MCSectionMachO&>(it->SectionData->getSection());
341 Section.getTypeAndAttributes() & MCSectionMachO::SECTION_TYPE;
342 if (Type != MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS)
345 MCSymbolData *&Entry = SymbolMap[it->Symbol];
347 Entry = new MCSymbolData(*it->Symbol, 0, 0, &Asm);
350 // Then lazy symbol pointers and symbol stubs.
351 for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
352 ie = Asm.indirect_symbol_end(); it != ie; ++it) {
353 // FIXME: cast<> support!
354 const MCSectionMachO &Section =
355 static_cast<const MCSectionMachO&>(it->SectionData->getSection());
358 Section.getTypeAndAttributes() & MCSectionMachO::SECTION_TYPE;
359 if (Type != MCSectionMachO::S_LAZY_SYMBOL_POINTERS &&
360 Type != MCSectionMachO::S_SYMBOL_STUBS)
363 MCSymbolData *&Entry = SymbolMap[it->Symbol];
365 Entry = new MCSymbolData(*it->Symbol, 0, 0, &Asm);
367 // Set the symbol type to undefined lazy, but only on construction.
369 // FIXME: Do not hardcode.
370 Entry->setFlags(Entry->getFlags() | 0x0001);
375 /// ComputeSymbolTable - Compute the symbol table data
377 /// \param StringTable [out] - The string table data.
378 /// \param StringIndexMap [out] - Map from symbol names to offsets in the
380 void ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
381 std::vector<MachSymbolData> &LocalSymbolData,
382 std::vector<MachSymbolData> &ExternalSymbolData,
383 std::vector<MachSymbolData> &UndefinedSymbolData) {
384 // Build section lookup table.
385 DenseMap<const MCSection*, uint8_t> SectionIndexMap;
387 for (MCAssembler::iterator it = Asm.begin(),
388 ie = Asm.end(); it != ie; ++it, ++Index)
389 SectionIndexMap[&it->getSection()] = Index;
390 assert(Index <= 256 && "Too many sections!");
392 // Index 0 is always the empty string.
393 StringMap<uint64_t> StringIndexMap;
394 StringTable += '\x00';
396 // Build the symbol arrays and the string table, but only for non-local
399 // The particular order that we collect the symbols and create the string
400 // table, then sort the symbols is chosen to match 'as'. Even though it
401 // doesn't matter for correctness, this is important for letting us diff .o
403 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
404 ie = Asm.symbol_end(); it != ie; ++it) {
405 MCSymbol &Symbol = it->getSymbol();
407 if (!it->isExternal() && !Symbol.isUndefined())
410 uint64_t &Entry = StringIndexMap[Symbol.getName()];
412 Entry = StringTable.size();
413 StringTable += Symbol.getName();
414 StringTable += '\x00';
419 MSD.StringIndex = Entry;
421 if (Symbol.isUndefined()) {
422 MSD.SectionIndex = 0;
423 UndefinedSymbolData.push_back(MSD);
424 } else if (Symbol.isAbsolute()) {
425 MSD.SectionIndex = 0;
426 ExternalSymbolData.push_back(MSD);
428 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
429 assert(MSD.SectionIndex && "Invalid section index!");
430 ExternalSymbolData.push_back(MSD);
434 // Now add the data for local symbols.
435 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
436 ie = Asm.symbol_end(); it != ie; ++it) {
437 MCSymbol &Symbol = it->getSymbol();
439 if (it->isExternal() || Symbol.isUndefined())
442 uint64_t &Entry = StringIndexMap[Symbol.getName()];
444 Entry = StringTable.size();
445 StringTable += Symbol.getName();
446 StringTable += '\x00';
451 MSD.StringIndex = Entry;
453 if (Symbol.isAbsolute()) {
454 MSD.SectionIndex = 0;
455 LocalSymbolData.push_back(MSD);
457 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
458 assert(MSD.SectionIndex && "Invalid section index!");
459 LocalSymbolData.push_back(MSD);
463 // External and undefined symbols are required to be in lexicographic order.
464 std::sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
465 std::sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end());
467 // The string table is padded to a multiple of 4.
469 // FIXME: Check to see if this varies per arch.
470 while (StringTable.size() % 4)
471 StringTable += '\x00';
474 void WriteObject(MCAssembler &Asm) {
475 unsigned NumSections = Asm.size();
477 BindIndirectSymbols(Asm);
479 // Compute symbol table information.
480 SmallString<256> StringTable;
481 std::vector<MachSymbolData> LocalSymbolData;
482 std::vector<MachSymbolData> ExternalSymbolData;
483 std::vector<MachSymbolData> UndefinedSymbolData;
484 unsigned NumSymbols = Asm.symbol_size();
486 // No symbol table command is written if there are no symbols.
488 ComputeSymbolTable(Asm, StringTable, LocalSymbolData, ExternalSymbolData,
489 UndefinedSymbolData);
491 // Compute the file offsets for all the sections in advance, so that we can
492 // write things out in order.
493 SmallVector<uint64_t, 16> SectionFileOffsets;
494 SectionFileOffsets.resize(NumSections);
496 // The section data starts after the header, the segment load command (and
497 // section headers) and the symbol table.
498 unsigned NumLoadCommands = 1;
499 uint64_t LoadCommandsSize =
500 SegmentLoadCommand32Size + NumSections * Section32Size;
502 // Add the symbol table load command sizes, if used.
504 NumLoadCommands += 2;
505 LoadCommandsSize += SymtabLoadCommandSize + DysymtabLoadCommandSize;
508 uint64_t FileOffset = Header32Size + LoadCommandsSize;
509 uint64_t SectionDataStartOffset = FileOffset;
510 uint64_t SectionDataSize = 0;
512 for (MCAssembler::iterator it = Asm.begin(),
513 ie = Asm.end(); it != ie; ++it, ++Index) {
514 SectionFileOffsets[Index] = FileOffset;
515 FileOffset += it->getFileSize();
516 SectionDataSize += it->getFileSize();
519 // Write the prolog, starting with the header and load command...
520 WriteHeader32(NumLoadCommands, LoadCommandsSize);
521 WriteSegmentLoadCommand32(NumSections, SectionDataStartOffset,
524 // ... and then the section headers.
526 for (MCAssembler::iterator it = Asm.begin(),
527 ie = Asm.end(); it != ie; ++it, ++Index)
528 WriteSection32(*it, SectionFileOffsets[Index]);
530 // Write the symbol table load command, if used.
532 unsigned FirstLocalSymbol = 0;
533 unsigned NumLocalSymbols = LocalSymbolData.size();
534 unsigned FirstExternalSymbol = FirstLocalSymbol + NumLocalSymbols;
535 unsigned NumExternalSymbols = ExternalSymbolData.size();
536 unsigned FirstUndefinedSymbol = FirstExternalSymbol + NumExternalSymbols;
537 unsigned NumUndefinedSymbols = UndefinedSymbolData.size();
538 unsigned NumIndirectSymbols = Asm.indirect_symbol_size();
539 unsigned NumSymTabSymbols =
540 NumLocalSymbols + NumExternalSymbols + NumUndefinedSymbols;
541 uint64_t IndirectSymbolSize = NumIndirectSymbols * 4;
542 uint64_t IndirectSymbolOffset = 0;
544 // If used, the indirect symbols are written after the section data.
545 if (NumIndirectSymbols)
546 IndirectSymbolOffset = SectionDataStartOffset + SectionDataSize;
548 // The symbol table is written after the indirect symbol data.
549 uint64_t SymbolTableOffset =
550 SectionDataStartOffset + SectionDataSize + IndirectSymbolSize;
552 // The string table is written after symbol table.
553 uint64_t StringTableOffset =
554 SymbolTableOffset + NumSymTabSymbols * Nlist32Size;
555 WriteSymtabLoadCommand(SymbolTableOffset, NumSymTabSymbols,
556 StringTableOffset, StringTable.size());
558 WriteDysymtabLoadCommand(FirstLocalSymbol, NumLocalSymbols,
559 FirstExternalSymbol, NumExternalSymbols,
560 FirstUndefinedSymbol, NumUndefinedSymbols,
561 IndirectSymbolOffset, NumIndirectSymbols);
564 // Write the actual section data.
565 for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
566 WriteFileData(OS, *it, *this);
568 // Write the symbol table data, if used.
570 // Write the indirect symbol entries.
572 // FIXME: We need the symbol index map for this.
573 for (unsigned i = 0, e = Asm.indirect_symbol_size(); i != e; ++i)
576 // FIXME: Check that offsets match computed ones.
578 // Write the symbol table entries.
579 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
580 WriteNlist32(LocalSymbolData[i]);
581 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
582 WriteNlist32(ExternalSymbolData[i]);
583 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
584 WriteNlist32(UndefinedSymbolData[i]);
586 // Write the string table.
587 OS << StringTable.str();
594 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
597 MCFragment::MCFragment(FragmentType _Kind, MCSectionData *SD)
599 FileSize(~UINT64_C(0))
602 SD->getFragmentList().push_back(this);
605 MCFragment::~MCFragment() {
610 MCSectionData::MCSectionData() : Section(*(MCSection*)0) {}
612 MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
615 FileSize(~UINT64_C(0))
618 A->getSectionList().push_back(this);
623 MCSymbolData::MCSymbolData() : Symbol(*(MCSymbol*)0) {}
625 MCSymbolData::MCSymbolData(MCSymbol &_Symbol, MCFragment *_Fragment,
626 uint64_t _Offset, MCAssembler *A)
627 : Symbol(_Symbol), Fragment(_Fragment), Offset(_Offset),
628 IsExternal(false), IsPrivateExtern(false), Flags(0)
631 A->getSymbolList().push_back(this);
636 MCAssembler::MCAssembler(raw_ostream &_OS) : OS(_OS) {}
638 MCAssembler::~MCAssembler() {
641 void MCAssembler::LayoutSection(MCSectionData &SD) {
644 for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
649 // Evaluate fragment size.
650 switch (F.getKind()) {
651 case MCFragment::FT_Align: {
652 MCAlignFragment &AF = cast<MCAlignFragment>(F);
654 uint64_t AlignedOffset = RoundUpToAlignment(Offset, AF.getAlignment());
655 uint64_t PaddingBytes = AlignedOffset - Offset;
657 if (PaddingBytes > AF.getMaxBytesToEmit())
660 AF.setFileSize(PaddingBytes);
664 case MCFragment::FT_Data:
665 case MCFragment::FT_Fill:
666 F.setFileSize(F.getMaxFileSize());
669 case MCFragment::FT_Org: {
670 MCOrgFragment &OF = cast<MCOrgFragment>(F);
672 if (!OF.getOffset().isAbsolute())
673 llvm_unreachable("FIXME: Not yet implemented!");
674 uint64_t OrgOffset = OF.getOffset().getConstant();
676 // FIXME: We need a way to communicate this error.
677 if (OrgOffset < Offset)
678 llvm_report_error("invalid .org offset '" + Twine(OrgOffset) +
679 "' (section offset '" + Twine(Offset) + "'");
681 F.setFileSize(OrgOffset - Offset);
686 Offset += F.getFileSize();
689 // FIXME: Pad section?
690 SD.setFileSize(Offset);
693 /// WriteFileData - Write the \arg F data to the output file.
694 static void WriteFileData(raw_ostream &OS, const MCFragment &F,
695 MachObjectWriter &MOW) {
696 uint64_t Start = OS.tell();
701 // FIXME: Embed in fragments instead?
702 switch (F.getKind()) {
703 case MCFragment::FT_Align: {
704 MCAlignFragment &AF = cast<MCAlignFragment>(F);
705 uint64_t Count = AF.getFileSize() / AF.getValueSize();
707 // FIXME: This error shouldn't actually occur (the front end should emit
708 // multiple .align directives to enforce the semantics it wants), but is
709 // severe enough that we want to report it. How to handle this?
710 if (Count * AF.getValueSize() != AF.getFileSize())
711 llvm_report_error("undefined .align directive, value size '" +
712 Twine(AF.getValueSize()) +
713 "' is not a divisor of padding size '" +
714 Twine(AF.getFileSize()) + "'");
716 for (uint64_t i = 0; i != Count; ++i) {
717 switch (AF.getValueSize()) {
719 assert(0 && "Invalid size!");
720 case 1: MOW.Write8 (uint8_t (AF.getValue())); break;
721 case 2: MOW.Write16(uint16_t(AF.getValue())); break;
722 case 4: MOW.Write32(uint32_t(AF.getValue())); break;
723 case 8: MOW.Write64(uint64_t(AF.getValue())); break;
729 case MCFragment::FT_Data:
730 OS << cast<MCDataFragment>(F).getContents().str();
733 case MCFragment::FT_Fill: {
734 MCFillFragment &FF = cast<MCFillFragment>(F);
736 if (!FF.getValue().isAbsolute())
737 llvm_unreachable("FIXME: Not yet implemented!");
738 int64_t Value = FF.getValue().getConstant();
740 for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
741 switch (FF.getValueSize()) {
743 assert(0 && "Invalid size!");
744 case 1: MOW.Write8 (uint8_t (Value)); break;
745 case 2: MOW.Write16(uint16_t(Value)); break;
746 case 4: MOW.Write32(uint32_t(Value)); break;
747 case 8: MOW.Write64(uint64_t(Value)); break;
753 case MCFragment::FT_Org: {
754 MCOrgFragment &OF = cast<MCOrgFragment>(F);
756 for (uint64_t i = 0, e = OF.getFileSize(); i != e; ++i)
757 MOW.Write8(uint8_t(OF.getValue()));
763 assert(OS.tell() - Start == F.getFileSize());
766 /// WriteFileData - Write the \arg SD data to the output file.
767 static void WriteFileData(raw_ostream &OS, const MCSectionData &SD,
768 MachObjectWriter &MOW) {
769 uint64_t Start = OS.tell();
772 for (MCSectionData::const_iterator it = SD.begin(),
773 ie = SD.end(); it != ie; ++it)
774 WriteFileData(OS, *it, MOW);
776 assert(OS.tell() - Start == SD.getFileSize());
779 void MCAssembler::Finish() {
780 // Layout the sections and fragments.
781 for (iterator it = begin(), ie = end(); it != ie; ++it)
784 // Write the object file.
785 MachObjectWriter MOW(OS);
786 MOW.WriteObject(*this);