@@ -1498,6 +1498,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1498
1498
}
1499
1499
}
1500
1500
// Emit the number of corresponding BasicBlocks.
1501
+ OutStreamer->AddComment (" num corresponding blocks" );
1501
1502
OutStreamer->emitULEB128IntValue (CorrBBs.size ());
1502
1503
// Emit the corresponding block indices.
1503
1504
for (auto CorrBB : CorrBBs) {
@@ -1513,6 +1514,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1513
1514
}
1514
1515
if (!Found)
1515
1516
OutContext.reportError (SMLoc (), " Couldn't find the block's index" );
1517
+ OutStreamer->AddComment (" corresponding block" );
1516
1518
OutStreamer->emitULEB128IntValue (I);
1517
1519
}
1518
1520
@@ -1524,18 +1526,25 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1524
1526
// compute the distance from the start of the block and use uleb128
1525
1527
// encoding.
1526
1528
const size_t NumCalls = YkCallMarkerSyms[&MBB].size ();
1529
+ OutStreamer->AddComment (" num calls" );
1527
1530
OutStreamer->emitULEB128IntValue (NumCalls);
1528
1531
for (auto Tup : YkCallMarkerSyms[&MBB]) {
1529
1532
// Emit address of the call instruction.
1533
+ OutStreamer->AddComment (" call offset" );
1530
1534
OutStreamer->emitSymbolValue (std::get<0 >(Tup), getPointerSize ());
1531
1535
// Emit the return address of the call.
1536
+ OutStreamer->AddComment (" return offset" );
1532
1537
OutStreamer->emitSymbolValue (std::get<1 >(Tup), getPointerSize ());
1533
1538
// Emit address of target if known, or 0.
1539
+ OutStreamer->AddComment (" target offset" );
1534
1540
MCSymbol *Target = std::get<2 >(Tup);
1535
1541
if (Target)
1536
1542
OutStreamer->emitSymbolValue (Target, getPointerSize ());
1537
1543
else
1538
1544
OutStreamer->emitIntValue (0 , getPointerSize ());
1545
+ // Emit whether it's a direct call.
1546
+ OutStreamer->AddComment (" direct?" );
1547
+ OutStreamer->emitIntValue (std::get<3 >(Tup), 1 );
1539
1548
}
1540
1549
1541
1550
// Emit successor information.
@@ -2009,14 +2018,25 @@ void AsmPrinter::emitFunctionBody() {
2009
2018
// If it's direct, then we know the call's target from the first
2010
2019
// operand alone.
2011
2020
const MachineOperand CallOpnd = MI.getOperand (0 );
2021
+ std::optional<bool > DirectCall;
2012
2022
MCSymbol *CallTargetSym = nullptr ;
2013
2023
if (CallOpnd.isGlobal ()) {
2014
- // Direct call.
2024
+ // Global: direct call, known target.
2025
+ DirectCall = true ;
2015
2026
CallTargetSym = getSymbol (CallOpnd.getGlobal ());
2016
2027
} else if (CallOpnd.isMCSymbol ()) {
2017
- // Also a direct call.
2028
+ // MCSymbol: direct call, known target.
2029
+ DirectCall = true ;
2018
2030
CallTargetSym = CallOpnd.getMCSymbol ();
2019
- } // Otherwise it's an indirect call.
2031
+ } else if (CallOpnd.isSymbol ()) {
2032
+ // Symbol: direct call, unknown target.
2033
+ DirectCall = true ;
2034
+ // CallTargetSym remains null.
2035
+ } else {
2036
+ // Otherwise: indirect call, therefore unknown target.
2037
+ DirectCall = false ;
2038
+ // CallTargetSym remains null.
2039
+ }
2020
2040
2021
2041
// Ensure we are only working with near calls. This matters because
2022
2042
// Intel PT optimises near calls, and it simplifies our implementation
@@ -2025,7 +2045,8 @@ void AsmPrinter::emitFunctionBody() {
2025
2045
assert (!MF->getSubtarget ().getInstrInfo ()->isFarCall (MI));
2026
2046
2027
2047
assert (YkCallMarkerSyms.find (&MBB) != YkCallMarkerSyms.end ());
2028
- YkCallMarkerSyms[&MBB].push_back ({YkPreCallSym, YkPostCallSym, CallTargetSym});
2048
+ YkCallMarkerSyms[&MBB].push_back ({
2049
+ YkPreCallSym, YkPostCallSym, CallTargetSym, DirectCall.value ()});
2029
2050
} else {
2030
2051
emitInstruction (&MI);
2031
2052
}
0 commit comments