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/SmallString.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/MC/MCAsmBackend.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/MCFixup.h"
25 #include "llvm/MC/MCFragment.h"
26 #include "llvm/MC/MCObjectFileInfo.h"
27 #include "llvm/MC/MCObjectWriter.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCSectionELF.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCSymbolELF.h"
33 #include "llvm/Support/Casting.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/TargetRegistry.h"
36 #include "llvm/Support/raw_ostream.h"
42 MCELFStreamer::MCELFStreamer(MCContext &Context,
43 std::unique_ptr<MCAsmBackend> TAB,
44 raw_pwrite_stream &OS,
45 std::unique_ptr<MCCodeEmitter> Emitter)
46 : MCObjectStreamer(Context, std::move(TAB), OS, std::move(Emitter)) {}
48 bool MCELFStreamer::isBundleLocked() const {
49 return getCurrentSectionOnly()->isBundleLocked();
52 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
54 MCAssembler &Assembler = getAssembler();
56 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
57 uint64_t FSize = EF->getContents().size();
59 if (FSize > Assembler.getBundleAlignSize())
60 report_fatal_error("Fragment can't be larger than a bundle size");
62 uint64_t RequiredBundlePadding = computeBundlePadding(
63 Assembler, EF, DF->getContents().size(), FSize);
65 if (RequiredBundlePadding > UINT8_MAX)
66 report_fatal_error("Padding cannot exceed 255 bytes");
68 if (RequiredBundlePadding > 0) {
69 SmallString<256> Code;
70 raw_svector_ostream VecOS(Code);
72 auto OW = Assembler.getBackend().createObjectWriter(VecOS);
74 EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
76 Assembler.writeFragmentPadding(*EF, FSize, OW.get());
79 DF->getContents().append(Code.begin(), Code.end());
83 flushPendingLabels(DF, DF->getContents().size());
85 for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
86 EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
87 DF->getContents().size());
88 DF->getFixups().push_back(EF->getFixups()[i]);
90 DF->setHasInstructions(true);
91 DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
94 void MCELFStreamer::InitSections(bool NoExecStack) {
95 MCContext &Ctx = getContext();
96 SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
100 SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
103 void MCELFStreamer::EmitLabel(MCSymbol *S, SMLoc Loc) {
104 auto *Symbol = cast<MCSymbolELF>(S);
105 MCObjectStreamer::EmitLabel(Symbol, Loc);
107 const MCSectionELF &Section =
108 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
109 if (Section.getFlags() & ELF::SHF_TLS)
110 Symbol->setType(ELF::STT_TLS);
113 void MCELFStreamer::EmitLabel(MCSymbol *S, SMLoc Loc, MCFragment *F) {
114 auto *Symbol = cast<MCSymbolELF>(S);
115 MCObjectStreamer::EmitLabel(Symbol, Loc, F);
117 const MCSectionELF &Section =
118 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
119 if (Section.getFlags() & ELF::SHF_TLS)
120 Symbol->setType(ELF::STT_TLS);
123 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
124 // Let the target do whatever target specific stuff it needs to do.
125 getAssembler().getBackend().handleAssemblerFlag(Flag);
126 // Do any generic stuff we need to do.
128 case MCAF_SyntaxUnified: return; // no-op here.
129 case MCAF_Code16: return; // Change parsing mode; no-op here.
130 case MCAF_Code32: return; // Change parsing mode; no-op here.
131 case MCAF_Code64: return; // Change parsing mode; no-op here.
132 case MCAF_SubsectionsViaSymbols:
133 getAssembler().setSubsectionsViaSymbols(true);
137 llvm_unreachable("invalid assembler flag!");
140 // If bundle alignment is used and there are any instructions in the section, it
141 // needs to be aligned to at least the bundle size.
142 static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
143 MCSection *Section) {
144 if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
145 Section->getAlignment() < Assembler.getBundleAlignSize())
146 Section->setAlignment(Assembler.getBundleAlignSize());
149 void MCELFStreamer::ChangeSection(MCSection *Section,
150 const MCExpr *Subsection) {
151 MCSection *CurSection = getCurrentSectionOnly();
152 if (CurSection && isBundleLocked())
153 report_fatal_error("Unterminated .bundle_lock when changing a section");
155 MCAssembler &Asm = getAssembler();
156 // Ensure the previous section gets aligned if necessary.
157 setSectionAlignmentForBundling(Asm, CurSection);
158 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
159 const MCSymbol *Grp = SectionELF->getGroup();
161 Asm.registerSymbol(*Grp);
163 changeSectionImpl(Section, Subsection);
164 Asm.registerSymbol(*Section->getBeginSymbol());
167 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
168 getAssembler().registerSymbol(*Symbol);
169 const MCExpr *Value = MCSymbolRefExpr::create(
170 Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
171 Alias->setVariableValue(Value);
174 // When GNU as encounters more than one .type declaration for an object it seems
175 // to use a mechanism similar to the one below to decide which type is actually
176 // used in the object file. The greater of T1 and T2 is selected based on the
177 // following ordering:
178 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
179 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
181 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
182 for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
183 ELF::STT_GNU_IFUNC, ELF::STT_TLS}) {
193 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
194 auto *Symbol = cast<MCSymbolELF>(S);
195 // Indirect symbols are handled differently, to match how 'as' handles
196 // them. This makes writing matching .o files easier.
197 if (Attribute == MCSA_IndirectSymbol) {
198 // Note that we intentionally cannot use the symbol data here; this is
199 // important for matching the string table that 'as' generates.
200 IndirectSymbolData ISD;
202 ISD.Section = getCurrentSectionOnly();
203 getAssembler().getIndirectSymbols().push_back(ISD);
207 // Adding a symbol attribute always introduces the symbol, note that an
208 // important side effect of calling registerSymbol here is to register
209 // the symbol with the assembler.
210 getAssembler().registerSymbol(*Symbol);
212 // The implementation of symbol attributes is designed to match 'as', but it
213 // leaves much to desired. It doesn't really make sense to arbitrarily add and
214 // remove flags, but 'as' allows this (in particular, see .desc).
216 // In the future it might be worth trying to make these operations more well
219 case MCSA_LazyReference:
221 case MCSA_SymbolResolver:
222 case MCSA_PrivateExtern:
223 case MCSA_WeakDefinition:
224 case MCSA_WeakDefAutoPrivate:
226 case MCSA_IndirectSymbol:
229 case MCSA_NoDeadStrip:
233 case MCSA_ELF_TypeGnuUniqueObject:
234 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
235 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
236 Symbol->setExternal(true);
240 Symbol->setBinding(ELF::STB_GLOBAL);
241 Symbol->setExternal(true);
244 case MCSA_WeakReference:
246 Symbol->setBinding(ELF::STB_WEAK);
247 Symbol->setExternal(true);
251 Symbol->setBinding(ELF::STB_LOCAL);
252 Symbol->setExternal(false);
255 case MCSA_ELF_TypeFunction:
256 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
259 case MCSA_ELF_TypeIndFunction:
260 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
263 case MCSA_ELF_TypeObject:
264 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
267 case MCSA_ELF_TypeTLS:
268 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
271 case MCSA_ELF_TypeCommon:
272 // TODO: Emit these as a common symbol.
273 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
276 case MCSA_ELF_TypeNoType:
277 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
281 Symbol->setVisibility(ELF::STV_PROTECTED);
285 Symbol->setVisibility(ELF::STV_HIDDEN);
289 Symbol->setVisibility(ELF::STV_INTERNAL);
293 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
299 void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
300 unsigned ByteAlignment) {
301 auto *Symbol = cast<MCSymbolELF>(S);
302 getAssembler().registerSymbol(*Symbol);
304 if (!Symbol->isBindingSet()) {
305 Symbol->setBinding(ELF::STB_GLOBAL);
306 Symbol->setExternal(true);
309 Symbol->setType(ELF::STT_OBJECT);
311 if (Symbol->getBinding() == ELF::STB_LOCAL) {
312 MCSection &Section = *getAssembler().getContext().getELFSection(
313 ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
314 MCSectionSubPair P = getCurrentSection();
315 SwitchSection(&Section);
317 EmitValueToAlignment(ByteAlignment, 0, 1, 0);
321 // Update the maximum alignment of the section if necessary.
322 if (ByteAlignment > Section.getAlignment())
323 Section.setAlignment(ByteAlignment);
325 SwitchSection(P.first, P.second);
327 if(Symbol->declareCommon(Size, ByteAlignment))
328 report_fatal_error("Symbol: " + Symbol->getName() +
329 " redeclared as different type");
332 cast<MCSymbolELF>(Symbol)
333 ->setSize(MCConstantExpr::create(Size, getContext()));
336 void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
337 cast<MCSymbolELF>(Symbol)->setSize(Value);
340 void MCELFStreamer::emitELFSymverDirective(StringRef AliasName,
341 const MCSymbol *Aliasee) {
342 getAssembler().Symvers.push_back({AliasName, Aliasee});
345 void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
346 unsigned ByteAlignment) {
347 auto *Symbol = cast<MCSymbolELF>(S);
348 // FIXME: Should this be caught and done earlier?
349 getAssembler().registerSymbol(*Symbol);
350 Symbol->setBinding(ELF::STB_LOCAL);
351 Symbol->setExternal(false);
352 EmitCommonSymbol(Symbol, Size, ByteAlignment);
355 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
357 if (isBundleLocked())
358 report_fatal_error("Emitting values inside a locked bundle is forbidden");
359 fixSymbolsInTLSFixups(Value);
360 MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
363 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
366 unsigned MaxBytesToEmit) {
367 if (isBundleLocked())
368 report_fatal_error("Emitting values inside a locked bundle is forbidden");
369 MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
370 ValueSize, MaxBytesToEmit);
373 void MCELFStreamer::EmitIdent(StringRef IdentString) {
374 MCSection *Comment = getAssembler().getContext().getELFSection(
375 ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
377 SwitchSection(Comment);
382 EmitBytes(IdentString);
387 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
388 switch (expr->getKind()) {
390 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
392 case MCExpr::Constant:
395 case MCExpr::Binary: {
396 const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
397 fixSymbolsInTLSFixups(be->getLHS());
398 fixSymbolsInTLSFixups(be->getRHS());
402 case MCExpr::SymbolRef: {
403 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
404 switch (symRef.getKind()) {
407 case MCSymbolRefExpr::VK_GOTTPOFF:
408 case MCSymbolRefExpr::VK_INDNTPOFF:
409 case MCSymbolRefExpr::VK_NTPOFF:
410 case MCSymbolRefExpr::VK_GOTNTPOFF:
411 case MCSymbolRefExpr::VK_TLSGD:
412 case MCSymbolRefExpr::VK_TLSLD:
413 case MCSymbolRefExpr::VK_TLSLDM:
414 case MCSymbolRefExpr::VK_TPOFF:
415 case MCSymbolRefExpr::VK_TPREL:
416 case MCSymbolRefExpr::VK_DTPOFF:
417 case MCSymbolRefExpr::VK_DTPREL:
418 case MCSymbolRefExpr::VK_PPC_DTPMOD:
419 case MCSymbolRefExpr::VK_PPC_TPREL_LO:
420 case MCSymbolRefExpr::VK_PPC_TPREL_HI:
421 case MCSymbolRefExpr::VK_PPC_TPREL_HA:
422 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
423 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
424 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
425 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
426 case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
427 case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
428 case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
429 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
430 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
431 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
432 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
433 case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
434 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
435 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
436 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
437 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
438 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
439 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
440 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
441 case MCSymbolRefExpr::VK_PPC_TLS:
442 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
443 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
444 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
445 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
446 case MCSymbolRefExpr::VK_PPC_TLSGD:
447 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
448 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
449 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
450 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
451 case MCSymbolRefExpr::VK_PPC_TLSLD:
454 getAssembler().registerSymbol(symRef.getSymbol());
455 cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
460 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
465 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
466 const MCSubtargetInfo &STI) {
467 this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
468 MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
470 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
471 fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
474 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
475 const MCSubtargetInfo &STI) {
476 MCAssembler &Assembler = getAssembler();
477 SmallVector<MCFixup, 4> Fixups;
478 SmallString<256> Code;
479 raw_svector_ostream VecOS(Code);
480 Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
482 for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
483 fixSymbolsInTLSFixups(Fixups[i].getValue());
485 // There are several possibilities here:
487 // If bundling is disabled, append the encoded instruction to the current data
488 // fragment (or create a new such fragment if the current fragment is not a
491 // If bundling is enabled:
492 // - If we're not in a bundle-locked group, emit the instruction into a
493 // fragment of its own. If there are no fixups registered for the
494 // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
496 // - If we're in a bundle-locked group, append the instruction to the current
497 // data fragment because we want all the instructions in a group to get into
498 // the same fragment. Be careful not to do that for the first instruction in
499 // the group, though.
502 if (Assembler.isBundlingEnabled()) {
503 MCSection &Sec = *getCurrentSectionOnly();
504 if (Assembler.getRelaxAll() && isBundleLocked())
505 // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
506 // the current bundle group.
507 DF = BundleGroups.back();
508 else if (Assembler.getRelaxAll() && !isBundleLocked())
509 // When not in a bundle-locked group and the -mc-relax-all flag is used,
510 // we create a new temporary fragment which will be later merged into
511 // the current fragment.
512 DF = new MCDataFragment();
513 else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
514 // If we are bundle-locked, we re-use the current fragment.
515 // The bundle-locking directive ensures this is a new data fragment.
516 DF = cast<MCDataFragment>(getCurrentFragment());
517 else if (!isBundleLocked() && Fixups.size() == 0) {
518 // Optimize memory usage by emitting the instruction to a
519 // MCCompactEncodedInstFragment when not in a bundle-locked group and
520 // there are no fixups registered.
521 MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
523 CEIF->getContents().append(Code.begin(), Code.end());
526 DF = new MCDataFragment();
529 if (Sec.getBundleLockState() == MCSection::BundleLockedAlignToEnd) {
530 // If this fragment is for a group marked "align_to_end", set a flag
531 // in the fragment. This can happen after the fragment has already been
532 // created if there are nested bundle_align groups and an inner one
533 // is the one marked align_to_end.
534 DF->setAlignToBundleEnd(true);
537 // We're now emitting an instruction in a bundle group, so this flag has
539 Sec.setBundleGroupBeforeFirstInst(false);
541 DF = getOrCreateDataFragment();
544 // Add the fixups and data.
545 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
546 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
547 DF->getFixups().push_back(Fixups[i]);
549 DF->setHasInstructions(true);
550 DF->getContents().append(Code.begin(), Code.end());
552 if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
553 if (!isBundleLocked()) {
554 mergeFragment(getOrCreateDataFragment(), DF);
560 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
561 assert(AlignPow2 <= 30 && "Invalid bundle alignment");
562 MCAssembler &Assembler = getAssembler();
563 if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
564 Assembler.getBundleAlignSize() == 1U << AlignPow2))
565 Assembler.setBundleAlignSize(1U << AlignPow2);
567 report_fatal_error(".bundle_align_mode cannot be changed once set");
570 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
571 MCSection &Sec = *getCurrentSectionOnly();
575 if (!getAssembler().isBundlingEnabled())
576 report_fatal_error(".bundle_lock forbidden when bundling is disabled");
578 if (!isBundleLocked())
579 Sec.setBundleGroupBeforeFirstInst(true);
581 if (getAssembler().getRelaxAll() && !isBundleLocked()) {
582 // TODO: drop the lock state and set directly in the fragment
583 MCDataFragment *DF = new MCDataFragment();
584 BundleGroups.push_back(DF);
587 Sec.setBundleLockState(AlignToEnd ? MCSection::BundleLockedAlignToEnd
588 : MCSection::BundleLocked);
591 void MCELFStreamer::EmitBundleUnlock() {
592 MCSection &Sec = *getCurrentSectionOnly();
595 if (!getAssembler().isBundlingEnabled())
596 report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
597 else if (!isBundleLocked())
598 report_fatal_error(".bundle_unlock without matching lock");
599 else if (Sec.isBundleGroupBeforeFirstInst())
600 report_fatal_error("Empty bundle-locked group is forbidden");
602 // When the -mc-relax-all flag is used, we emit instructions to fragments
603 // stored on a stack. When the bundle unlock is emitted, we pop a fragment
604 // from the stack a merge it to the one below.
605 if (getAssembler().getRelaxAll()) {
606 assert(!BundleGroups.empty() && "There are no bundle groups");
607 MCDataFragment *DF = BundleGroups.back();
609 // FIXME: Use BundleGroups to track the lock state instead.
610 Sec.setBundleLockState(MCSection::NotBundleLocked);
612 // FIXME: Use more separate fragments for nested groups.
613 if (!isBundleLocked()) {
614 mergeFragment(getOrCreateDataFragment(), DF);
615 BundleGroups.pop_back();
619 if (Sec.getBundleLockState() != MCSection::BundleLockedAlignToEnd)
620 getOrCreateDataFragment()->setAlignToBundleEnd(false);
622 Sec.setBundleLockState(MCSection::NotBundleLocked);
625 void MCELFStreamer::FinishImpl() {
626 // Ensure the last section gets aligned if necessary.
627 MCSection *CurSection = getCurrentSectionOnly();
628 setSectionAlignmentForBundling(getAssembler(), CurSection);
632 this->MCObjectStreamer::FinishImpl();
635 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
636 llvm_unreachable("Generic ELF doesn't support this directive");
639 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
640 llvm_unreachable("ELF doesn't support this directive");
643 void MCELFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
644 uint64_t Size, unsigned ByteAlignment) {
645 llvm_unreachable("ELF doesn't support this directive");
648 void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
649 uint64_t Size, unsigned ByteAlignment) {
650 llvm_unreachable("ELF doesn't support this directive");
653 MCStreamer *llvm::createELFStreamer(MCContext &Context,
654 std::unique_ptr<MCAsmBackend> &&MAB,
655 raw_pwrite_stream &OS,
656 std::unique_ptr<MCCodeEmitter> &&CE,
659 new MCELFStreamer(Context, std::move(MAB), OS, std::move(CE));
661 S->getAssembler().setRelaxAll(true);