@@ -1498,6 +1498,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
14981498 }
14991499 }
15001500 // Emit the number of corresponding BasicBlocks.
1501+ OutStreamer->AddComment (" num corresponding blocks" );
15011502 OutStreamer->emitULEB128IntValue (CorrBBs.size ());
15021503 // Emit the corresponding block indices.
15031504 for (auto CorrBB : CorrBBs) {
@@ -1513,6 +1514,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
15131514 }
15141515 if (!Found)
15151516 OutContext.reportError (SMLoc (), " Couldn't find the block's index" );
1517+ OutStreamer->AddComment (" corresponding block" );
15161518 OutStreamer->emitULEB128IntValue (I);
15171519 }
15181520
@@ -1524,18 +1526,25 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
15241526 // compute the distance from the start of the block and use uleb128
15251527 // encoding.
15261528 const size_t NumCalls = YkCallMarkerSyms[&MBB].size ();
1529+ OutStreamer->AddComment (" num calls" );
15271530 OutStreamer->emitULEB128IntValue (NumCalls);
15281531 for (auto Tup : YkCallMarkerSyms[&MBB]) {
15291532 // Emit address of the call instruction.
1533+ OutStreamer->AddComment (" call offset" );
15301534 OutStreamer->emitSymbolValue (std::get<0 >(Tup), getPointerSize ());
15311535 // Emit the return address of the call.
1536+ OutStreamer->AddComment (" return offset" );
15321537 OutStreamer->emitSymbolValue (std::get<1 >(Tup), getPointerSize ());
15331538 // Emit address of target if known, or 0.
1539+ OutStreamer->AddComment (" target offset" );
15341540 MCSymbol *Target = std::get<2 >(Tup);
15351541 if (Target)
15361542 OutStreamer->emitSymbolValue (Target, getPointerSize ());
15371543 else
15381544 OutStreamer->emitIntValue (0 , getPointerSize ());
1545+ // Emit whether it's a direct call.
1546+ OutStreamer->AddComment (" direct?" );
1547+ OutStreamer->emitIntValue (std::get<3 >(Tup), 1 );
15391548 }
15401549
15411550 // Emit successor information.
@@ -2009,14 +2018,25 @@ void AsmPrinter::emitFunctionBody() {
20092018 // If it's direct, then we know the call's target from the first
20102019 // operand alone.
20112020 const MachineOperand CallOpnd = MI.getOperand (0 );
2021+ std::optional<bool > DirectCall;
20122022 MCSymbol *CallTargetSym = nullptr ;
20132023 if (CallOpnd.isGlobal ()) {
2014- // Direct call.
2024+ // Global: direct call, known target.
2025+ DirectCall = true ;
20152026 CallTargetSym = getSymbol (CallOpnd.getGlobal ());
20162027 } else if (CallOpnd.isMCSymbol ()) {
2017- // Also a direct call.
2028+ // MCSymbol: direct call, known target.
2029+ DirectCall = true ;
20182030 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+ }
20202040
20212041 // Ensure we are only working with near calls. This matters because
20222042 // Intel PT optimises near calls, and it simplifies our implementation
@@ -2025,7 +2045,8 @@ void AsmPrinter::emitFunctionBody() {
20252045 assert (!MF->getSubtarget ().getInstrInfo ()->isFarCall (MI));
20262046
20272047 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 ()});
20292050 } else {
20302051 emitInstruction (&MI);
20312052 }
0 commit comments