@@ -511,12 +511,6 @@ static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI,
511
511
void MCELFStreamer::emitInstToData (const MCInst &Inst,
512
512
const MCSubtargetInfo &STI) {
513
513
MCAssembler &Assembler = getAssembler ();
514
- SmallVector<MCFixup, 4 > Fixups;
515
- SmallString<256 > Code;
516
- Assembler.getEmitter ().encodeInstruction (Inst, Code, Fixups, STI);
517
-
518
- for (auto &Fixup : Fixups)
519
- fixSymbolsInTLSFixups (Fixup.getValue ());
520
514
521
515
// There are several possibilities here:
522
516
//
@@ -535,7 +529,16 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
535
529
// the group, though.
536
530
MCDataFragment *DF;
537
531
532
+ // When bundling is enabled, we can't just append to the data fragment, as it
533
+ // might need to be a MCCompactEncodedInstFragment for zero fixups.
538
534
if (Assembler.isBundlingEnabled ()) {
535
+ SmallVector<MCFixup, 4 > Fixups;
536
+ SmallString<256 > Code;
537
+ Assembler.getEmitter ().encodeInstruction (Inst, Code, Fixups, STI);
538
+
539
+ for (auto &Fixup : Fixups)
540
+ fixSymbolsInTLSFixups (Fixup.getValue ());
541
+
539
542
MCSection &Sec = *getCurrentSectionOnly ();
540
543
if (isBundleLocked () && !Sec.isBundleGroupBeforeFirstInst ()) {
541
544
// If we are bundle-locked, we re-use the current fragment.
@@ -546,6 +549,9 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
546
549
// Optimize memory usage by emitting the instruction to a
547
550
// MCCompactEncodedInstFragment when not in a bundle-locked group and
548
551
// there are no fixups registered.
552
+ //
553
+ // Apparently, this is not just a performance optimization? Using an
554
+ // MCDataFragment at this point causes test failures.
549
555
MCCompactEncodedInstFragment *CEIF =
550
556
getContext ().allocFragment <MCCompactEncodedInstFragment>();
551
557
insert (CEIF);
@@ -567,21 +573,39 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
567
573
// We're now emitting an instruction in a bundle group, so this flag has
568
574
// to be turned off.
569
575
Sec.setBundleGroupBeforeFirstInst (false );
570
- } else {
571
- DF = getOrCreateDataFragment (&STI);
576
+
577
+ for (auto &Fixup : Fixups) {
578
+ Fixup.setOffset (Fixup.getOffset () + DF->getContents ().size ());
579
+ DF->getFixups ().push_back (Fixup);
580
+ }
581
+
582
+ DF->setHasInstructions (STI);
583
+ if (!Fixups.empty () && Fixups.back ().getTargetKind () ==
584
+ getAssembler ().getBackend ().RelaxFixupKind )
585
+ DF->setLinkerRelaxable ();
586
+
587
+ DF->getContents ().append (Code.begin (), Code.end ());
588
+ return ;
572
589
}
573
590
574
- // Add the fixups and data.
591
+ DF = getOrCreateDataFragment (&STI);
592
+
593
+ // Emit instruction directly into data fragment.
594
+ size_t FixupStartIndex = DF->getFixups ().size ();
595
+ size_t CodeOffset = DF->getContents ().size ();
596
+ Assembler.getEmitter ().encodeInstruction (Inst, DF->getContents (),
597
+ DF->getFixups (), STI);
598
+
599
+ auto Fixups = MutableArrayRef (DF->getFixups ()).slice (FixupStartIndex);
575
600
for (auto &Fixup : Fixups) {
576
- Fixup.setOffset (Fixup.getOffset () + DF-> getContents (). size () );
577
- DF-> getFixups (). push_back (Fixup );
601
+ Fixup.setOffset (Fixup.getOffset () + CodeOffset );
602
+ fixSymbolsInTLSFixups (Fixup. getValue () );
578
603
}
579
604
580
605
DF->setHasInstructions (STI);
581
606
if (!Fixups.empty () && Fixups.back ().getTargetKind () ==
582
607
getAssembler ().getBackend ().RelaxFixupKind )
583
608
DF->setLinkerRelaxable ();
584
- DF->getContents ().append (Code.begin (), Code.end ());
585
609
}
586
610
587
611
void MCELFStreamer::emitBundleAlignMode (Align Alignment) {
0 commit comments