@@ -106,18 +106,6 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
106106 MCDwarfFrameEmitter::Emit (*this , MAB, false );
107107}
108108
109- MCFragment *MCObjectStreamer::getOrCreateDataFragment () {
110- // TODO: Start a new fragment whenever finalizing the variable-size tail of a
111- // previous one, so that all getOrCreateDataFragment calls can be replaced
112- // with getCurrentFragment
113- auto *F = getCurrentFragment ();
114- if (F->getKind () != MCFragment::FT_Data) {
115- F = getContext ().allocFragment <MCFragment>();
116- insert (F);
117- }
118- return F;
119- }
120-
121109void MCObjectStreamer::visitUsedSymbol (const MCSymbol &Sym) {
122110 Assembler->registerSymbol (Sym);
123111}
@@ -379,6 +367,7 @@ void MCObjectStreamer::emitInstToFragment(const MCInst &Inst,
379367 F->setVarContents (Data);
380368 F->setVarFixups (Fixups);
381369 F->setInst (Inst);
370+ newFragment ();
382371}
383372
384373void MCObjectStreamer::emitDwarfLocDirective (unsigned FileNo, unsigned Line,
@@ -444,6 +433,7 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
444433 F->Kind = MCFragment::FT_Dwarf;
445434 F->setDwarfAddrDelta (buildSymbolDiff (*this , Label, LastLabel, SMLoc ()));
446435 F->setDwarfLineDelta (LineDelta);
436+ newFragment ();
447437}
448438
449439void MCObjectStreamer::emitDwarfLineEndEntry (MCSection *Section,
@@ -474,6 +464,7 @@ void MCObjectStreamer::emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
474464 auto *F = getOrCreateDataFragment ();
475465 F->Kind = MCFragment::FT_DwarfFrame;
476466 F->setDwarfAddrDelta (buildSymbolDiff (*this , Label, LastLabel, Loc));
467+ newFragment ();
477468}
478469
479470void MCObjectStreamer::emitCVLocDirective (unsigned FunctionId, unsigned FileNo,
@@ -536,32 +527,38 @@ void MCObjectStreamer::emitBytes(StringRef Data) {
536527 DF->appendContents (ArrayRef (Data.data (), Data.size ()));
537528}
538529
539- void MCObjectStreamer::emitValueToAlignment (Align Alignment, int64_t Fill,
540- uint8_t FillLen,
541- unsigned MaxBytesToEmit) {
530+ MCAlignFragment *MCObjectStreamer::createAlignFragment (
531+ Align Alignment, int64_t Fill, uint8_t FillLen, unsigned MaxBytesToEmit) {
542532 if (MaxBytesToEmit == 0 )
543533 MaxBytesToEmit = Alignment.value ();
544- insert (getContext ().allocFragment <MCAlignFragment>(Alignment, Fill, FillLen,
545- MaxBytesToEmit));
534+ return getContext ().allocFragment <MCAlignFragment>(Alignment, Fill, FillLen,
535+ MaxBytesToEmit);
536+ }
546537
538+ void MCObjectStreamer::emitValueToAlignment (Align Alignment, int64_t Fill,
539+ uint8_t FillLen,
540+ unsigned MaxBytesToEmit) {
541+ auto *F = createAlignFragment (Alignment, Fill, FillLen, MaxBytesToEmit);
542+ insert (F);
547543 // Update the maximum alignment on the current section if necessary.
548- MCSection *CurSec = getCurrentSectionOnly ();
549- CurSec->ensureMinAlignment (Alignment);
544+ F->getParent ()->ensureMinAlignment (Alignment);
550545}
551546
552547void MCObjectStreamer::emitCodeAlignment (Align Alignment,
553548 const MCSubtargetInfo *STI,
554549 unsigned MaxBytesToEmit) {
555- emitValueToAlignment (Alignment, 0 , 1 , MaxBytesToEmit);
556- auto *F = cast<MCAlignFragment>(getCurrentFragment ());
550+ auto *F = createAlignFragment (Alignment, 0 , 1 , MaxBytesToEmit);
557551 F->setEmitNops (true , STI);
552+ insert (F);
553+ // Update the maximum alignment on the current section if necessary.
554+ F->getParent ()->ensureMinAlignment (Alignment);
555+
558556 // With RISC-V style linker relaxation, mark the section as linker-relaxable
559557 // if the alignment is larger than the minimum NOP size.
560558 unsigned Size;
561559 if (getAssembler ().getBackend ().shouldInsertExtraNopBytesForCodeAlign (*F,
562560 Size)) {
563- getCurrentSectionOnly ()->setLinkerRelaxable ();
564- newFragment ();
561+ F->getParent ()->setLinkerRelaxable ();
565562 }
566563}
567564
0 commit comments