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