@@ -106,18 +106,12 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
106106 MCDwarfFrameEmitter::Emit (*this , MAB, false );
107107}
108108
109- static bool canReuseDataFragment (const MCFragment &F) {
110- if (!F.hasInstructions ())
111- return true ;
112- // Do not add data after a linker-relaxable instruction. The difference
113- // between a new label and a label at or before the linker-relaxable
114- // instruction cannot be resolved at assemble-time.
115- return !F.isLinkerRelaxable ();
116- }
117-
118109MCFragment *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
119113 auto *F = getCurrentFragment ();
120- if (F->getKind () != MCFragment::FT_Data || ! canReuseDataFragment (*F) ) {
114+ if (F->getKind () != MCFragment::FT_Data) {
121115 F = getContext ().allocFragment <MCFragment>();
122116 insert (F);
123117 }
@@ -355,16 +349,23 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,
355349 F->doneAppending ();
356350 if (!Fixups.empty ())
357351 F->appendFixups (Fixups);
352+ F->setHasInstructions (STI);
358353
354+ bool MarkedLinkerRelaxable = false ;
359355 for (auto &Fixup : MutableArrayRef (F->getFixups ()).slice (FixupStartIndex)) {
360356 Fixup.setOffset (Fixup.getOffset () + CodeOffset);
361- if (Fixup.isLinkerRelaxable ()) {
362- F->setLinkerRelaxable ();
357+ if (!Fixup.isLinkerRelaxable ())
358+ continue ;
359+ F->setLinkerRelaxable ();
360+ // Do not add data after a linker-relaxable instruction. The difference
361+ // between a new label and a label at or before the linker-relaxable
362+ // instruction cannot be resolved at assemble-time.
363+ if (!MarkedLinkerRelaxable) {
364+ MarkedLinkerRelaxable = true ;
363365 getCurrentSectionOnly ()->setLinkerRelaxable ();
366+ newFragment ();
364367 }
365368 }
366-
367- F->setHasInstructions (STI);
368369}
369370
370371void MCObjectStreamer::emitInstToFragment (const MCInst &Inst,
@@ -560,8 +561,10 @@ void MCObjectStreamer::emitCodeAlignment(Align Alignment,
560561 // if the alignment is larger than the minimum NOP size.
561562 unsigned Size;
562563 if (getAssembler ().getBackend ().shouldInsertExtraNopBytesForCodeAlign (*F,
563- Size))
564+ Size)) {
564565 getCurrentSectionOnly ()->setLinkerRelaxable ();
566+ newFragment ();
567+ }
565568}
566569
567570void MCObjectStreamer::emitValueToOffset (const MCExpr *Offset,
0 commit comments