@@ -1528,8 +1528,10 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1528
1528
for (auto Tup : YkCallMarkerSyms[&MBB]) {
1529
1529
// Emit address of the call instruction.
1530
1530
OutStreamer->emitSymbolValue (std::get<0 >(Tup), getPointerSize ());
1531
+ // Emit the return address of the call.
1532
+ OutStreamer->emitSymbolValue (std::get<1 >(Tup), getPointerSize ());
1531
1533
// Emit address of target if known, or 0.
1532
- MCSymbol *Target = std::get<1 >(Tup);
1534
+ MCSymbol *Target = std::get<2 >(Tup);
1533
1535
if (Target)
1534
1536
OutStreamer->emitSymbolValue (Target, getPointerSize ());
1535
1537
else
@@ -1988,15 +1990,33 @@ void AsmPrinter::emitFunctionBody() {
1988
1990
(MI.getOpcode () != TargetOpcode::STACKMAP) &&
1989
1991
(MI.getOpcode () != TargetOpcode::PATCHPOINT) &&
1990
1992
(MI.getOpcode () != TargetOpcode::STATEPOINT)) {
1993
+ // Record the address of the call instruction itself.
1991
1994
MCSymbol *YkPreCallSym =
1992
1995
MF->getContext ().createTempSymbol (" yk_precall" , true );
1993
1996
OutStreamer->emitLabel (YkPreCallSym);
1997
+
1998
+ // Codegen it as usual.
1999
+ emitInstruction (&MI);
2000
+
2001
+ // Record the address of the instruction following the call. In other
2002
+ // words, this is the return address of the call.
2003
+ MCSymbol *YkPostCallSym =
2004
+ MF->getContext ().createTempSymbol (" yk_postcall" , true );
2005
+ OutStreamer->emitLabel (YkPostCallSym);
2006
+
2007
+ // Figure out if this is a direct or indirect call.
2008
+ //
2009
+ // If it's direct, then we know the call's target from the first
2010
+ // operand alone.
1994
2011
const MachineOperand CallOpnd = MI.getOperand (0 );
1995
2012
MCSymbol *CallTargetSym = nullptr ;
1996
2013
if (CallOpnd.isGlobal ()) {
1997
- // Statically known function address .
2014
+ // Direct call .
1998
2015
CallTargetSym = getSymbol (CallOpnd.getGlobal ());
1999
- }
2016
+ } else if (CallOpnd.isMCSymbol ()) {
2017
+ // Also a direct call.
2018
+ CallTargetSym = CallOpnd.getMCSymbol ();
2019
+ } // Otherwise it's an indirect call.
2000
2020
2001
2021
// Ensure we are only working with near calls. This matters because
2002
2022
// Intel PT optimises near calls, and it simplifies our implementation
@@ -2005,10 +2025,11 @@ void AsmPrinter::emitFunctionBody() {
2005
2025
assert (!MF->getSubtarget ().getInstrInfo ()->isFarCall (MI));
2006
2026
2007
2027
assert (YkCallMarkerSyms.find (&MBB) != YkCallMarkerSyms.end ());
2008
- YkCallMarkerSyms[&MBB].push_back ({YkPreCallSym, CallTargetSym});
2028
+ YkCallMarkerSyms[&MBB].push_back ({YkPreCallSym, YkPostCallSym, CallTargetSym});
2029
+ } else {
2030
+ emitInstruction (&MI);
2009
2031
}
2010
2032
2011
- emitInstruction (&MI);
2012
2033
// Generate labels for function calls so we can record the correct
2013
2034
// instruction offset. The conditions for generating the label must be
2014
2035
// the same as the ones for generating the stackmap call in
0 commit comments