Revert commit r219835 and r219829.
[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/MCAsmInfo.h"
19 #include "llvm/MC/MCAssembler.h"
20 #include "llvm/MC/MCCodeEmitter.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCELF.h"
23 #include "llvm/MC/MCELFSymbolFlags.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 #include "llvm/MC/MCObjectFileInfo.h"
27 #include "llvm/MC/MCObjectStreamer.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCSectionELF.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/MC/MCValue.h"
32 #include "llvm/Support/Debug.h"
33 #include "llvm/Support/ELF.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/raw_ostream.h"
36
37 using namespace llvm;
38
39 MCELFStreamer::~MCELFStreamer() {
40 }
41
42 void MCELFStreamer::InitSections(bool NoExecStack) {
43   // This emulates the same behavior of GNU as. This makes it easier
44   // to compare the output as the major sections are in the same order.
45   MCContext &Ctx = getContext();
46   SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
47   EmitCodeAlignment(4);
48
49   SwitchSection(Ctx.getObjectFileInfo()->getDataSection());
50   EmitCodeAlignment(4);
51
52   SwitchSection(Ctx.getObjectFileInfo()->getBSSSection());
53   EmitCodeAlignment(4);
54
55   SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
56
57   if (NoExecStack)
58     SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
59 }
60
61 void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
62   assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
63
64   MCObjectStreamer::EmitLabel(Symbol);
65
66   const MCSectionELF &Section =
67     static_cast<const MCSectionELF&>(Symbol->getSection());
68   MCSymbolData &SD = getAssembler().getSymbolData(*Symbol);
69   if (Section.getFlags() & ELF::SHF_TLS)
70     MCELF::SetType(SD, ELF::STT_TLS);
71 }
72
73 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
74   // Let the target do whatever target specific stuff it needs to do.
75   getAssembler().getBackend().handleAssemblerFlag(Flag);
76   // Do any generic stuff we need to do.
77   switch (Flag) {
78   case MCAF_SyntaxUnified: return; // no-op here.
79   case MCAF_Code16: return; // Change parsing mode; no-op here.
80   case MCAF_Code32: return; // Change parsing mode; no-op here.
81   case MCAF_Code64: return; // Change parsing mode; no-op here.
82   case MCAF_SubsectionsViaSymbols:
83     getAssembler().setSubsectionsViaSymbols(true);
84     return;
85   }
86
87   llvm_unreachable("invalid assembler flag!");
88 }
89
90 void MCELFStreamer::ChangeSection(const MCSection *Section,
91                                   const MCExpr *Subsection) {
92   MCSectionData *CurSection = getCurrentSectionData();
93   if (CurSection && CurSection->isBundleLocked())
94     report_fatal_error("Unterminated .bundle_lock when changing a section");
95   const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup();
96   if (Grp)
97     getAssembler().getOrCreateSymbolData(*Grp);
98   this->MCObjectStreamer::ChangeSection(Section, Subsection);
99 }
100
101 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
102   getAssembler().getOrCreateSymbolData(*Symbol);
103   const MCExpr *Value = MCSymbolRefExpr::Create(
104       Symbol, MCSymbolRefExpr::VK_WEAKREF, 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                                   const SMLoc &Loc) {
281   if (getCurrentSectionData()->isBundleLocked())
282     report_fatal_error("Emitting values inside a locked bundle is forbidden");
283   fixSymbolsInTLSFixups(Value);
284   MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
285 }
286
287 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
288                                          int64_t Value,
289                                          unsigned ValueSize,
290                                          unsigned MaxBytesToEmit) {
291   if (getCurrentSectionData()->isBundleLocked())
292     report_fatal_error("Emitting values inside a locked bundle is forbidden");
293   MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
294                                          ValueSize, MaxBytesToEmit);
295 }
296
297 // Add a symbol for the file name of this module. They start after the
298 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
299 // with the same name may appear.
300 void MCELFStreamer::EmitFileDirective(StringRef Filename) {
301   getAssembler().addFileName(Filename);
302 }
303
304 void MCELFStreamer::EmitIdent(StringRef IdentString) {
305   const MCSection *Comment = getAssembler().getContext().getELFSection(
306       ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS,
307       SectionKind::getReadOnly(), 1, "");
308   PushSection();
309   SwitchSection(Comment);
310   if (!SeenIdent) {
311     EmitIntValue(0, 1);
312     SeenIdent = true;
313   }
314   EmitBytes(IdentString);
315   EmitIntValue(0, 1);
316   PopSection();
317 }
318
319 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
320   switch (expr->getKind()) {
321   case MCExpr::Target:
322     cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
323     break;
324   case MCExpr::Constant:
325     break;
326
327   case MCExpr::Binary: {
328     const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
329     fixSymbolsInTLSFixups(be->getLHS());
330     fixSymbolsInTLSFixups(be->getRHS());
331     break;
332   }
333
334   case MCExpr::SymbolRef: {
335     const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
336     switch (symRef.getKind()) {
337     default:
338       return;
339     case MCSymbolRefExpr::VK_GOTTPOFF:
340     case MCSymbolRefExpr::VK_INDNTPOFF:
341     case MCSymbolRefExpr::VK_NTPOFF:
342     case MCSymbolRefExpr::VK_GOTNTPOFF:
343     case MCSymbolRefExpr::VK_TLSGD:
344     case MCSymbolRefExpr::VK_TLSLD:
345     case MCSymbolRefExpr::VK_TLSLDM:
346     case MCSymbolRefExpr::VK_TPOFF:
347     case MCSymbolRefExpr::VK_DTPOFF:
348     case MCSymbolRefExpr::VK_Mips_TLSGD:
349     case MCSymbolRefExpr::VK_Mips_GOTTPREL:
350     case MCSymbolRefExpr::VK_Mips_TPREL_HI:
351     case MCSymbolRefExpr::VK_Mips_TPREL_LO:
352     case MCSymbolRefExpr::VK_PPC_DTPMOD:
353     case MCSymbolRefExpr::VK_PPC_TPREL:
354     case MCSymbolRefExpr::VK_PPC_TPREL_LO:
355     case MCSymbolRefExpr::VK_PPC_TPREL_HI:
356     case MCSymbolRefExpr::VK_PPC_TPREL_HA:
357     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
358     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
359     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
360     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
361     case MCSymbolRefExpr::VK_PPC_DTPREL:
362     case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
363     case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
364     case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
365     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
366     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
367     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
368     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
369     case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
370     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
371     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
372     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
373     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
374     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
375     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
376     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
377     case MCSymbolRefExpr::VK_PPC_TLS:
378     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
379     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
380     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
381     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
382     case MCSymbolRefExpr::VK_PPC_TLSGD:
383     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
384     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
385     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
386     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
387     case MCSymbolRefExpr::VK_PPC_TLSLD:
388       break;
389     }
390     MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
391     MCELF::SetType(SD, ELF::STT_TLS);
392     break;
393   }
394
395   case MCExpr::Unary:
396     fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
397     break;
398   }
399 }
400
401 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
402                                        const MCSubtargetInfo &STI) {
403   this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
404   MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
405
406   for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
407     fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
408 }
409
410 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
411                                    const MCSubtargetInfo &STI) {
412   MCAssembler &Assembler = getAssembler();
413   SmallVector<MCFixup, 4> Fixups;
414   SmallString<256> Code;
415   raw_svector_ostream VecOS(Code);
416   Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups, STI);
417   VecOS.flush();
418
419   for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
420     fixSymbolsInTLSFixups(Fixups[i].getValue());
421
422   // There are several possibilities here:
423   //
424   // If bundling is disabled, append the encoded instruction to the current data
425   // fragment (or create a new such fragment if the current fragment is not a
426   // data fragment).
427   //
428   // If bundling is enabled:
429   // - If we're not in a bundle-locked group, emit the instruction into a
430   //   fragment of its own. If there are no fixups registered for the
431   //   instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
432   //   MCDataFragment.
433   // - If we're in a bundle-locked group, append the instruction to the current
434   //   data fragment because we want all the instructions in a group to get into
435   //   the same fragment. Be careful not to do that for the first instruction in
436   //   the group, though.
437   MCDataFragment *DF;
438
439   if (Assembler.isBundlingEnabled()) {
440     MCSectionData *SD = getCurrentSectionData();
441     if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
442       // If we are bundle-locked, we re-use the current fragment.
443       // The bundle-locking directive ensures this is a new data fragment.
444       DF = cast<MCDataFragment>(getCurrentFragment());
445     else if (!SD->isBundleLocked() && Fixups.size() == 0) {
446       // Optimize memory usage by emitting the instruction to a
447       // MCCompactEncodedInstFragment when not in a bundle-locked group and
448       // there are no fixups registered.
449       MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
450       insert(CEIF);
451       CEIF->getContents().append(Code.begin(), Code.end());
452       return;
453     } else {
454       DF = new MCDataFragment();
455       insert(DF);
456     }
457     if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
458       // If this fragment is for a group marked "align_to_end", set a flag
459       // in the fragment. This can happen after the fragment has already been
460       // created if there are nested bundle_align groups and an inner one
461       // is the one marked align_to_end.
462       DF->setAlignToBundleEnd(true);
463     }
464
465     // We're now emitting an instruction in a bundle group, so this flag has
466     // to be turned off.
467     SD->setBundleGroupBeforeFirstInst(false);
468   } else {
469     DF = getOrCreateDataFragment();
470   }
471
472   // Add the fixups and data.
473   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
474     Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
475     DF->getFixups().push_back(Fixups[i]);
476   }
477   DF->setHasInstructions(true);
478   DF->getContents().append(Code.begin(), Code.end());
479 }
480
481 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
482   assert(AlignPow2 <= 30 && "Invalid bundle alignment");
483   MCAssembler &Assembler = getAssembler();
484   if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
485                         Assembler.getBundleAlignSize() == 1U << AlignPow2))
486     Assembler.setBundleAlignSize(1U << AlignPow2);
487   else
488     report_fatal_error(".bundle_align_mode cannot be changed once set");
489 }
490
491 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
492   MCSectionData *SD = getCurrentSectionData();
493
494   // Sanity checks
495   //
496   if (!getAssembler().isBundlingEnabled())
497     report_fatal_error(".bundle_lock forbidden when bundling is disabled");
498
499   if (!SD->isBundleLocked())
500     SD->setBundleGroupBeforeFirstInst(true);
501
502   SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd :
503                                       MCSectionData::BundleLocked);
504 }
505
506 void MCELFStreamer::EmitBundleUnlock() {
507   MCSectionData *SD = getCurrentSectionData();
508
509   // Sanity checks
510   if (!getAssembler().isBundlingEnabled())
511     report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
512   else if (!SD->isBundleLocked())
513     report_fatal_error(".bundle_unlock without matching lock");
514   else if (SD->isBundleGroupBeforeFirstInst())
515     report_fatal_error("Empty bundle-locked group is forbidden");
516
517   SD->setBundleLockState(MCSectionData::NotBundleLocked);
518 }
519
520 void MCELFStreamer::Flush() {
521   for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
522                                                 e = LocalCommons.end();
523        i != e; ++i) {
524     MCSymbolData *SD = i->SD;
525     uint64_t Size = i->Size;
526     unsigned ByteAlignment = i->ByteAlignment;
527     const MCSymbol &Symbol = SD->getSymbol();
528     const MCSection &Section = Symbol.getSection();
529
530     MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
531     new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
532
533     MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
534     SD->setFragment(F);
535
536     // Update the maximum alignment of the section if necessary.
537     if (ByteAlignment > SectData.getAlignment())
538       SectData.setAlignment(ByteAlignment);
539   }
540
541   LocalCommons.clear();
542 }
543
544 void MCELFStreamer::FinishImpl() {
545   EmitFrames(nullptr);
546
547   Flush();
548
549   this->MCObjectStreamer::FinishImpl();
550 }
551
552 MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
553                                     raw_ostream &OS, MCCodeEmitter *CE,
554                                     bool RelaxAll) {
555   MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
556   if (RelaxAll)
557     S->getAssembler().setRelaxAll(true);
558   return S;
559 }
560
561 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
562   llvm_unreachable("Generic ELF doesn't support this directive");
563 }
564
565 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
566   llvm_unreachable("ELF doesn't support this directive");
567 }
568
569 void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
570   llvm_unreachable("ELF doesn't support this directive");
571 }
572
573 void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
574   llvm_unreachable("ELF doesn't support this directive");
575 }
576
577 void MCELFStreamer::EmitCOFFSymbolType(int Type) {
578   llvm_unreachable("ELF doesn't support this directive");
579 }
580
581 void MCELFStreamer::EndCOFFSymbolDef() {
582   llvm_unreachable("ELF doesn't support this directive");
583 }
584
585 void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
586                                  uint64_t Size, unsigned ByteAlignment) {
587   llvm_unreachable("ELF doesn't support this directive");
588 }
589
590 void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
591                                    uint64_t Size, unsigned ByteAlignment) {
592   llvm_unreachable("ELF doesn't support this directive");
593 }