@@ -161,9 +161,17 @@ class BinaryEmitter {
161
161
// / \p FirstInstr indicates if \p NewLoc represents the first instruction
162
162
// / in a sequence, such as a function fragment.
163
163
// /
164
+ // / If \p NewLoc location matches \p PrevLoc, no new line number entry will be
165
+ // / created and the function will return \p PrevLoc while \p InstrLabel will
166
+ // / be ignored. Otherwise, the caller should use \p InstrLabel to mark the
167
+ // / corresponding instruction by emitting \p InstrLabel before it.
168
+ // / If \p InstrLabel is set by the caller, its value will be used with \p
169
+ // / \p NewLoc. If it was nullptr on entry, it will be populated with a pointer
170
+ // / to a new temp symbol used with \p NewLoc.
171
+ // /
164
172
// / Return new current location which is either \p NewLoc or \p PrevLoc.
165
173
SMLoc emitLineInfo (const BinaryFunction &BF, SMLoc NewLoc, SMLoc PrevLoc,
166
- bool FirstInstr);
174
+ bool FirstInstr, MCSymbol *&InstrLabel );
167
175
168
176
// / Use \p FunctionEndSymbol to mark the end of the line info sequence.
169
177
// / Note that it does not automatically result in the insertion of the EOS
@@ -483,23 +491,28 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
483
491
// are relaxable, we should be safe.
484
492
}
485
493
486
- if (!EmitCodeOnly && opts::UpdateDebugSections && BF.getDWARFUnit ()) {
487
- LastLocSeen = emitLineInfo (BF, Instr.getLoc (), LastLocSeen, FirstInstr);
488
- FirstInstr = false ;
489
- }
494
+ if (!EmitCodeOnly) {
495
+ // A symbol to be emitted before the instruction to mark its location.
496
+ MCSymbol *InstrLabel = BC.MIB ->getLabel (Instr);
490
497
491
- // Prepare to tag this location with a label if we need to keep track of
492
- // the location of calls/returns for BOLT address translation maps
493
- if (!EmitCodeOnly && BF.requiresAddressTranslation () &&
494
- BC.MIB ->getOffset (Instr)) {
495
- const uint32_t Offset = *BC.MIB ->getOffset (Instr);
496
- MCSymbol *LocSym = BC.Ctx ->createTempSymbol ();
497
- Streamer.emitLabel (LocSym);
498
- BB->getLocSyms ().emplace_back (Offset, LocSym);
499
- }
498
+ if (opts::UpdateDebugSections && BF.getDWARFUnit ()) {
499
+ LastLocSeen = emitLineInfo (BF, Instr.getLoc (), LastLocSeen,
500
+ FirstInstr, InstrLabel);
501
+ FirstInstr = false ;
502
+ }
500
503
501
- if (auto Label = BC.MIB ->getLabel (Instr))
502
- Streamer.emitLabel (*Label);
504
+ // Prepare to tag this location with a label if we need to keep track of
505
+ // the location of calls/returns for BOLT address translation maps
506
+ if (BF.requiresAddressTranslation () && BC.MIB ->getOffset (Instr)) {
507
+ const uint32_t Offset = *BC.MIB ->getOffset (Instr);
508
+ if (!InstrLabel)
509
+ InstrLabel = BC.Ctx ->createTempSymbol ();
510
+ BB->getLocSyms ().emplace_back (Offset, InstrLabel);
511
+ }
512
+
513
+ if (InstrLabel)
514
+ Streamer.emitLabel (InstrLabel);
515
+ }
503
516
504
517
Streamer.emitInstruction (Instr, *BC.STI );
505
518
LastIsPrefix = BC.MIB ->isPrefix (Instr);
@@ -661,7 +674,8 @@ void BinaryEmitter::emitConstantIslands(BinaryFunction &BF, bool EmitColdPart,
661
674
}
662
675
663
676
SMLoc BinaryEmitter::emitLineInfo (const BinaryFunction &BF, SMLoc NewLoc,
664
- SMLoc PrevLoc, bool FirstInstr) {
677
+ SMLoc PrevLoc, bool FirstInstr,
678
+ MCSymbol *&InstrLabel) {
665
679
DWARFUnit *FunctionCU = BF.getDWARFUnit ();
666
680
const DWARFDebugLine::LineTable *FunctionLineTable = BF.getDWARFLineTable ();
667
681
assert (FunctionCU && " cannot emit line info for function without CU" );
@@ -711,12 +725,12 @@ SMLoc BinaryEmitter::emitLineInfo(const BinaryFunction &BF, SMLoc NewLoc,
711
725
const MCDwarfLoc &DwarfLoc = BC.Ctx ->getCurrentDwarfLoc ();
712
726
BC.Ctx ->clearDwarfLocSeen ();
713
727
714
- MCSymbol *LineSym = BC. Ctx -> createTempSymbol ();
715
- Streamer. emitLabel (LineSym );
728
+ if (!InstrLabel)
729
+ InstrLabel = BC. Ctx -> createTempSymbol ( );
716
730
717
731
BC.getDwarfLineTable (FunctionUnitIndex)
718
732
.getMCLineSections ()
719
- .addLineEntry (MCDwarfLineEntry (LineSym , DwarfLoc),
733
+ .addLineEntry (MCDwarfLineEntry (InstrLabel , DwarfLoc),
720
734
Streamer.getCurrentSectionOnly ());
721
735
722
736
return NewLoc;
0 commit comments