1 //===- lib/MC/MCMachOStreamer.cpp - Mach-O Object Output ------------===//
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/MCStreamer.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCCodeEmitter.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCObjectStreamer.h"
18 #include "llvm/MC/MCSection.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/MC/MCMachOSymbolFlags.h"
21 #include "llvm/MC/MCSectionMachO.h"
22 #include "llvm/MC/MCDwarf.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/Target/TargetAsmBackend.h"
31 class MCMachOStreamer : public MCObjectStreamer {
33 void EmitInstToFragment(const MCInst &Inst);
34 void EmitInstToData(const MCInst &Inst);
35 // FIXME: These will likely moved to a better place.
36 void MakeLineEntryForSection(const MCSection *Section);
37 const MCExpr * MakeStartMinusEndExpr(MCSymbol *Start, MCSymbol *End,
39 void EmitDwarfFileTable(void);
42 MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
43 raw_ostream &OS, MCCodeEmitter *Emitter)
44 : MCObjectStreamer(Context, TAB, OS, Emitter) {}
46 /// @name MCStreamer Interface
49 virtual void EmitLabel(MCSymbol *Symbol);
50 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
51 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
52 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
53 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
54 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
55 unsigned ByteAlignment);
56 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
57 assert(0 && "macho doesn't support this directive");
59 virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
60 assert(0 && "macho doesn't support this directive");
62 virtual void EmitCOFFSymbolType(int Type) {
63 assert(0 && "macho doesn't support this directive");
65 virtual void EndCOFFSymbolDef() {
66 assert(0 && "macho doesn't support this directive");
68 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
69 assert(0 && "macho doesn't support this directive");
71 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
72 assert(0 && "macho doesn't support this directive");
74 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
75 unsigned Size = 0, unsigned ByteAlignment = 0);
76 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
77 uint64_t Size, unsigned ByteAlignment = 0);
78 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
79 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
80 virtual void EmitGPRel32Value(const MCExpr *Value) {
81 assert(0 && "macho doesn't support this directive");
83 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
84 unsigned ValueSize = 1,
85 unsigned MaxBytesToEmit = 0);
86 virtual void EmitCodeAlignment(unsigned ByteAlignment,
87 unsigned MaxBytesToEmit = 0);
88 virtual void EmitValueToOffset(const MCExpr *Offset,
89 unsigned char Value = 0);
91 virtual void EmitFileDirective(StringRef Filename) {
92 // FIXME: Just ignore the .file; it isn't important enough to fail the
95 //report_fatal_error("unsupported directive: '.file'");
97 virtual void EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
98 // FIXME: Just ignore the .file; it isn't important enough to fail the
101 //report_fatal_error("unsupported directive: '.file'");
104 virtual void EmitInstruction(const MCInst &Inst);
106 virtual void Finish();
111 } // end anonymous namespace.
113 void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
114 // TODO: This is almost exactly the same as WinCOFFStreamer. Consider merging
115 // into MCObjectStreamer.
116 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
117 assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
118 assert(CurSection && "Cannot emit before setting section!");
120 Symbol->setSection(*CurSection);
122 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
124 // We have to create a new fragment if this is an atom defining symbol,
125 // fragments cannot span atoms.
126 if (getAssembler().isSymbolLinkerVisible(SD.getSymbol()))
127 new MCDataFragment(getCurrentSectionData());
129 // FIXME: This is wasteful, we don't necessarily need to create a data
130 // fragment. Instead, we should mark the symbol as pointing into the data
131 // fragment if it exists, otherwise we should just queue the label and set its
132 // fragment pointer when we emit the next fragment.
133 MCDataFragment *F = getOrCreateDataFragment();
134 assert(!SD.getFragment() && "Unexpected fragment on symbol data!");
136 SD.setOffset(F->getContents().size());
138 // This causes the reference type flag to be cleared. Darwin 'as' was "trying"
139 // to clear the weak reference and weak definition bits too, but the
140 // implementation was buggy. For now we just try to match 'as', for
143 // FIXME: Cleanup this code, these bits should be emitted based on semantic
144 // properties, not on the order of definition, etc.
145 SD.setFlags(SD.getFlags() & ~SF_ReferenceTypeMask);
148 void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
150 case MCAF_SubsectionsViaSymbols:
151 getAssembler().setSubsectionsViaSymbols(true);
155 assert(0 && "invalid assembler flag!");
158 void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
159 // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
161 // FIXME: Lift context changes into super class.
162 getAssembler().getOrCreateSymbolData(*Symbol);
163 Symbol->setVariableValue(AddValueSymbols(Value));
166 void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
167 MCSymbolAttr Attribute) {
168 // Indirect symbols are handled differently, to match how 'as' handles
169 // them. This makes writing matching .o files easier.
170 if (Attribute == MCSA_IndirectSymbol) {
171 // Note that we intentionally cannot use the symbol data here; this is
172 // important for matching the string table that 'as' generates.
173 IndirectSymbolData ISD;
175 ISD.SectionData = getCurrentSectionData();
176 getAssembler().getIndirectSymbols().push_back(ISD);
180 // Adding a symbol attribute always introduces the symbol, note that an
181 // important side effect of calling getOrCreateSymbolData here is to register
182 // the symbol with the assembler.
183 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
185 // The implementation of symbol attributes is designed to match 'as', but it
186 // leaves much to desired. It doesn't really make sense to arbitrarily add and
187 // remove flags, but 'as' allows this (in particular, see .desc).
189 // In the future it might be worth trying to make these operations more well
193 case MCSA_ELF_TypeFunction:
194 case MCSA_ELF_TypeIndFunction:
195 case MCSA_ELF_TypeObject:
196 case MCSA_ELF_TypeTLS:
197 case MCSA_ELF_TypeCommon:
198 case MCSA_ELF_TypeNoType:
199 case MCSA_IndirectSymbol:
205 assert(0 && "Invalid symbol attribute for Mach-O!");
209 SD.setExternal(true);
210 // This effectively clears the undefined lazy bit, in Darwin 'as', although
211 // it isn't very consistent because it implements this as part of symbol
214 // FIXME: Cleanup this code, these bits should be emitted based on semantic
215 // properties, not on the order of definition, etc.
216 SD.setFlags(SD.getFlags() & ~SF_ReferenceTypeUndefinedLazy);
219 case MCSA_LazyReference:
220 // FIXME: This requires -dynamic.
221 SD.setFlags(SD.getFlags() | SF_NoDeadStrip);
222 if (Symbol->isUndefined())
223 SD.setFlags(SD.getFlags() | SF_ReferenceTypeUndefinedLazy);
226 // Since .reference sets the no dead strip bit, it is equivalent to
227 // .no_dead_strip in practice.
229 case MCSA_NoDeadStrip:
230 SD.setFlags(SD.getFlags() | SF_NoDeadStrip);
233 case MCSA_PrivateExtern:
234 SD.setExternal(true);
235 SD.setPrivateExtern(true);
238 case MCSA_WeakReference:
239 // FIXME: This requires -dynamic.
240 if (Symbol->isUndefined())
241 SD.setFlags(SD.getFlags() | SF_WeakReference);
244 case MCSA_WeakDefinition:
245 // FIXME: 'as' enforces that this is defined and global. The manual claims
246 // it has to be in a coalesced section, but this isn't enforced.
247 SD.setFlags(SD.getFlags() | SF_WeakDefinition);
250 case MCSA_WeakDefAutoPrivate:
251 SD.setFlags(SD.getFlags() | SF_WeakDefinition | SF_WeakReference);
256 void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
257 // Encode the 'desc' value into the lowest implementation defined bits.
258 assert(DescValue == (DescValue & SF_DescFlagsMask) &&
259 "Invalid .desc value!");
260 getAssembler().getOrCreateSymbolData(*Symbol).setFlags(
261 DescValue & SF_DescFlagsMask);
264 void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
265 unsigned ByteAlignment) {
266 // FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
267 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
269 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
270 SD.setExternal(true);
271 SD.setCommon(Size, ByteAlignment);
274 void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
275 unsigned Size, unsigned ByteAlignment) {
276 MCSectionData &SectData = getAssembler().getOrCreateSectionData(*Section);
278 // The symbol may not be present, which only creates the section.
282 // FIXME: Assert that this section has the zerofill type.
284 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
286 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
288 // Emit an align fragment if necessary.
289 if (ByteAlignment != 1)
290 new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectData);
292 MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
295 Symbol->setSection(*Section);
297 // Update the maximum alignment on the zero fill section if necessary.
298 if (ByteAlignment > SectData.getAlignment())
299 SectData.setAlignment(ByteAlignment);
302 // This should always be called with the thread local bss section. Like the
303 // .zerofill directive this doesn't actually switch sections on us.
304 void MCMachOStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
305 uint64_t Size, unsigned ByteAlignment) {
306 EmitZerofill(Section, Symbol, Size, ByteAlignment);
310 void MCMachOStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
311 // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
313 getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
316 void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
317 unsigned AddrSpace) {
318 // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
320 MCDataFragment *DF = getOrCreateDataFragment();
322 // Avoid fixups when possible.
324 if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
325 // FIXME: Endianness assumption.
326 for (unsigned i = 0; i != Size; ++i)
327 DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
329 DF->addFixup(MCFixup::Create(DF->getContents().size(),
330 AddValueSymbols(Value),
331 MCFixup::getKindForSize(Size)));
332 DF->getContents().resize(DF->getContents().size() + Size, 0);
336 void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
337 int64_t Value, unsigned ValueSize,
338 unsigned MaxBytesToEmit) {
339 // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
341 if (MaxBytesToEmit == 0)
342 MaxBytesToEmit = ByteAlignment;
343 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
344 getCurrentSectionData());
346 // Update the maximum alignment on the current section if necessary.
347 if (ByteAlignment > getCurrentSectionData()->getAlignment())
348 getCurrentSectionData()->setAlignment(ByteAlignment);
351 void MCMachOStreamer::EmitCodeAlignment(unsigned ByteAlignment,
352 unsigned MaxBytesToEmit) {
353 // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
355 if (MaxBytesToEmit == 0)
356 MaxBytesToEmit = ByteAlignment;
357 MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
358 getCurrentSectionData());
359 F->setEmitNops(true);
361 // Update the maximum alignment on the current section if necessary.
362 if (ByteAlignment > getCurrentSectionData()->getAlignment())
363 getCurrentSectionData()->setAlignment(ByteAlignment);
366 void MCMachOStreamer::EmitValueToOffset(const MCExpr *Offset,
367 unsigned char Value) {
368 new MCOrgFragment(*Offset, Value, getCurrentSectionData());
371 void MCMachOStreamer::EmitInstToFragment(const MCInst &Inst) {
372 MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData());
374 // Add the fixups and data.
376 // FIXME: Revisit this design decision when relaxation is done, we may be
377 // able to get away with not storing any extra data in the MCInst.
378 SmallVector<MCFixup, 4> Fixups;
379 SmallString<256> Code;
380 raw_svector_ostream VecOS(Code);
381 getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
384 IF->getCode() = Code;
385 IF->getFixups() = Fixups;
388 void MCMachOStreamer::EmitInstToData(const MCInst &Inst) {
389 MCDataFragment *DF = getOrCreateDataFragment();
391 SmallVector<MCFixup, 4> Fixups;
392 SmallString<256> Code;
393 raw_svector_ostream VecOS(Code);
394 getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
397 // Add the fixups and data.
398 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
399 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
400 DF->addFixup(Fixups[i]);
402 DF->getContents().append(Code.begin(), Code.end());
405 void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
407 for (unsigned i = Inst.getNumOperands(); i--; )
408 if (Inst.getOperand(i).isExpr())
409 AddValueSymbols(Inst.getOperand(i).getExpr());
411 getCurrentSectionData()->setHasInstructions(true);
413 // Now that a machine instruction has been assembled into this section, make
414 // a line entry for any .loc directive that has been seen.
415 MakeLineEntryForSection(getCurrentSection());
417 // If this instruction doesn't need relaxation, just emit it as data.
418 if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
419 EmitInstToData(Inst);
423 // Otherwise, if we are relaxing everything, relax the instruction as much as
424 // possible and emit it as data.
425 if (getAssembler().getRelaxAll()) {
427 getAssembler().getBackend().RelaxInstruction(Inst, Relaxed);
428 while (getAssembler().getBackend().MayNeedRelaxation(Relaxed))
429 getAssembler().getBackend().RelaxInstruction(Relaxed, Relaxed);
430 EmitInstToData(Relaxed);
434 // Otherwise emit to a separate fragment.
435 EmitInstToFragment(Inst);
439 // This is called when an instruction is assembled into the specified section
440 // and if there is information from the last .loc directive that has yet to have
441 // a line entry made for it is made.
443 void MCMachOStreamer::MakeLineEntryForSection(const MCSection *Section) {
444 if (!getContext().getDwarfLocSeen())
447 // Create a symbol at in the current section for use in the line entry.
448 MCSymbol *LineSym = getContext().CreateTempSymbol();
449 // Set the value of the symbol to use for the MCLineEntry.
452 // Get the current .loc info saved in the context.
453 const MCDwarfLoc &DwarfLoc = getContext().getCurrentDwarfLoc();
455 // Create a (local) line entry with the symbol and the current .loc info.
456 MCLineEntry LineEntry(LineSym, DwarfLoc);
458 // clear DwarfLocSeen saying the current .loc info is now used.
459 getContext().clearDwarfLocSeen();
461 // Get the MCLineSection for this section, if one does not exist for this
462 // section create it.
463 DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
464 getContext().getMCLineSections();
465 MCLineSection *LineSection = MCLineSections[Section];
467 // Create a new MCLineSection. This will be deleted after the dwarf line
468 // table is created using it by iterating through the MCLineSections
470 LineSection = new MCLineSection;
471 // Save a pointer to the new LineSection into the MCLineSections DenseMap.
472 MCLineSections[Section] = LineSection;
475 // Add the line entry to this section's entries.
476 LineSection->addLineEntry(LineEntry);
480 // This helper routine returns an expression of End - Start + IntVal for use
481 // by EmitDwarfFileTable() below.
483 const MCExpr * MCMachOStreamer::MakeStartMinusEndExpr(MCSymbol *Start,
486 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
488 MCSymbolRefExpr::Create(End, Variant, getContext());
490 MCSymbolRefExpr::Create(Start, Variant, getContext());
492 MCBinaryExpr::Create(MCBinaryExpr::Sub, Res, RHS,getContext());
494 MCConstantExpr::Create(IntVal, getContext());
496 MCBinaryExpr::Create(MCBinaryExpr::Sub, Res1, Res2, getContext());
501 // This emits the Dwarf file (and eventually the line) table.
503 void MCMachOStreamer::EmitDwarfFileTable(void) {
504 // For now make sure we don't put out the Dwarf file table if no .file
505 // directives were seen.
506 const std::vector<MCDwarfFile *> &MCDwarfFiles =
507 getContext().getMCDwarfFiles();
508 if (MCDwarfFiles.size() == 0)
511 // This is the Mach-O section, for ELF it is the .debug_line section.
512 SwitchSection(getContext().getMachOSection("__DWARF", "__debug_line",
513 MCSectionMachO::S_ATTR_DEBUG,
514 0, SectionKind::getDataRelLocal()));
516 // Create a symbol at the beginning of this section.
517 MCSymbol *LineStartSym = getContext().CreateTempSymbol();
518 // Set the value of the symbol, as we are at the start of the section.
519 EmitLabel(LineStartSym);
521 // Create a symbol for the end of the section (to be set when we get there).
522 MCSymbol *LineEndSym = getContext().CreateTempSymbol();
524 // The first 4 bytes is the total length of the information for this
525 // compilation unit (not including these 4 bytes for the length).
526 EmitValue(MakeStartMinusEndExpr(LineStartSym, LineEndSym, 4), 4, 0);
528 // Next 2 bytes is the Version, which is Dwarf 2.
531 // Create a symbol for the end of the prologue (to be set when we get there).
532 MCSymbol *ProEndSym = getContext().CreateTempSymbol(); // Lprologue_end
534 // Length of the prologue, is the next 4 bytes. Which is the start of the
535 // section to the end of the prologue. Not including the 4 bytes for the
536 // total length, the 2 bytes for the version, and these 4 bytes for the
537 // length of the prologue.
538 EmitValue(MakeStartMinusEndExpr(LineStartSym, ProEndSym, (4 + 2 + 4)), 4, 0);
540 // Parameters of the state machine, are next.
541 // Define the architecture-dependent minimum instruction length (in
542 // bytes). This value should be rather too small than too big. */
543 // DWARF2_LINE_MIN_INSN_LENGTH
545 // Flag that indicates the initial value of the is_stmt_start flag.
546 // DWARF2_LINE_DEFAULT_IS_STMT
548 // Minimum line offset in a special line info. opcode. This value
549 // was chosen to give a reasonable range of values. */
551 EmitIntValue(uint64_t(-5), 1);
552 // Range of line offsets in a special line info. opcode.
555 // First special line opcode - leave room for the standard opcodes.
556 // DWARF2_LINE_OPCODE_BASE
559 // Standard opcode lengths
560 EmitIntValue(0, 1); // length of DW_LNS_copy
561 EmitIntValue(1, 1); // length of DW_LNS_advance_pc
562 EmitIntValue(1, 1); // length of DW_LNS_advance_line
563 EmitIntValue(1, 1); // length of DW_LNS_set_file
564 EmitIntValue(1, 1); // length of DW_LNS_set_column
565 EmitIntValue(0, 1); // length of DW_LNS_negate_stmt
566 EmitIntValue(0, 1); // length of DW_LNS_set_basic_block
567 EmitIntValue(0, 1); // length of DW_LNS_const_add_pc
568 EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc
569 EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end
570 EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin
571 EmitIntValue(1, 1); // DW_LNS_set_isa
573 // Put out the directory and file tables.
575 // First the directory table.
576 const std::vector<StringRef> &MCDwarfDirs =
577 getContext().getMCDwarfDirs();
578 for (unsigned i = 0; i < MCDwarfDirs.size(); i++) {
579 EmitBytes(MCDwarfDirs[i], 0); // the DirectoryName
580 EmitBytes(StringRef("\0", 1), 0); // the null termination of the string
582 EmitIntValue(0, 1); // Terminate the directory list
584 // Second the file table.
585 for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
586 EmitBytes(MCDwarfFiles[i]->getName(), 0); // FileName
587 EmitBytes(StringRef("\0", 1), 0); // the null termination of the string
588 // FIXME the Directory number should be a .uleb128 not a .byte
589 EmitIntValue(MCDwarfFiles[i]->getDirIndex(), 1);
590 EmitIntValue(0, 1); // last modification timestamp (always 0)
591 EmitIntValue(0, 1); // filesize (always 0)
593 EmitIntValue(0, 1); // Terminate the file list
595 // This is the end of the prologue, so set the value of the symbol at the
596 // end of the prologue (that was used in a previous expression).
597 EmitLabel(ProEndSym);
599 // TODO: This is the point where the line tables would be emitted.
601 // Delete the MCLineSections that were created in
602 // MCMachOStreamer::MakeLineEntryForSection() and used to emit the line
604 DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
605 getContext().getMCLineSections();
606 for (DenseMap<const MCSection *, MCLineSection *>::iterator it =
607 MCLineSections.begin(), ie = MCLineSections.end(); it != ie; ++it) {
611 // If there are no line tables emited then we emit:
612 // The following DW_LNE_set_address sequence to set the address to zero
613 // TODO test for 32-bit or 64-bit output
614 // This is the sequence for 32-bit code
623 // Lastly emit the DW_LNE_end_sequence which consists of 3 bytes '00 01 01'
624 // (00 is the code for extended opcodes, followed by a ULEB128 length of the
625 // extended opcode (01), and the DW_LNE_end_sequence (01).
626 EmitIntValue(0, 1); // DW_LNS_extended_op
627 EmitIntValue(1, 1); // ULEB128 length of the extended opcode
628 EmitIntValue(1, 1); // DW_LNE_end_sequence
630 // This is the end of the section, so set the value of the symbol at the end
631 // of this section (that was used in a previous expression).
632 EmitLabel(LineEndSym);
635 void MCMachOStreamer::Finish() {
636 // Dump out the dwarf file and directory tables (soon to include line table)
637 EmitDwarfFileTable();
639 // We have to set the fragment atom associations so we can relax properly for
642 // First, scan the symbol table to build a lookup table from fragments to
644 DenseMap<const MCFragment*, MCSymbolData*> DefiningSymbolMap;
645 for (MCAssembler::symbol_iterator it = getAssembler().symbol_begin(),
646 ie = getAssembler().symbol_end(); it != ie; ++it) {
647 if (getAssembler().isSymbolLinkerVisible(it->getSymbol()) &&
649 // An atom defining symbol should never be internal to a fragment.
650 assert(it->getOffset() == 0 && "Invalid offset in atom defining symbol!");
651 DefiningSymbolMap[it->getFragment()] = it;
655 // Set the fragment atom associations by tracking the last seen atom defining
657 for (MCAssembler::iterator it = getAssembler().begin(),
658 ie = getAssembler().end(); it != ie; ++it) {
659 MCSymbolData *CurrentAtom = 0;
660 for (MCSectionData::iterator it2 = it->begin(),
661 ie2 = it->end(); it2 != ie2; ++it2) {
662 if (MCSymbolData *SD = DefiningSymbolMap.lookup(it2))
664 it2->setAtom(CurrentAtom);
668 this->MCObjectStreamer::Finish();
671 MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
672 raw_ostream &OS, MCCodeEmitter *CE,
674 MCMachOStreamer *S = new MCMachOStreamer(Context, TAB, OS, CE);
676 S->getAssembler().setRelaxAll(true);