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