1 //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file assembles .s files and emits ELF .o object files.
12 //===----------------------------------------------------------------------===//
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/MCAsmLayout.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCAssembler.h"
21 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCELF.h"
24 #include "llvm/MC/MCELFSymbolFlags.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCObjectFileInfo.h"
28 #include "llvm/MC/MCObjectStreamer.h"
29 #include "llvm/MC/MCSection.h"
30 #include "llvm/MC/MCSectionELF.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCValue.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ELF.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/TargetRegistry.h"
37 #include "llvm/Support/raw_ostream.h"
41 MCELFStreamer::~MCELFStreamer() {
44 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
45 MCEncodedFragmentWithFixups *EF) {
46 MCAssembler &Assembler = getAssembler();
48 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
49 uint64_t FSize = EF->getContents().size();
51 if (FSize > Assembler.getBundleAlignSize())
52 report_fatal_error("Fragment can't be larger than a bundle size");
54 uint64_t RequiredBundlePadding = computeBundlePadding(
55 Assembler, EF, DF->getContents().size(), FSize);
57 if (RequiredBundlePadding > UINT8_MAX)
58 report_fatal_error("Padding cannot exceed 255 bytes");
60 if (RequiredBundlePadding > 0) {
61 SmallString<256> Code;
62 raw_svector_ostream VecOS(Code);
63 MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
65 EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
67 Assembler.writeFragmentPadding(*EF, FSize, OW);
71 DF->getContents().append(Code.begin(), Code.end());
75 flushPendingLabels(DF, DF->getContents().size());
77 for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
78 EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
79 DF->getContents().size());
80 DF->getFixups().push_back(EF->getFixups()[i]);
82 DF->setHasInstructions(true);
83 DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
86 void MCELFStreamer::InitSections(bool NoExecStack) {
87 // This emulates the same behavior of GNU as. This makes it easier
88 // to compare the output as the major sections are in the same order.
89 MCContext &Ctx = getContext();
90 SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
93 SwitchSection(Ctx.getObjectFileInfo()->getDataSection());
96 SwitchSection(Ctx.getObjectFileInfo()->getBSSSection());
99 SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
102 SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
105 void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
106 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
108 MCObjectStreamer::EmitLabel(Symbol);
110 const MCSectionELF &Section =
111 static_cast<const MCSectionELF&>(Symbol->getSection());
112 MCSymbolData &SD = getAssembler().getSymbolData(*Symbol);
113 if (Section.getFlags() & ELF::SHF_TLS)
114 MCELF::SetType(SD, ELF::STT_TLS);
117 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
118 // Let the target do whatever target specific stuff it needs to do.
119 getAssembler().getBackend().handleAssemblerFlag(Flag);
120 // Do any generic stuff we need to do.
122 case MCAF_SyntaxUnified: return; // no-op here.
123 case MCAF_Code16: return; // Change parsing mode; no-op here.
124 case MCAF_Code32: return; // Change parsing mode; no-op here.
125 case MCAF_Code64: return; // Change parsing mode; no-op here.
126 case MCAF_SubsectionsViaSymbols:
127 getAssembler().setSubsectionsViaSymbols(true);
131 llvm_unreachable("invalid assembler flag!");
134 void MCELFStreamer::ChangeSection(const MCSection *Section,
135 const MCExpr *Subsection) {
136 MCSectionData *CurSection = getCurrentSectionData();
137 if (CurSection && CurSection->isBundleLocked())
138 report_fatal_error("Unterminated .bundle_lock when changing a section");
140 MCAssembler &Asm = getAssembler();
141 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
142 const MCSymbol *Grp = SectionELF->getGroup();
144 Asm.getOrCreateSymbolData(*Grp);
146 this->MCObjectStreamer::ChangeSection(Section, Subsection);
147 MCSymbol *SectionSymbol = getContext().getOrCreateSectionSymbol(*SectionELF);
148 if (SectionSymbol->isUndefined()) {
149 EmitLabel(SectionSymbol);
150 MCELF::SetType(Asm.getSymbolData(*SectionSymbol), ELF::STT_SECTION);
154 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
155 getAssembler().getOrCreateSymbolData(*Symbol);
156 const MCExpr *Value = MCSymbolRefExpr::Create(
157 Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
158 Alias->setVariableValue(Value);
161 // When GNU as encounters more than one .type declaration for an object it seems
162 // to use a mechanism similar to the one below to decide which type is actually
163 // used in the object file. The greater of T1 and T2 is selected based on the
164 // following ordering:
165 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
166 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
168 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
169 for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
170 ELF::STT_GNU_IFUNC, ELF::STT_TLS}) {
180 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
181 MCSymbolAttr Attribute) {
182 // Indirect symbols are handled differently, to match how 'as' handles
183 // them. This makes writing matching .o files easier.
184 if (Attribute == MCSA_IndirectSymbol) {
185 // Note that we intentionally cannot use the symbol data here; this is
186 // important for matching the string table that 'as' generates.
187 IndirectSymbolData ISD;
189 ISD.SectionData = getCurrentSectionData();
190 getAssembler().getIndirectSymbols().push_back(ISD);
194 // Adding a symbol attribute always introduces the symbol, note that an
195 // important side effect of calling getOrCreateSymbolData here is to register
196 // the symbol with the assembler.
197 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
199 // The implementation of symbol attributes is designed to match 'as', but it
200 // leaves much to desired. It doesn't really make sense to arbitrarily add and
201 // remove flags, but 'as' allows this (in particular, see .desc).
203 // In the future it might be worth trying to make these operations more well
206 case MCSA_LazyReference:
208 case MCSA_SymbolResolver:
209 case MCSA_PrivateExtern:
210 case MCSA_WeakDefinition:
211 case MCSA_WeakDefAutoPrivate:
213 case MCSA_IndirectSymbol:
216 case MCSA_NoDeadStrip:
220 case MCSA_ELF_TypeGnuUniqueObject:
221 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), ELF::STT_OBJECT));
222 MCELF::SetBinding(SD, ELF::STB_GNU_UNIQUE);
223 SD.setExternal(true);
224 BindingExplicitlySet.insert(Symbol);
228 MCELF::SetBinding(SD, ELF::STB_GLOBAL);
229 SD.setExternal(true);
230 BindingExplicitlySet.insert(Symbol);
233 case MCSA_WeakReference:
235 MCELF::SetBinding(SD, ELF::STB_WEAK);
236 SD.setExternal(true);
237 BindingExplicitlySet.insert(Symbol);
241 MCELF::SetBinding(SD, ELF::STB_LOCAL);
242 SD.setExternal(false);
243 BindingExplicitlySet.insert(Symbol);
246 case MCSA_ELF_TypeFunction:
247 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
251 case MCSA_ELF_TypeIndFunction:
252 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
253 ELF::STT_GNU_IFUNC));
256 case MCSA_ELF_TypeObject:
257 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
261 case MCSA_ELF_TypeTLS:
262 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
266 case MCSA_ELF_TypeCommon:
267 // TODO: Emit these as a common symbol.
268 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
272 case MCSA_ELF_TypeNoType:
273 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
278 MCELF::SetVisibility(SD, ELF::STV_PROTECTED);
282 MCELF::SetVisibility(SD, ELF::STV_HIDDEN);
286 MCELF::SetVisibility(SD, ELF::STV_INTERNAL);
293 void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
294 unsigned ByteAlignment) {
295 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
297 if (!BindingExplicitlySet.count(Symbol)) {
298 MCELF::SetBinding(SD, ELF::STB_GLOBAL);
299 SD.setExternal(true);
302 MCELF::SetType(SD, ELF::STT_OBJECT);
304 if (MCELF::GetBinding(SD) == ELF_STB_Local) {
305 const MCSection *Section = getAssembler().getContext().getELFSection(
306 ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
308 AssignSection(Symbol, Section);
310 struct LocalCommon L = {&SD, Size, ByteAlignment};
311 LocalCommons.push_back(L);
313 SD.setCommon(Size, ByteAlignment);
316 SD.setSize(MCConstantExpr::Create(Size, getContext()));
319 void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
320 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
324 void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
325 unsigned ByteAlignment) {
326 // FIXME: Should this be caught and done earlier?
327 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
328 MCELF::SetBinding(SD, ELF::STB_LOCAL);
329 SD.setExternal(false);
330 BindingExplicitlySet.insert(Symbol);
331 EmitCommonSymbol(Symbol, Size, ByteAlignment);
334 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
336 if (getCurrentSectionData()->isBundleLocked())
337 report_fatal_error("Emitting values inside a locked bundle is forbidden");
338 fixSymbolsInTLSFixups(Value);
339 MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
342 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
345 unsigned MaxBytesToEmit) {
346 if (getCurrentSectionData()->isBundleLocked())
347 report_fatal_error("Emitting values inside a locked bundle is forbidden");
348 MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
349 ValueSize, MaxBytesToEmit);
352 // Add a symbol for the file name of this module. They start after the
353 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
354 // with the same name may appear.
355 void MCELFStreamer::EmitFileDirective(StringRef Filename) {
356 getAssembler().addFileName(Filename);
359 void MCELFStreamer::EmitIdent(StringRef IdentString) {
360 const MCSection *Comment = getAssembler().getContext().getELFSection(
361 ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
363 SwitchSection(Comment);
368 EmitBytes(IdentString);
373 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
374 switch (expr->getKind()) {
376 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
378 case MCExpr::Constant:
381 case MCExpr::Binary: {
382 const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
383 fixSymbolsInTLSFixups(be->getLHS());
384 fixSymbolsInTLSFixups(be->getRHS());
388 case MCExpr::SymbolRef: {
389 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
390 switch (symRef.getKind()) {
393 case MCSymbolRefExpr::VK_GOTTPOFF:
394 case MCSymbolRefExpr::VK_INDNTPOFF:
395 case MCSymbolRefExpr::VK_NTPOFF:
396 case MCSymbolRefExpr::VK_GOTNTPOFF:
397 case MCSymbolRefExpr::VK_TLSGD:
398 case MCSymbolRefExpr::VK_TLSLD:
399 case MCSymbolRefExpr::VK_TLSLDM:
400 case MCSymbolRefExpr::VK_TPOFF:
401 case MCSymbolRefExpr::VK_DTPOFF:
402 case MCSymbolRefExpr::VK_Mips_TLSGD:
403 case MCSymbolRefExpr::VK_Mips_GOTTPREL:
404 case MCSymbolRefExpr::VK_Mips_TPREL_HI:
405 case MCSymbolRefExpr::VK_Mips_TPREL_LO:
406 case MCSymbolRefExpr::VK_PPC_DTPMOD:
407 case MCSymbolRefExpr::VK_PPC_TPREL:
408 case MCSymbolRefExpr::VK_PPC_TPREL_LO:
409 case MCSymbolRefExpr::VK_PPC_TPREL_HI:
410 case MCSymbolRefExpr::VK_PPC_TPREL_HA:
411 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
412 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
413 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
414 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
415 case MCSymbolRefExpr::VK_PPC_DTPREL:
416 case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
417 case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
418 case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
419 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
420 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
421 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
422 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
423 case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
424 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
425 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
426 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
427 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
428 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
429 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
430 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
431 case MCSymbolRefExpr::VK_PPC_TLS:
432 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
433 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
434 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
435 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
436 case MCSymbolRefExpr::VK_PPC_TLSGD:
437 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
438 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
439 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
440 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
441 case MCSymbolRefExpr::VK_PPC_TLSLD:
444 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
445 MCELF::SetType(SD, ELF::STT_TLS);
450 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
455 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
456 const MCSubtargetInfo &STI) {
457 this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
458 MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
460 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
461 fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
464 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
465 const MCSubtargetInfo &STI) {
466 MCAssembler &Assembler = getAssembler();
467 SmallVector<MCFixup, 4> Fixups;
468 SmallString<256> Code;
469 raw_svector_ostream VecOS(Code);
470 Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups, STI);
473 for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
474 fixSymbolsInTLSFixups(Fixups[i].getValue());
476 // There are several possibilities here:
478 // If bundling is disabled, append the encoded instruction to the current data
479 // fragment (or create a new such fragment if the current fragment is not a
482 // If bundling is enabled:
483 // - If we're not in a bundle-locked group, emit the instruction into a
484 // fragment of its own. If there are no fixups registered for the
485 // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
487 // - If we're in a bundle-locked group, append the instruction to the current
488 // data fragment because we want all the instructions in a group to get into
489 // the same fragment. Be careful not to do that for the first instruction in
490 // the group, though.
493 if (Assembler.isBundlingEnabled()) {
494 MCSectionData *SD = getCurrentSectionData();
495 if (Assembler.getRelaxAll() && SD->isBundleLocked())
496 // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
497 // the current bundle group.
498 DF = BundleGroups.back();
499 else if (Assembler.getRelaxAll() && !SD->isBundleLocked())
500 // When not in a bundle-locked group and the -mc-relax-all flag is used,
501 // we create a new temporary fragment which will be later merged into
502 // the current fragment.
503 DF = new MCDataFragment();
504 else if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
505 // If we are bundle-locked, we re-use the current fragment.
506 // The bundle-locking directive ensures this is a new data fragment.
507 DF = cast<MCDataFragment>(getCurrentFragment());
508 else if (!SD->isBundleLocked() && Fixups.size() == 0) {
509 // Optimize memory usage by emitting the instruction to a
510 // MCCompactEncodedInstFragment when not in a bundle-locked group and
511 // there are no fixups registered.
512 MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
514 CEIF->getContents().append(Code.begin(), Code.end());
517 DF = new MCDataFragment();
520 if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
521 // If this fragment is for a group marked "align_to_end", set a flag
522 // in the fragment. This can happen after the fragment has already been
523 // created if there are nested bundle_align groups and an inner one
524 // is the one marked align_to_end.
525 DF->setAlignToBundleEnd(true);
528 // We're now emitting an instruction in a bundle group, so this flag has
530 SD->setBundleGroupBeforeFirstInst(false);
532 DF = getOrCreateDataFragment();
535 // Add the fixups and data.
536 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
537 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
538 DF->getFixups().push_back(Fixups[i]);
540 DF->setHasInstructions(true);
541 DF->getContents().append(Code.begin(), Code.end());
543 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
544 MCSectionData *SD = getCurrentSectionData();
545 if (!SD->isBundleLocked()) {
546 mergeFragment(getOrCreateDataFragment(), DF);
552 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
553 assert(AlignPow2 <= 30 && "Invalid bundle alignment");
554 MCAssembler &Assembler = getAssembler();
555 if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
556 Assembler.getBundleAlignSize() == 1U << AlignPow2))
557 Assembler.setBundleAlignSize(1U << AlignPow2);
559 report_fatal_error(".bundle_align_mode cannot be changed once set");
562 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
563 MCSectionData *SD = getCurrentSectionData();
567 if (!getAssembler().isBundlingEnabled())
568 report_fatal_error(".bundle_lock forbidden when bundling is disabled");
570 if (!SD->isBundleLocked())
571 SD->setBundleGroupBeforeFirstInst(true);
573 if (getAssembler().getRelaxAll() && !SD->isBundleLocked()) {
574 // TODO: drop the lock state and set directly in the fragment
575 MCDataFragment *DF = new MCDataFragment();
576 BundleGroups.push_back(DF);
579 SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd :
580 MCSectionData::BundleLocked);
583 void MCELFStreamer::EmitBundleUnlock() {
584 MCSectionData *SD = getCurrentSectionData();
587 if (!getAssembler().isBundlingEnabled())
588 report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
589 else if (!SD->isBundleLocked())
590 report_fatal_error(".bundle_unlock without matching lock");
591 else if (SD->isBundleGroupBeforeFirstInst())
592 report_fatal_error("Empty bundle-locked group is forbidden");
594 // When the -mc-relax-all flag is used, we emit instructions to fragments
595 // stored on a stack. When the bundle unlock is emited, we pop a fragment
596 // from the stack a merge it to the one below.
597 if (getAssembler().getRelaxAll()) {
598 assert(!BundleGroups.empty() && "There are no bundle groups");
599 MCDataFragment *DF = BundleGroups.back();
601 // FIXME: Use BundleGroups to track the lock state instead.
602 SD->setBundleLockState(MCSectionData::NotBundleLocked);
604 // FIXME: Use more separate fragments for nested groups.
605 if (!SD->isBundleLocked()) {
606 mergeFragment(getOrCreateDataFragment(), DF);
607 BundleGroups.pop_back();
611 if (SD->getBundleLockState() != MCSectionData::BundleLockedAlignToEnd)
612 getOrCreateDataFragment()->setAlignToBundleEnd(false);
614 SD->setBundleLockState(MCSectionData::NotBundleLocked);
617 void MCELFStreamer::Flush() {
618 for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
619 e = LocalCommons.end();
621 MCSymbolData *SD = i->SD;
622 uint64_t Size = i->Size;
623 unsigned ByteAlignment = i->ByteAlignment;
624 const MCSymbol &Symbol = SD->getSymbol();
625 const MCSection &Section = Symbol.getSection();
627 MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
628 new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
630 MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
633 // Update the maximum alignment of the section if necessary.
634 if (ByteAlignment > SectData.getAlignment())
635 SectData.setAlignment(ByteAlignment);
638 LocalCommons.clear();
641 void MCELFStreamer::FinishImpl() {
646 this->MCObjectStreamer::FinishImpl();
649 MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
650 raw_pwrite_stream &OS, MCCodeEmitter *CE,
652 MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
654 S->getAssembler().setRelaxAll(true);
658 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
659 llvm_unreachable("Generic ELF doesn't support this directive");
662 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
663 llvm_unreachable("ELF doesn't support this directive");
666 void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
667 llvm_unreachable("ELF doesn't support this directive");
670 void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
671 llvm_unreachable("ELF doesn't support this directive");
674 void MCELFStreamer::EmitCOFFSymbolType(int Type) {
675 llvm_unreachable("ELF doesn't support this directive");
678 void MCELFStreamer::EndCOFFSymbolDef() {
679 llvm_unreachable("ELF doesn't support this directive");
682 void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
683 uint64_t Size, unsigned ByteAlignment) {
684 llvm_unreachable("ELF doesn't support this directive");
687 void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
688 uint64_t Size, unsigned ByteAlignment) {
689 llvm_unreachable("ELF doesn't support this directive");