@@ -340,31 +340,33 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,
340340 MCFragment *F = getCurrentFragment ();
341341
342342 // Append the instruction to the data fragment.
343- size_t FixupStartIndex = F->getFixups ().size ();
344343 size_t CodeOffset = F->getContents ().size ();
345344 SmallVector<MCFixup, 1 > Fixups;
346345 getAssembler ().getEmitter ().encodeInstruction (
347346 Inst, F->getContentsForAppending (), Fixups, STI);
348347 F->doneAppending ();
349- if (!Fixups.empty ())
350- F->appendFixups (Fixups);
351348 F->setHasInstructions (STI);
352349
350+ if (Fixups.empty ())
351+ return ;
353352 bool MarkedLinkerRelaxable = false ;
354- for (auto &Fixup : MutableArrayRef (F-> getFixups ()). slice (FixupStartIndex) ) {
353+ for (auto &Fixup : Fixups ) {
355354 Fixup.setOffset (Fixup.getOffset () + CodeOffset);
356- if (!Fixup.isLinkerRelaxable ())
355+ if (!Fixup.isLinkerRelaxable () || MarkedLinkerRelaxable )
357356 continue ;
358- F->setLinkerRelaxable ();
357+ MarkedLinkerRelaxable = true ;
358+ // Set the fragment's order within the subsection for use by
359+ // MCAssembler::relaxAlign.
360+ auto *Sec = F->getParent ();
361+ if (!Sec->isLinkerRelaxable ())
362+ Sec->setLinkerRelaxable ();
359363 // Do not add data after a linker-relaxable instruction. The difference
360364 // between a new label and a label at or before the linker-relaxable
361365 // instruction cannot be resolved at assemble-time.
362- if (!MarkedLinkerRelaxable) {
363- MarkedLinkerRelaxable = true ;
364- getCurrentSectionOnly ()->setLinkerRelaxable ();
365- newFragment ();
366- }
366+ F->setLinkerRelaxable ();
367+ newFragment ();
367368 }
369+ F->appendFixups (Fixups);
368370}
369371
370372void MCObjectStreamer::emitInstToFragment (const MCInst &Inst,
0 commit comments