Index: lib/MC/MCELFStreamer.cpp =================================================================== --- lib/MC/MCELFStreamer.cpp +++ lib/MC/MCELFStreamer.cpp @@ -131,6 +131,14 @@ llvm_unreachable("invalid assembler flag!"); } +static void SetSectionAlignmentForBundling( + const MCAssembler &Assembler, MCSectionData *Section) { + if (Assembler.isBundlingEnabled() && Section && + Section->hasInstructions() && + Section->getAlignment() < Assembler.getBundleAlignSize()) + Section->setAlignment(Assembler.getBundleAlignSize()); +} + void MCELFStreamer::ChangeSection(const MCSection *Section, const MCExpr *Subsection) { MCSectionData *CurSection = getCurrentSectionData(); @@ -138,6 +146,7 @@ report_fatal_error("Unterminated .bundle_lock when changing a section"); MCAssembler &Asm = getAssembler(); + SetSectionAlignmentForBundling(Asm, CurSection); auto *SectionELF = static_cast(Section); const MCSymbol *Grp = SectionELF->getGroup(); if (Grp) @@ -639,6 +648,8 @@ } void MCELFStreamer::FinishImpl() { + SetSectionAlignmentForBundling(getAssembler(), getCurrentSectionData()); + EmitFrames(nullptr); Flush();