Always print the implicit .text at the start of an asm file.
[oota-llvm.git] / lib / MC / MCELFStreamer.cpp
1 //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file assembles .s files and emits ELF .o object files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/MC/MCELFStreamer.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/MC/MCAsmBackend.h"
18 #include "llvm/MC/MCAssembler.h"
19 #include "llvm/MC/MCCodeEmitter.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCELF.h"
22 #include "llvm/MC/MCELFSymbolFlags.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCInst.h"
25 #include "llvm/MC/MCObjectFileInfo.h"
26 #include "llvm/MC/MCObjectStreamer.h"
27 #include "llvm/MC/MCSection.h"
28 #include "llvm/MC/MCSectionELF.h"
29 #include "llvm/MC/MCSymbol.h"
30 #include "llvm/MC/MCValue.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/ELF.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
35
36 using namespace llvm;
37
38 MCELFStreamer::~MCELFStreamer() {
39 }
40
41 void MCELFStreamer::InitSections() {
42   // This emulates the same behavior of GNU as. This makes it easier
43   // to compare the output as the major sections are in the same order.
44   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
45   EmitCodeAlignment(4);
46
47   SwitchSection(getContext().getObjectFileInfo()->getDataSection());
48   EmitCodeAlignment(4);
49
50   SwitchSection(getContext().getObjectFileInfo()->getBSSSection());
51   EmitCodeAlignment(4);
52
53   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
54 }
55
56 void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
57   assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
58
59   MCObjectStreamer::EmitLabel(Symbol);
60
61   const MCSectionELF &Section =
62     static_cast<const MCSectionELF&>(Symbol->getSection());
63   MCSymbolData &SD = getAssembler().getSymbolData(*Symbol);
64   if (Section.getFlags() & ELF::SHF_TLS)
65     MCELF::SetType(SD, ELF::STT_TLS);
66 }
67
68 void MCELFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
69   EmitLabel(Symbol);
70 }
71
72 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
73   // Let the target do whatever target specific stuff it needs to do.
74   getAssembler().getBackend().handleAssemblerFlag(Flag);
75   // Do any generic stuff we need to do.
76   switch (Flag) {
77   case MCAF_SyntaxUnified: return; // no-op here.
78   case MCAF_Code16: return; // Change parsing mode; no-op here.
79   case MCAF_Code32: return; // Change parsing mode; no-op here.
80   case MCAF_Code64: return; // Change parsing mode; no-op here.
81   case MCAF_SubsectionsViaSymbols:
82     getAssembler().setSubsectionsViaSymbols(true);
83     return;
84   }
85
86   llvm_unreachable("invalid assembler flag!");
87 }
88
89 void MCELFStreamer::ChangeSection(const MCSection *Section,
90                                   const MCExpr *Subsection) {
91   MCSectionData *CurSection = getCurrentSectionData();
92   if (CurSection && CurSection->isBundleLocked())
93     report_fatal_error("Unterminated .bundle_lock when changing a section");
94   const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup();
95   if (Grp)
96     getAssembler().getOrCreateSymbolData(*Grp);
97   this->MCObjectStreamer::ChangeSection(Section, Subsection);
98 }
99
100 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
101   getAssembler().getOrCreateSymbolData(*Symbol);
102   MCSymbolData &AliasSD = getAssembler().getOrCreateSymbolData(*Alias);
103   AliasSD.setFlags(AliasSD.getFlags() | ELF_Other_Weakref);
104   const MCExpr *Value = MCSymbolRefExpr::Create(Symbol, getContext());
105   Alias->setVariableValue(Value);
106 }
107
108 // When GNU as encounters more than one .type declaration for an object it seems
109 // to use a mechanism similar to the one below to decide which type is actually
110 // used in the object file.  The greater of T1 and T2 is selected based on the
111 // following ordering:
112 //  STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
113 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
114 // provided type).
115 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
116   unsigned TypeOrdering[] = {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
117                              ELF::STT_GNU_IFUNC, ELF::STT_TLS};
118   for (unsigned i = 0; i != array_lengthof(TypeOrdering); ++i) {
119     if (T1 == TypeOrdering[i])
120       return T2;
121     if (T2 == TypeOrdering[i])
122       return T1;
123   }
124
125   return T2;
126 }
127
128 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
129                                         MCSymbolAttr Attribute) {
130   // Indirect symbols are handled differently, to match how 'as' handles
131   // them. This makes writing matching .o files easier.
132   if (Attribute == MCSA_IndirectSymbol) {
133     // Note that we intentionally cannot use the symbol data here; this is
134     // important for matching the string table that 'as' generates.
135     IndirectSymbolData ISD;
136     ISD.Symbol = Symbol;
137     ISD.SectionData = getCurrentSectionData();
138     getAssembler().getIndirectSymbols().push_back(ISD);
139     return true;
140   }
141
142   // Adding a symbol attribute always introduces the symbol, note that an
143   // important side effect of calling getOrCreateSymbolData here is to register
144   // the symbol with the assembler.
145   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
146
147   // The implementation of symbol attributes is designed to match 'as', but it
148   // leaves much to desired. It doesn't really make sense to arbitrarily add and
149   // remove flags, but 'as' allows this (in particular, see .desc).
150   //
151   // In the future it might be worth trying to make these operations more well
152   // defined.
153   switch (Attribute) {
154   case MCSA_LazyReference:
155   case MCSA_Reference:
156   case MCSA_SymbolResolver:
157   case MCSA_PrivateExtern:
158   case MCSA_WeakDefinition:
159   case MCSA_WeakDefAutoPrivate:
160   case MCSA_Invalid:
161   case MCSA_IndirectSymbol:
162     return false;
163
164   case MCSA_NoDeadStrip:
165   case MCSA_ELF_TypeGnuUniqueObject:
166     // Ignore for now.
167     break;
168
169   case MCSA_Global:
170     MCELF::SetBinding(SD, ELF::STB_GLOBAL);
171     SD.setExternal(true);
172     BindingExplicitlySet.insert(Symbol);
173     break;
174
175   case MCSA_WeakReference:
176   case MCSA_Weak:
177     MCELF::SetBinding(SD, ELF::STB_WEAK);
178     SD.setExternal(true);
179     BindingExplicitlySet.insert(Symbol);
180     break;
181
182   case MCSA_Local:
183     MCELF::SetBinding(SD, ELF::STB_LOCAL);
184     SD.setExternal(false);
185     BindingExplicitlySet.insert(Symbol);
186     break;
187
188   case MCSA_ELF_TypeFunction:
189     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
190                                           ELF::STT_FUNC));
191     break;
192
193   case MCSA_ELF_TypeIndFunction:
194     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
195                                           ELF::STT_GNU_IFUNC));
196     break;
197
198   case MCSA_ELF_TypeObject:
199     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
200                                           ELF::STT_OBJECT));
201     break;
202
203   case MCSA_ELF_TypeTLS:
204     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
205                                           ELF::STT_TLS));
206     break;
207
208   case MCSA_ELF_TypeCommon:
209     // TODO: Emit these as a common symbol.
210     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
211                                           ELF::STT_OBJECT));
212     break;
213
214   case MCSA_ELF_TypeNoType:
215     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
216                                           ELF::STT_NOTYPE));
217     break;
218
219   case MCSA_Protected:
220     MCELF::SetVisibility(SD, ELF::STV_PROTECTED);
221     break;
222
223   case MCSA_Hidden:
224     MCELF::SetVisibility(SD, ELF::STV_HIDDEN);
225     break;
226
227   case MCSA_Internal:
228     MCELF::SetVisibility(SD, ELF::STV_INTERNAL);
229     break;
230   }
231
232   return true;
233 }
234
235 void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
236                                        unsigned ByteAlignment) {
237   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
238
239   if (!BindingExplicitlySet.count(Symbol)) {
240     MCELF::SetBinding(SD, ELF::STB_GLOBAL);
241     SD.setExternal(true);
242   }
243
244   MCELF::SetType(SD, ELF::STT_OBJECT);
245
246   if (MCELF::GetBinding(SD) == ELF_STB_Local) {
247     const MCSection *Section = getAssembler().getContext().getELFSection(".bss",
248                                                          ELF::SHT_NOBITS,
249                                                          ELF::SHF_WRITE |
250                                                          ELF::SHF_ALLOC,
251                                                          SectionKind::getBSS());
252
253     AssignSection(Symbol, Section);
254
255     struct LocalCommon L = {&SD, Size, ByteAlignment};
256     LocalCommons.push_back(L);
257   } else {
258     SD.setCommon(Size, ByteAlignment);
259   }
260
261   SD.setSize(MCConstantExpr::Create(Size, getContext()));
262 }
263
264 void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
265   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
266   SD.setSize(Value);
267 }
268
269 void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
270                                           unsigned ByteAlignment) {
271   // FIXME: Should this be caught and done earlier?
272   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
273   MCELF::SetBinding(SD, ELF::STB_LOCAL);
274   SD.setExternal(false);
275   BindingExplicitlySet.insert(Symbol);
276   EmitCommonSymbol(Symbol, Size, ByteAlignment);
277 }
278
279 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
280   if (getCurrentSectionData()->isBundleLocked())
281     report_fatal_error("Emitting values inside a locked bundle is forbidden");
282   fixSymbolsInTLSFixups(Value);
283   MCObjectStreamer::EmitValueImpl(Value, Size);
284 }
285
286 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
287                                          int64_t Value,
288                                          unsigned ValueSize,
289                                          unsigned MaxBytesToEmit) {
290   if (getCurrentSectionData()->isBundleLocked())
291     report_fatal_error("Emitting values inside a locked bundle is forbidden");
292   MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
293                                          ValueSize, MaxBytesToEmit);
294 }
295
296 // Add a symbol for the file name of this module. They start after the
297 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
298 // with the same name may appear.
299 void MCELFStreamer::EmitFileDirective(StringRef Filename) {
300   getAssembler().addFileName(Filename);
301 }
302
303 void MCELFStreamer::EmitIdent(StringRef IdentString) {
304   const MCSection *Comment = getAssembler().getContext().getELFSection(
305       ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS,
306       SectionKind::getReadOnly(), 1, "");
307   PushSection();
308   SwitchSection(Comment);
309   if (!SeenIdent) {
310     EmitIntValue(0, 1);
311     SeenIdent = true;
312   }
313   EmitBytes(IdentString);
314   EmitIntValue(0, 1);
315   PopSection();
316 }
317
318 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
319   switch (expr->getKind()) {
320   case MCExpr::Target:
321     cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
322     break;
323   case MCExpr::Constant:
324     break;
325
326   case MCExpr::Binary: {
327     const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
328     fixSymbolsInTLSFixups(be->getLHS());
329     fixSymbolsInTLSFixups(be->getRHS());
330     break;
331   }
332
333   case MCExpr::SymbolRef: {
334     const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
335     switch (symRef.getKind()) {
336     default:
337       return;
338     case MCSymbolRefExpr::VK_GOTTPOFF:
339     case MCSymbolRefExpr::VK_INDNTPOFF:
340     case MCSymbolRefExpr::VK_NTPOFF:
341     case MCSymbolRefExpr::VK_GOTNTPOFF:
342     case MCSymbolRefExpr::VK_TLSGD:
343     case MCSymbolRefExpr::VK_TLSLD:
344     case MCSymbolRefExpr::VK_TLSLDM:
345     case MCSymbolRefExpr::VK_TPOFF:
346     case MCSymbolRefExpr::VK_DTPOFF:
347     case MCSymbolRefExpr::VK_Mips_TLSGD:
348     case MCSymbolRefExpr::VK_Mips_GOTTPREL:
349     case MCSymbolRefExpr::VK_Mips_TPREL_HI:
350     case MCSymbolRefExpr::VK_Mips_TPREL_LO:
351     case MCSymbolRefExpr::VK_PPC_DTPMOD:
352     case MCSymbolRefExpr::VK_PPC_TPREL:
353     case MCSymbolRefExpr::VK_PPC_TPREL_LO:
354     case MCSymbolRefExpr::VK_PPC_TPREL_HI:
355     case MCSymbolRefExpr::VK_PPC_TPREL_HA:
356     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
357     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
358     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
359     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
360     case MCSymbolRefExpr::VK_PPC_DTPREL:
361     case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
362     case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
363     case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
364     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
365     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
366     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
367     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
368     case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
369     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
370     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
371     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
372     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
373     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
374     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
375     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
376     case MCSymbolRefExpr::VK_PPC_TLS:
377     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
378     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
379     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
380     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
381     case MCSymbolRefExpr::VK_PPC_TLSGD:
382     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
383     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
384     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
385     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
386     case MCSymbolRefExpr::VK_PPC_TLSLD:
387       break;
388     }
389     MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
390     MCELF::SetType(SD, ELF::STT_TLS);
391     break;
392   }
393
394   case MCExpr::Unary:
395     fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
396     break;
397   }
398 }
399
400 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
401                                        const MCSubtargetInfo &STI) {
402   this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
403   MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
404
405   for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
406     fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
407 }
408
409 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
410                                    const MCSubtargetInfo &STI) {
411   MCAssembler &Assembler = getAssembler();
412   SmallVector<MCFixup, 4> Fixups;
413   SmallString<256> Code;
414   raw_svector_ostream VecOS(Code);
415   Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups, STI);
416   VecOS.flush();
417
418   for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
419     fixSymbolsInTLSFixups(Fixups[i].getValue());
420
421   // There are several possibilities here:
422   //
423   // If bundling is disabled, append the encoded instruction to the current data
424   // fragment (or create a new such fragment if the current fragment is not a
425   // data fragment).
426   //
427   // If bundling is enabled:
428   // - If we're not in a bundle-locked group, emit the instruction into a
429   //   fragment of its own. If there are no fixups registered for the
430   //   instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
431   //   MCDataFragment.
432   // - If we're in a bundle-locked group, append the instruction to the current
433   //   data fragment because we want all the instructions in a group to get into
434   //   the same fragment. Be careful not to do that for the first instruction in
435   //   the group, though.
436   MCDataFragment *DF;
437
438   if (Assembler.isBundlingEnabled()) {
439     MCSectionData *SD = getCurrentSectionData();
440     if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
441       // If we are bundle-locked, we re-use the current fragment.
442       // The bundle-locking directive ensures this is a new data fragment.
443       DF = cast<MCDataFragment>(getCurrentFragment());
444     else if (!SD->isBundleLocked() && Fixups.size() == 0) {
445       // Optimize memory usage by emitting the instruction to a
446       // MCCompactEncodedInstFragment when not in a bundle-locked group and
447       // there are no fixups registered.
448       MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
449       insert(CEIF);
450       CEIF->getContents().append(Code.begin(), Code.end());
451       return;
452     } else {
453       DF = new MCDataFragment();
454       insert(DF);
455       if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
456         // If this is a new fragment created for a bundle-locked group, and the
457         // group was marked as "align_to_end", set a flag in the fragment.
458         DF->setAlignToBundleEnd(true);
459       }
460     }
461
462     // We're now emitting an instruction in a bundle group, so this flag has
463     // to be turned off.
464     SD->setBundleGroupBeforeFirstInst(false);
465   } else {
466     DF = getOrCreateDataFragment();
467   }
468
469   // Add the fixups and data.
470   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
471     Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
472     DF->getFixups().push_back(Fixups[i]);
473   }
474   DF->setHasInstructions(true);
475   DF->getContents().append(Code.begin(), Code.end());
476 }
477
478 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
479   assert(AlignPow2 <= 30 && "Invalid bundle alignment");
480   MCAssembler &Assembler = getAssembler();
481   if (Assembler.getBundleAlignSize() == 0 && AlignPow2 > 0)
482     Assembler.setBundleAlignSize(1 << AlignPow2);
483   else
484     report_fatal_error(".bundle_align_mode should be only set once per file");
485 }
486
487 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
488   MCSectionData *SD = getCurrentSectionData();
489
490   // Sanity checks
491   //
492   if (!getAssembler().isBundlingEnabled())
493     report_fatal_error(".bundle_lock forbidden when bundling is disabled");
494   else if (SD->isBundleLocked())
495     report_fatal_error("Nesting of .bundle_lock is forbidden");
496
497   SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd :
498                                       MCSectionData::BundleLocked);
499   SD->setBundleGroupBeforeFirstInst(true);
500 }
501
502 void MCELFStreamer::EmitBundleUnlock() {
503   MCSectionData *SD = getCurrentSectionData();
504
505   // Sanity checks
506   if (!getAssembler().isBundlingEnabled())
507     report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
508   else if (!SD->isBundleLocked())
509     report_fatal_error(".bundle_unlock without matching lock");
510   else if (SD->isBundleGroupBeforeFirstInst())
511     report_fatal_error("Empty bundle-locked group is forbidden");
512
513   SD->setBundleLockState(MCSectionData::NotBundleLocked);
514 }
515
516 void MCELFStreamer::Flush() {
517   for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
518                                                 e = LocalCommons.end();
519        i != e; ++i) {
520     MCSymbolData *SD = i->SD;
521     uint64_t Size = i->Size;
522     unsigned ByteAlignment = i->ByteAlignment;
523     const MCSymbol &Symbol = SD->getSymbol();
524     const MCSection &Section = Symbol.getSection();
525
526     MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
527     new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
528
529     MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
530     SD->setFragment(F);
531
532     // Update the maximum alignment of the section if necessary.
533     if (ByteAlignment > SectData.getAlignment())
534       SectData.setAlignment(ByteAlignment);
535   }
536
537   LocalCommons.clear();
538 }
539
540 void MCELFStreamer::FinishImpl() {
541   EmitFrames(NULL, true);
542
543   Flush();
544
545   this->MCObjectStreamer::FinishImpl();
546 }
547
548 MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
549                                     raw_ostream &OS, MCCodeEmitter *CE,
550                                     bool RelaxAll, bool NoExecStack) {
551   MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
552   if (RelaxAll)
553     S->getAssembler().setRelaxAll(true);
554   if (NoExecStack)
555     S->getAssembler().setNoExecStack(true);
556   return S;
557 }
558
559 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
560   llvm_unreachable("Generic ELF doesn't support this directive");
561 }
562
563 MCSymbolData &MCELFStreamer::getOrCreateSymbolData(MCSymbol *Symbol) {
564   return getAssembler().getOrCreateSymbolData(*Symbol);
565 }
566
567 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
568   llvm_unreachable("ELF doesn't support this directive");
569 }
570
571 void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
572   llvm_unreachable("ELF doesn't support this directive");
573 }
574
575 void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
576   llvm_unreachable("ELF doesn't support this directive");
577 }
578
579 void MCELFStreamer::EmitCOFFSymbolType(int Type) {
580   llvm_unreachable("ELF doesn't support this directive");
581 }
582
583 void MCELFStreamer::EndCOFFSymbolDef() {
584   llvm_unreachable("ELF doesn't support this directive");
585 }
586
587 void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
588                                  uint64_t Size, unsigned ByteAlignment) {
589   llvm_unreachable("ELF doesn't support this directive");
590 }
591
592 void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
593                                    uint64_t Size, unsigned ByteAlignment) {
594   llvm_unreachable("ELF doesn't support this directive");
595 }