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/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/MCSymbolELF.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"
40 bool MCELFStreamer::isBundleLocked() const {
41 return getCurrentSectionOnly()->isBundleLocked();
44 MCELFStreamer::~MCELFStreamer() {
47 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
49 MCAssembler &Assembler = getAssembler();
51 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
52 uint64_t FSize = EF->getContents().size();
54 if (FSize > Assembler.getBundleAlignSize())
55 report_fatal_error("Fragment can't be larger than a bundle size");
57 uint64_t RequiredBundlePadding = computeBundlePadding(
58 Assembler, EF, DF->getContents().size(), FSize);
60 if (RequiredBundlePadding > UINT8_MAX)
61 report_fatal_error("Padding cannot exceed 255 bytes");
63 if (RequiredBundlePadding > 0) {
64 SmallString<256> Code;
65 raw_svector_ostream VecOS(Code);
66 MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
68 EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
70 Assembler.writeFragmentPadding(*EF, FSize, OW);
73 DF->getContents().append(Code.begin(), Code.end());
77 flushPendingLabels(DF, DF->getContents().size());
79 for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
80 EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
81 DF->getContents().size());
82 DF->getFixups().push_back(EF->getFixups()[i]);
84 DF->setHasInstructions(true);
85 DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
88 void MCELFStreamer::InitSections(bool NoExecStack) {
89 MCContext &Ctx = getContext();
90 SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
94 SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
97 void MCELFStreamer::EmitLabel(MCSymbol *S) {
98 auto *Symbol = cast<MCSymbolELF>(S);
99 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
101 MCObjectStreamer::EmitLabel(Symbol);
103 const MCSectionELF &Section =
104 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
105 if (Section.getFlags() & ELF::SHF_TLS)
106 Symbol->setType(ELF::STT_TLS);
109 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
110 // Let the target do whatever target specific stuff it needs to do.
111 getAssembler().getBackend().handleAssemblerFlag(Flag);
112 // Do any generic stuff we need to do.
114 case MCAF_SyntaxUnified: return; // no-op here.
115 case MCAF_Code16: return; // Change parsing mode; no-op here.
116 case MCAF_Code32: return; // Change parsing mode; no-op here.
117 case MCAF_Code64: return; // Change parsing mode; no-op here.
118 case MCAF_SubsectionsViaSymbols:
119 getAssembler().setSubsectionsViaSymbols(true);
123 llvm_unreachable("invalid assembler flag!");
126 // If bundle alignment is used and there are any instructions in the section, it
127 // needs to be aligned to at least the bundle size.
128 static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
129 MCSection *Section) {
130 if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
131 Section->getAlignment() < Assembler.getBundleAlignSize())
132 Section->setAlignment(Assembler.getBundleAlignSize());
135 void MCELFStreamer::ChangeSection(MCSection *Section,
136 const MCExpr *Subsection) {
137 MCSection *CurSection = getCurrentSectionOnly();
138 if (CurSection && isBundleLocked())
139 report_fatal_error("Unterminated .bundle_lock when changing a section");
141 MCAssembler &Asm = getAssembler();
142 // Ensure the previous section gets aligned if necessary.
143 setSectionAlignmentForBundling(Asm, CurSection);
144 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
145 const MCSymbol *Grp = SectionELF->getGroup();
147 Asm.registerSymbol(*Grp);
149 this->MCObjectStreamer::ChangeSection(Section, Subsection);
150 MCContext &Ctx = getContext();
151 auto *Begin = cast_or_null<MCSymbolELF>(Section->getBeginSymbol());
153 Begin = Ctx.getOrCreateSectionSymbol(*SectionELF);
154 Section->setBeginSymbol(Begin);
156 if (Begin->isUndefined()) {
157 Asm.registerSymbol(*Begin);
158 Begin->setType(ELF::STT_SECTION);
162 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
163 getAssembler().registerSymbol(*Symbol);
164 const MCExpr *Value = MCSymbolRefExpr::create(
165 Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
166 Alias->setVariableValue(Value);
169 // When GNU as encounters more than one .type declaration for an object it seems
170 // to use a mechanism similar to the one below to decide which type is actually
171 // used in the object file. The greater of T1 and T2 is selected based on the
172 // following ordering:
173 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
174 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
176 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
177 for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
178 ELF::STT_GNU_IFUNC, ELF::STT_TLS}) {
188 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
189 auto *Symbol = cast<MCSymbolELF>(S);
190 // Indirect symbols are handled differently, to match how 'as' handles
191 // them. This makes writing matching .o files easier.
192 if (Attribute == MCSA_IndirectSymbol) {
193 // Note that we intentionally cannot use the symbol data here; this is
194 // important for matching the string table that 'as' generates.
195 IndirectSymbolData ISD;
197 ISD.Section = getCurrentSectionOnly();
198 getAssembler().getIndirectSymbols().push_back(ISD);
202 // Adding a symbol attribute always introduces the symbol, note that an
203 // important side effect of calling registerSymbol here is to register
204 // the symbol with the assembler.
205 getAssembler().registerSymbol(*Symbol);
207 // The implementation of symbol attributes is designed to match 'as', but it
208 // leaves much to desired. It doesn't really make sense to arbitrarily add and
209 // remove flags, but 'as' allows this (in particular, see .desc).
211 // In the future it might be worth trying to make these operations more well
214 case MCSA_LazyReference:
216 case MCSA_SymbolResolver:
217 case MCSA_PrivateExtern:
218 case MCSA_WeakDefinition:
219 case MCSA_WeakDefAutoPrivate:
221 case MCSA_IndirectSymbol:
224 case MCSA_NoDeadStrip:
228 case MCSA_ELF_TypeGnuUniqueObject:
229 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
230 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
231 Symbol->setExternal(true);
235 Symbol->setBinding(ELF::STB_GLOBAL);
236 Symbol->setExternal(true);
239 case MCSA_WeakReference:
241 Symbol->setBinding(ELF::STB_WEAK);
242 Symbol->setExternal(true);
246 Symbol->setBinding(ELF::STB_LOCAL);
247 Symbol->setExternal(false);
250 case MCSA_ELF_TypeFunction:
251 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
254 case MCSA_ELF_TypeIndFunction:
255 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
258 case MCSA_ELF_TypeObject:
259 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
262 case MCSA_ELF_TypeTLS:
263 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
266 case MCSA_ELF_TypeCommon:
267 // TODO: Emit these as a common symbol.
268 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
271 case MCSA_ELF_TypeNoType:
272 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
276 Symbol->setVisibility(ELF::STV_PROTECTED);
280 Symbol->setVisibility(ELF::STV_HIDDEN);
284 Symbol->setVisibility(ELF::STV_INTERNAL);
291 void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
292 unsigned ByteAlignment) {
293 auto *Symbol = cast<MCSymbolELF>(S);
294 getAssembler().registerSymbol(*Symbol);
296 if (!Symbol->isBindingSet()) {
297 Symbol->setBinding(ELF::STB_GLOBAL);
298 Symbol->setExternal(true);
301 Symbol->setType(ELF::STT_OBJECT);
303 if (Symbol->getBinding() == ELF::STB_LOCAL) {
304 MCSection &Section = *getAssembler().getContext().getELFSection(
305 ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
306 MCSectionSubPair P = getCurrentSection();
307 SwitchSection(&Section);
309 EmitValueToAlignment(ByteAlignment, 0, 1, 0);
313 // Update the maximum alignment of the section if necessary.
314 if (ByteAlignment > Section.getAlignment())
315 Section.setAlignment(ByteAlignment);
317 SwitchSection(P.first, P.second);
319 if(Symbol->declareCommon(Size, ByteAlignment))
320 report_fatal_error("Symbol: " + Symbol->getName() +
321 " redeclared as different type");
324 cast<MCSymbolELF>(Symbol)
325 ->setSize(MCConstantExpr::create(Size, getContext()));
328 void MCELFStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
329 Symbol->setSize(Value);
332 void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
333 unsigned ByteAlignment) {
334 auto *Symbol = cast<MCSymbolELF>(S);
335 // FIXME: Should this be caught and done earlier?
336 getAssembler().registerSymbol(*Symbol);
337 Symbol->setBinding(ELF::STB_LOCAL);
338 Symbol->setExternal(false);
339 EmitCommonSymbol(Symbol, Size, ByteAlignment);
342 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
344 if (isBundleLocked())
345 report_fatal_error("Emitting values inside a locked bundle is forbidden");
346 fixSymbolsInTLSFixups(Value);
347 MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
350 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
353 unsigned MaxBytesToEmit) {
354 if (isBundleLocked())
355 report_fatal_error("Emitting values inside a locked bundle is forbidden");
356 MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
357 ValueSize, MaxBytesToEmit);
360 // Add a symbol for the file name of this module. They start after the
361 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
362 // with the same name may appear.
363 void MCELFStreamer::EmitFileDirective(StringRef Filename) {
364 getAssembler().addFileName(Filename);
367 void MCELFStreamer::EmitIdent(StringRef IdentString) {
368 MCSection *Comment = getAssembler().getContext().getELFSection(
369 ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
371 SwitchSection(Comment);
376 EmitBytes(IdentString);
381 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
382 switch (expr->getKind()) {
384 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
386 case MCExpr::Constant:
389 case MCExpr::Binary: {
390 const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
391 fixSymbolsInTLSFixups(be->getLHS());
392 fixSymbolsInTLSFixups(be->getRHS());
396 case MCExpr::SymbolRef: {
397 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
398 switch (symRef.getKind()) {
401 case MCSymbolRefExpr::VK_GOTTPOFF:
402 case MCSymbolRefExpr::VK_INDNTPOFF:
403 case MCSymbolRefExpr::VK_NTPOFF:
404 case MCSymbolRefExpr::VK_GOTNTPOFF:
405 case MCSymbolRefExpr::VK_TLSGD:
406 case MCSymbolRefExpr::VK_TLSLD:
407 case MCSymbolRefExpr::VK_TLSLDM:
408 case MCSymbolRefExpr::VK_TPOFF:
409 case MCSymbolRefExpr::VK_DTPOFF:
410 case MCSymbolRefExpr::VK_Mips_TLSGD:
411 case MCSymbolRefExpr::VK_Mips_GOTTPREL:
412 case MCSymbolRefExpr::VK_Mips_TPREL_HI:
413 case MCSymbolRefExpr::VK_Mips_TPREL_LO:
414 case MCSymbolRefExpr::VK_PPC_DTPMOD:
415 case MCSymbolRefExpr::VK_PPC_TPREL:
416 case MCSymbolRefExpr::VK_PPC_TPREL_LO:
417 case MCSymbolRefExpr::VK_PPC_TPREL_HI:
418 case MCSymbolRefExpr::VK_PPC_TPREL_HA:
419 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
420 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
421 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
422 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
423 case MCSymbolRefExpr::VK_PPC_DTPREL:
424 case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
425 case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
426 case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
427 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
428 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
429 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
430 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
431 case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
432 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
433 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
434 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
435 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
436 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
437 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
438 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
439 case MCSymbolRefExpr::VK_PPC_TLS:
440 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
441 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
442 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
443 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
444 case MCSymbolRefExpr::VK_PPC_TLSGD:
445 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
446 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
447 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
448 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
449 case MCSymbolRefExpr::VK_PPC_TLSLD:
452 getAssembler().registerSymbol(symRef.getSymbol());
453 cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
458 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
463 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
464 const MCSubtargetInfo &STI) {
465 this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
466 MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
468 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
469 fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
472 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
473 const MCSubtargetInfo &STI) {
474 MCAssembler &Assembler = getAssembler();
475 SmallVector<MCFixup, 4> Fixups;
476 SmallString<256> Code;
477 raw_svector_ostream VecOS(Code);
478 Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
480 for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
481 fixSymbolsInTLSFixups(Fixups[i].getValue());
483 // There are several possibilities here:
485 // If bundling is disabled, append the encoded instruction to the current data
486 // fragment (or create a new such fragment if the current fragment is not a
489 // If bundling is enabled:
490 // - If we're not in a bundle-locked group, emit the instruction into a
491 // fragment of its own. If there are no fixups registered for the
492 // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
494 // - If we're in a bundle-locked group, append the instruction to the current
495 // data fragment because we want all the instructions in a group to get into
496 // the same fragment. Be careful not to do that for the first instruction in
497 // the group, though.
500 if (Assembler.isBundlingEnabled()) {
501 MCSection &Sec = *getCurrentSectionOnly();
502 if (Assembler.getRelaxAll() && isBundleLocked())
503 // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
504 // the current bundle group.
505 DF = BundleGroups.back();
506 else if (Assembler.getRelaxAll() && !isBundleLocked())
507 // When not in a bundle-locked group and the -mc-relax-all flag is used,
508 // we create a new temporary fragment which will be later merged into
509 // the current fragment.
510 DF = new MCDataFragment();
511 else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
512 // If we are bundle-locked, we re-use the current fragment.
513 // The bundle-locking directive ensures this is a new data fragment.
514 DF = cast<MCDataFragment>(getCurrentFragment());
515 else if (!isBundleLocked() && Fixups.size() == 0) {
516 // Optimize memory usage by emitting the instruction to a
517 // MCCompactEncodedInstFragment when not in a bundle-locked group and
518 // there are no fixups registered.
519 MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
521 CEIF->getContents().append(Code.begin(), Code.end());
524 DF = new MCDataFragment();
527 if (Sec.getBundleLockState() == MCSection::BundleLockedAlignToEnd) {
528 // If this fragment is for a group marked "align_to_end", set a flag
529 // in the fragment. This can happen after the fragment has already been
530 // created if there are nested bundle_align groups and an inner one
531 // is the one marked align_to_end.
532 DF->setAlignToBundleEnd(true);
535 // We're now emitting an instruction in a bundle group, so this flag has
537 Sec.setBundleGroupBeforeFirstInst(false);
539 DF = getOrCreateDataFragment();
542 // Add the fixups and data.
543 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
544 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
545 DF->getFixups().push_back(Fixups[i]);
547 DF->setHasInstructions(true);
548 DF->getContents().append(Code.begin(), Code.end());
550 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
551 if (!isBundleLocked()) {
552 mergeFragment(getOrCreateDataFragment(), DF);
558 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
559 assert(AlignPow2 <= 30 && "Invalid bundle alignment");
560 MCAssembler &Assembler = getAssembler();
561 if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
562 Assembler.getBundleAlignSize() == 1U << AlignPow2))
563 Assembler.setBundleAlignSize(1U << AlignPow2);
565 report_fatal_error(".bundle_align_mode cannot be changed once set");
568 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
569 MCSection &Sec = *getCurrentSectionOnly();
573 if (!getAssembler().isBundlingEnabled())
574 report_fatal_error(".bundle_lock forbidden when bundling is disabled");
576 if (!isBundleLocked())
577 Sec.setBundleGroupBeforeFirstInst(true);
579 if (getAssembler().getRelaxAll() && !isBundleLocked()) {
580 // TODO: drop the lock state and set directly in the fragment
581 MCDataFragment *DF = new MCDataFragment();
582 BundleGroups.push_back(DF);
585 Sec.setBundleLockState(AlignToEnd ? MCSection::BundleLockedAlignToEnd
586 : MCSection::BundleLocked);
589 void MCELFStreamer::EmitBundleUnlock() {
590 MCSection &Sec = *getCurrentSectionOnly();
593 if (!getAssembler().isBundlingEnabled())
594 report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
595 else if (!isBundleLocked())
596 report_fatal_error(".bundle_unlock without matching lock");
597 else if (Sec.isBundleGroupBeforeFirstInst())
598 report_fatal_error("Empty bundle-locked group is forbidden");
600 // When the -mc-relax-all flag is used, we emit instructions to fragments
601 // stored on a stack. When the bundle unlock is emitted, we pop a fragment
602 // from the stack a merge it to the one below.
603 if (getAssembler().getRelaxAll()) {
604 assert(!BundleGroups.empty() && "There are no bundle groups");
605 MCDataFragment *DF = BundleGroups.back();
607 // FIXME: Use BundleGroups to track the lock state instead.
608 Sec.setBundleLockState(MCSection::NotBundleLocked);
610 // FIXME: Use more separate fragments for nested groups.
611 if (!isBundleLocked()) {
612 mergeFragment(getOrCreateDataFragment(), DF);
613 BundleGroups.pop_back();
617 if (Sec.getBundleLockState() != MCSection::BundleLockedAlignToEnd)
618 getOrCreateDataFragment()->setAlignToBundleEnd(false);
620 Sec.setBundleLockState(MCSection::NotBundleLocked);
623 void MCELFStreamer::FinishImpl() {
624 // Ensure the last section gets aligned if necessary.
625 MCSection *CurSection = getCurrentSectionOnly();
626 setSectionAlignmentForBundling(getAssembler(), CurSection);
630 this->MCObjectStreamer::FinishImpl();
633 MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
634 raw_pwrite_stream &OS, MCCodeEmitter *CE,
636 MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
638 S->getAssembler().setRelaxAll(true);
642 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
643 llvm_unreachable("Generic ELF doesn't support this directive");
646 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
647 llvm_unreachable("ELF doesn't support this directive");
650 void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
651 llvm_unreachable("ELF doesn't support this directive");
654 void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
655 llvm_unreachable("ELF doesn't support this directive");
658 void MCELFStreamer::EmitCOFFSymbolType(int Type) {
659 llvm_unreachable("ELF doesn't support this directive");
662 void MCELFStreamer::EndCOFFSymbolDef() {
663 llvm_unreachable("ELF doesn't support this directive");
666 void MCELFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
667 uint64_t Size, unsigned ByteAlignment) {
668 llvm_unreachable("ELF doesn't support this directive");
671 void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
672 uint64_t Size, unsigned ByteAlignment) {
673 llvm_unreachable("ELF doesn't support this directive");