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 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCSectionMachO.h"
12 #include "llvm/Target/TargetMachOWriterInfo.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/Support/raw_ostream.h"
22 class MachObjectWriter;
24 static void WriteFileData(raw_ostream &OS, const MCSectionData &SD,
25 MachObjectWriter &MOW);
27 class MachObjectWriter {
28 // See <mach-o/loader.h>.
30 Header_Magic32 = 0xFEEDFACE,
31 Header_Magic64 = 0xFEEDFACF
34 static const unsigned Header32Size = 28;
35 static const unsigned Header64Size = 32;
36 static const unsigned SegmentLoadCommand32Size = 56;
37 static const unsigned Section32Size = 68;
38 static const unsigned SymtabLoadCommandSize = 24;
39 static const unsigned DysymtabLoadCommandSize = 80;
40 static const unsigned Nlist32Size = 12;
46 enum LoadCommandType {
52 // See <mach-o/nlist.h>.
59 enum SymbolTypeFlags {
60 // If any of these bits are set, then the entry is a stab entry number (see
61 // <mach-o/stab.h>. Otherwise the other masks apply.
62 STF_StabsEntryMask = 0xe0,
66 STF_PrivateExtern = 0x10
69 /// MachSymbolData - Helper struct for containing some precomputed information
71 struct MachSymbolData {
72 MCSymbolData *SymbolData;
76 // Support lexicographic sorting.
77 bool operator<(const MachSymbolData &RHS) const {
78 const std::string &Name = SymbolData->getSymbol().getName();
79 return Name < RHS.SymbolData->getSymbol().getName();
87 MachObjectWriter(raw_ostream &_OS, bool _IsLSB = true)
88 : OS(_OS), IsLSB(_IsLSB) {
91 /// @name Helper Methods
94 void Write8(uint8_t Value) {
98 void Write16(uint16_t Value) {
100 Write8(uint8_t(Value >> 0));
101 Write8(uint8_t(Value >> 8));
103 Write8(uint8_t(Value >> 8));
104 Write8(uint8_t(Value >> 0));
108 void Write32(uint32_t Value) {
110 Write16(uint16_t(Value >> 0));
111 Write16(uint16_t(Value >> 16));
113 Write16(uint16_t(Value >> 16));
114 Write16(uint16_t(Value >> 0));
118 void Write64(uint64_t Value) {
120 Write32(uint32_t(Value >> 0));
121 Write32(uint32_t(Value >> 32));
123 Write32(uint32_t(Value >> 32));
124 Write32(uint32_t(Value >> 0));
128 void WriteZeros(unsigned N) {
129 const char Zeros[16] = { 0 };
131 for (unsigned i = 0, e = N / 16; i != e; ++i)
132 OS << StringRef(Zeros, 16);
134 OS << StringRef(Zeros, N % 16);
137 void WriteString(const StringRef &Str, unsigned ZeroFillSize = 0) {
140 WriteZeros(ZeroFillSize - Str.size());
145 void WriteHeader32(unsigned NumLoadCommands, unsigned LoadCommandsSize) {
146 // struct mach_header (28 bytes)
148 uint64_t Start = OS.tell();
151 Write32(Header_Magic32);
153 // FIXME: Support cputype.
154 Write32(TargetMachOWriterInfo::HDR_CPU_TYPE_I386);
156 // FIXME: Support cpusubtype.
157 Write32(TargetMachOWriterInfo::HDR_CPU_SUBTYPE_I386_ALL);
161 // Object files have a single load command, the segment.
162 Write32(NumLoadCommands);
163 Write32(LoadCommandsSize);
166 assert(OS.tell() - Start == Header32Size);
169 /// WriteSegmentLoadCommand32 - Write a 32-bit segment load command.
171 /// \arg NumSections - The number of sections in this segment.
172 /// \arg SectionDataSize - The total size of the sections.
173 void WriteSegmentLoadCommand32(unsigned NumSections,
174 uint64_t SectionDataStartOffset,
175 uint64_t SectionDataSize) {
176 // struct segment_command (56 bytes)
178 uint64_t Start = OS.tell();
181 Write32(LCT_Segment);
182 Write32(SegmentLoadCommand32Size + NumSections * Section32Size);
185 Write32(0); // vmaddr
186 Write32(SectionDataSize); // vmsize
187 Write32(SectionDataStartOffset); // file offset
188 Write32(SectionDataSize); // file size
189 Write32(0x7); // maxprot
190 Write32(0x7); // initprot
191 Write32(NumSections);
194 assert(OS.tell() - Start == SegmentLoadCommand32Size);
197 void WriteSection32(const MCSectionData &SD, uint64_t FileOffset) {
198 // struct section (68 bytes)
200 uint64_t Start = OS.tell();
203 // FIXME: cast<> support!
204 const MCSectionMachO &Section =
205 static_cast<const MCSectionMachO&>(SD.getSection());
206 WriteString(Section.getSectionName(), 16);
207 WriteString(Section.getSegmentName(), 16);
208 Write32(0); // address
209 Write32(SD.getFileSize()); // size
212 assert(isPowerOf2_32(SD.getAlignment()) && "Invalid alignment!");
213 Write32(Log2_32(SD.getAlignment()));
214 Write32(0); // file offset of relocation entries
215 Write32(0); // number of relocation entrions
216 Write32(Section.getTypeAndAttributes());
217 Write32(0); // reserved1
218 Write32(Section.getStubSize()); // reserved2
220 assert(OS.tell() - Start == Section32Size);
223 void WriteSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols,
224 uint32_t StringTableOffset,
225 uint32_t StringTableSize) {
226 // struct symtab_command (24 bytes)
228 uint64_t Start = OS.tell();
232 Write32(SymtabLoadCommandSize);
233 Write32(SymbolOffset);
235 Write32(StringTableOffset);
236 Write32(StringTableSize);
238 assert(OS.tell() - Start == SymtabLoadCommandSize);
241 void WriteDysymtabLoadCommand(uint32_t FirstLocalSymbol,
242 uint32_t NumLocalSymbols,
243 uint32_t FirstExternalSymbol,
244 uint32_t NumExternalSymbols,
245 uint32_t FirstUndefinedSymbol,
246 uint32_t NumUndefinedSymbols,
247 uint32_t IndirectSymbolOffset,
248 uint32_t NumIndirectSymbols) {
249 // struct dysymtab_command (80 bytes)
251 uint64_t Start = OS.tell();
254 Write32(LCT_Dysymtab);
255 Write32(DysymtabLoadCommandSize);
256 Write32(FirstLocalSymbol);
257 Write32(NumLocalSymbols);
258 Write32(FirstExternalSymbol);
259 Write32(NumExternalSymbols);
260 Write32(FirstUndefinedSymbol);
261 Write32(NumUndefinedSymbols);
262 Write32(0); // tocoff
264 Write32(0); // modtaboff
265 Write32(0); // nmodtab
266 Write32(0); // extrefsymoff
267 Write32(0); // nextrefsyms
268 Write32(IndirectSymbolOffset);
269 Write32(NumIndirectSymbols);
270 Write32(0); // extreloff
271 Write32(0); // nextrel
272 Write32(0); // locreloff
273 Write32(0); // nlocrel
275 assert(OS.tell() - Start == DysymtabLoadCommandSize);
278 void WriteNlist32(MachSymbolData &MSD) {
279 MCSymbol &Symbol = MSD.SymbolData->getSymbol();
282 // Set the N_TYPE bits. See <mach-o/nlist.h>.
284 // FIXME: Are the prebound or indirect fields possible here?
285 if (Symbol.isUndefined())
286 Type = STT_Undefined;
287 else if (Symbol.isAbsolute())
292 // FIXME: Set STAB bits.
294 if (MSD.SymbolData->isPrivateExtern())
295 Type |= STF_PrivateExtern;
298 if (MSD.SymbolData->isExternal() || Symbol.isUndefined())
299 Type |= STF_External;
301 // struct nlist (12 bytes)
303 Write32(MSD.StringIndex);
305 Write8(MSD.SectionIndex);
307 // The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
309 Write16(MSD.SymbolData->getFlags() & 0xFFFF);
311 Write32(0); // FIXME: Value
314 void BindIndirectSymbols(MCAssembler &Asm) {
315 // This is the point where 'as' creates actual symbols for indirect symbols
316 // (in the following two passes). It would be easier for us to do this
317 // sooner when we see the attribute, but that makes getting the order in the
318 // symbol table much more complicated than it is worth.
320 // FIXME: Revisit this when the dust settles.
322 // FIXME: This should not be needed.
323 DenseMap<MCSymbol*, MCSymbolData *> SymbolMap;
325 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
326 ie = Asm.symbol_end(); it != ie; ++it)
327 SymbolMap[&it->getSymbol()] = it;
329 // Bind non lazy symbol pointers first.
330 for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
331 ie = Asm.indirect_symbol_end(); it != ie; ++it) {
332 // FIXME: cast<> support!
333 const MCSectionMachO &Section =
334 static_cast<const MCSectionMachO&>(it->SectionData->getSection());
337 Section.getTypeAndAttributes() & MCSectionMachO::SECTION_TYPE;
338 if (Type != MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS)
341 MCSymbolData *&Entry = SymbolMap[it->Symbol];
343 Entry = new MCSymbolData(*it->Symbol, 0, 0, &Asm);
346 // Then lazy symbol pointers and symbol stubs.
347 for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
348 ie = Asm.indirect_symbol_end(); it != ie; ++it) {
349 // FIXME: cast<> support!
350 const MCSectionMachO &Section =
351 static_cast<const MCSectionMachO&>(it->SectionData->getSection());
354 Section.getTypeAndAttributes() & MCSectionMachO::SECTION_TYPE;
355 if (Type != MCSectionMachO::S_LAZY_SYMBOL_POINTERS &&
356 Type != MCSectionMachO::S_SYMBOL_STUBS)
359 MCSymbolData *&Entry = SymbolMap[it->Symbol];
361 Entry = new MCSymbolData(*it->Symbol, 0, 0, &Asm);
363 // Set the symbol type to undefined lazy, but only on construction.
365 // FIXME: Do not hardcode.
366 Entry->setFlags(Entry->getFlags() | 0x0001);
371 /// ComputeSymbolTable - Compute the symbol table data
373 /// \param StringTable [out] - The string table data.
374 /// \param StringIndexMap [out] - Map from symbol names to offsets in the
376 void ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
377 std::vector<MachSymbolData> &LocalSymbolData,
378 std::vector<MachSymbolData> &ExternalSymbolData,
379 std::vector<MachSymbolData> &UndefinedSymbolData) {
380 // Build section lookup table.
381 DenseMap<const MCSection*, uint8_t> SectionIndexMap;
383 for (MCAssembler::iterator it = Asm.begin(),
384 ie = Asm.end(); it != ie; ++it, ++Index)
385 SectionIndexMap[&it->getSection()] = Index;
386 assert(Index <= 256 && "Too many sections!");
388 // Index 0 is always the empty string.
389 StringMap<uint64_t> StringIndexMap;
390 StringTable += '\x00';
392 // Build the symbol arrays and the string table, but only for non-local
395 // The particular order that we collect the symbols and create the string
396 // table, then sort the symbols is chosen to match 'as'. Even though it
397 // doesn't matter for correctness, this is important for letting us diff .o
399 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
400 ie = Asm.symbol_end(); it != ie; ++it) {
401 MCSymbol &Symbol = it->getSymbol();
403 if (!it->isExternal() && !Symbol.isUndefined())
406 uint64_t &Entry = StringIndexMap[Symbol.getName()];
408 Entry = StringTable.size();
409 StringTable += Symbol.getName();
410 StringTable += '\x00';
415 MSD.StringIndex = Entry;
417 if (Symbol.isUndefined()) {
418 MSD.SectionIndex = 0;
419 UndefinedSymbolData.push_back(MSD);
420 } else if (Symbol.isAbsolute()) {
421 MSD.SectionIndex = 0;
422 ExternalSymbolData.push_back(MSD);
424 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
425 assert(MSD.SectionIndex && "Invalid section index!");
426 ExternalSymbolData.push_back(MSD);
430 // Now add the data for local symbols.
431 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
432 ie = Asm.symbol_end(); it != ie; ++it) {
433 MCSymbol &Symbol = it->getSymbol();
435 if (it->isExternal() || Symbol.isUndefined())
438 uint64_t &Entry = StringIndexMap[Symbol.getName()];
440 Entry = StringTable.size();
441 StringTable += Symbol.getName();
442 StringTable += '\x00';
447 MSD.StringIndex = Entry;
449 if (Symbol.isAbsolute()) {
450 MSD.SectionIndex = 0;
451 LocalSymbolData.push_back(MSD);
453 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
454 assert(MSD.SectionIndex && "Invalid section index!");
455 LocalSymbolData.push_back(MSD);
459 // External and undefined symbols are required to be in lexicographic order.
460 std::sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
461 std::sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end());
463 // The string table is padded to a multiple of 4.
465 // FIXME: Check to see if this varies per arch.
466 while (StringTable.size() % 4)
467 StringTable += '\x00';
470 void WriteObject(MCAssembler &Asm) {
471 unsigned NumSections = Asm.size();
473 BindIndirectSymbols(Asm);
475 // Compute symbol table information.
476 SmallString<256> StringTable;
477 std::vector<MachSymbolData> LocalSymbolData;
478 std::vector<MachSymbolData> ExternalSymbolData;
479 std::vector<MachSymbolData> UndefinedSymbolData;
480 unsigned NumSymbols = Asm.symbol_size();
482 // No symbol table command is written if there are no symbols.
484 ComputeSymbolTable(Asm, StringTable, LocalSymbolData, ExternalSymbolData,
485 UndefinedSymbolData);
487 // Compute the file offsets for all the sections in advance, so that we can
488 // write things out in order.
489 SmallVector<uint64_t, 16> SectionFileOffsets;
490 SectionFileOffsets.resize(NumSections);
492 // The section data starts after the header, the segment load command (and
493 // section headers) and the symbol table.
494 unsigned NumLoadCommands = 1;
495 uint64_t LoadCommandsSize =
496 SegmentLoadCommand32Size + NumSections * Section32Size;
498 // Add the symbol table load command sizes, if used.
500 NumLoadCommands += 2;
501 LoadCommandsSize += SymtabLoadCommandSize + DysymtabLoadCommandSize;
504 uint64_t FileOffset = Header32Size + LoadCommandsSize;
505 uint64_t SectionDataStartOffset = FileOffset;
506 uint64_t SectionDataSize = 0;
508 for (MCAssembler::iterator it = Asm.begin(),
509 ie = Asm.end(); it != ie; ++it, ++Index) {
510 SectionFileOffsets[Index] = FileOffset;
511 FileOffset += it->getFileSize();
512 SectionDataSize += it->getFileSize();
515 // Write the prolog, starting with the header and load command...
516 WriteHeader32(NumLoadCommands, LoadCommandsSize);
517 WriteSegmentLoadCommand32(NumSections, SectionDataStartOffset,
520 // ... and then the section headers.
522 for (MCAssembler::iterator it = Asm.begin(),
523 ie = Asm.end(); it != ie; ++it, ++Index)
524 WriteSection32(*it, SectionFileOffsets[Index]);
526 // Write the symbol table load command, if used.
528 unsigned FirstLocalSymbol = 0;
529 unsigned NumLocalSymbols = LocalSymbolData.size();
530 unsigned FirstExternalSymbol = FirstLocalSymbol + NumLocalSymbols;
531 unsigned NumExternalSymbols = ExternalSymbolData.size();
532 unsigned FirstUndefinedSymbol = FirstExternalSymbol + NumExternalSymbols;
533 unsigned NumUndefinedSymbols = UndefinedSymbolData.size();
534 unsigned NumIndirectSymbols = Asm.indirect_symbol_size();
535 unsigned NumSymTabSymbols =
536 NumLocalSymbols + NumExternalSymbols + NumUndefinedSymbols;
537 uint64_t IndirectSymbolSize = NumIndirectSymbols * 4;
538 uint64_t IndirectSymbolOffset = 0;
540 // If used, the indirect symbols are written after the section data.
541 if (NumIndirectSymbols)
542 IndirectSymbolOffset = SectionDataStartOffset + SectionDataSize;
544 // The symbol table is written after the indirect symbol data.
545 uint64_t SymbolTableOffset =
546 SectionDataStartOffset + SectionDataSize + IndirectSymbolSize;
548 // The string table is written after symbol table.
549 uint64_t StringTableOffset =
550 SymbolTableOffset + NumSymTabSymbols * Nlist32Size;
551 WriteSymtabLoadCommand(SymbolTableOffset, NumSymTabSymbols,
552 StringTableOffset, StringTable.size());
554 WriteDysymtabLoadCommand(FirstLocalSymbol, NumLocalSymbols,
555 FirstExternalSymbol, NumExternalSymbols,
556 FirstUndefinedSymbol, NumUndefinedSymbols,
557 IndirectSymbolOffset, NumIndirectSymbols);
560 // Write the actual section data.
561 for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
562 WriteFileData(OS, *it, *this);
564 // Write the symbol table data, if used.
566 // Write the indirect symbol entries.
568 // FIXME: We need the symbol index map for this.
569 for (unsigned i = 0, e = Asm.indirect_symbol_size(); i != e; ++i)
572 // FIXME: Check that offsets match computed ones.
574 // Write the symbol table entries.
575 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
576 WriteNlist32(LocalSymbolData[i]);
577 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
578 WriteNlist32(ExternalSymbolData[i]);
579 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
580 WriteNlist32(UndefinedSymbolData[i]);
582 // Write the string table.
583 OS << StringTable.str();
590 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
593 MCFragment::MCFragment(FragmentType _Kind, MCSectionData *SD)
595 FileSize(~UINT64_C(0))
598 SD->getFragmentList().push_back(this);
601 MCFragment::~MCFragment() {
606 MCSectionData::MCSectionData() : Section(*(MCSection*)0) {}
608 MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
611 FileSize(~UINT64_C(0))
614 A->getSectionList().push_back(this);
619 MCSymbolData::MCSymbolData() : Symbol(*(MCSymbol*)0) {}
621 MCSymbolData::MCSymbolData(MCSymbol &_Symbol, MCFragment *_Fragment,
622 uint64_t _Offset, MCAssembler *A)
623 : Symbol(_Symbol), Fragment(_Fragment), Offset(_Offset),
624 IsExternal(false), IsPrivateExtern(false), Flags(0)
627 A->getSymbolList().push_back(this);
632 MCAssembler::MCAssembler(raw_ostream &_OS) : OS(_OS) {}
634 MCAssembler::~MCAssembler() {
637 void MCAssembler::LayoutSection(MCSectionData &SD) {
640 for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
645 // Evaluate fragment size.
646 switch (F.getKind()) {
647 case MCFragment::FT_Align: {
648 MCAlignFragment &AF = cast<MCAlignFragment>(F);
650 uint64_t AlignedOffset = RoundUpToAlignment(Offset, AF.getAlignment());
651 uint64_t PaddingBytes = AlignedOffset - Offset;
653 if (PaddingBytes > AF.getMaxBytesToEmit())
656 AF.setFileSize(PaddingBytes);
660 case MCFragment::FT_Data:
661 case MCFragment::FT_Fill:
662 F.setFileSize(F.getMaxFileSize());
665 case MCFragment::FT_Org: {
666 MCOrgFragment &OF = cast<MCOrgFragment>(F);
668 if (!OF.getOffset().isAbsolute())
669 llvm_unreachable("FIXME: Not yet implemented!");
670 uint64_t OrgOffset = OF.getOffset().getConstant();
672 // FIXME: We need a way to communicate this error.
673 if (OrgOffset < Offset)
674 llvm_report_error("invalid .org offset '" + Twine(OrgOffset) +
675 "' (section offset '" + Twine(Offset) + "'");
677 F.setFileSize(OrgOffset - Offset);
682 Offset += F.getFileSize();
685 // FIXME: Pad section?
686 SD.setFileSize(Offset);
689 /// WriteFileData - Write the \arg F data to the output file.
690 static void WriteFileData(raw_ostream &OS, const MCFragment &F,
691 MachObjectWriter &MOW) {
692 uint64_t Start = OS.tell();
695 // FIXME: Embed in fragments instead?
696 switch (F.getKind()) {
697 case MCFragment::FT_Align: {
698 MCAlignFragment &AF = cast<MCAlignFragment>(F);
699 uint64_t Count = AF.getFileSize() / AF.getValueSize();
701 // FIXME: This error shouldn't actually occur (the front end should emit
702 // multiple .align directives to enforce the semantics it wants), but is
703 // severe enough that we want to report it. How to handle this?
704 if (Count * AF.getValueSize() != AF.getFileSize())
705 llvm_report_error("undefined .align directive, value size '" +
706 Twine(AF.getValueSize()) +
707 "' is not a divisor of padding size '" +
708 Twine(AF.getFileSize()) + "'");
710 for (uint64_t i = 0; i != Count; ++i) {
711 switch (AF.getValueSize()) {
713 assert(0 && "Invalid size!");
714 case 1: MOW.Write8 (uint8_t (AF.getValue())); break;
715 case 2: MOW.Write16(uint16_t(AF.getValue())); break;
716 case 4: MOW.Write32(uint32_t(AF.getValue())); break;
717 case 8: MOW.Write64(uint64_t(AF.getValue())); break;
723 case MCFragment::FT_Data:
724 OS << cast<MCDataFragment>(F).getContents().str();
727 case MCFragment::FT_Fill: {
728 MCFillFragment &FF = cast<MCFillFragment>(F);
730 if (!FF.getValue().isAbsolute())
731 llvm_unreachable("FIXME: Not yet implemented!");
732 int64_t Value = FF.getValue().getConstant();
734 for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
735 switch (FF.getValueSize()) {
737 assert(0 && "Invalid size!");
738 case 1: MOW.Write8 (uint8_t (Value)); break;
739 case 2: MOW.Write16(uint16_t(Value)); break;
740 case 4: MOW.Write32(uint32_t(Value)); break;
741 case 8: MOW.Write64(uint64_t(Value)); break;
747 case MCFragment::FT_Org: {
748 MCOrgFragment &OF = cast<MCOrgFragment>(F);
750 for (uint64_t i = 0, e = OF.getFileSize(); i != e; ++i)
751 MOW.Write8(uint8_t(OF.getValue()));
757 assert(OS.tell() - Start == F.getFileSize());
760 /// WriteFileData - Write the \arg SD data to the output file.
761 static void WriteFileData(raw_ostream &OS, const MCSectionData &SD,
762 MachObjectWriter &MOW) {
763 uint64_t Start = OS.tell();
766 for (MCSectionData::const_iterator it = SD.begin(),
767 ie = SD.end(); it != ie; ++it)
768 WriteFileData(OS, *it, MOW);
770 assert(OS.tell() - Start == SD.getFileSize());
773 void MCAssembler::Finish() {
774 // Layout the sections and fragments.
775 for (iterator it = begin(), ie = end(); it != ie; ++it)
778 // Write the object file.
779 MachObjectWriter MOW(OS);
780 MOW.WriteObject(*this);