Skip to content

Commit fa846a1

Browse files
author
Serge Rogatch
committed
[XRay][AArch64] More staging for tail call support in XRay AArch64 - in compiler-rt
Summary: This patch provides a trampoline for function tail exit tracing. Still, it's staging because code `1` is passed to the handler function (indicating a normal exit) instead of `2`, which would indicate tail exit. This is so until the logging part of XRay supports tail exits too. Related: https://reviews.llvm.org/D28947 (LLVM) Reviewers: dberris, rengolin Reviewed By: rengolin Subscribers: aemerson, llvm-commits, iid_iunknown Differential Revision: https://reviews.llvm.org/D28948 llvm-svn: 293082
1 parent 5d91019 commit fa846a1

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

compiler-rt/lib/xray/xray_AArch64.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ bool patchFunctionExit(const bool Enable, const uint32_t FuncId,
117117

118118
bool patchFunctionTailExit(const bool Enable, const uint32_t FuncId,
119119
const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {
120-
// FIXME: In the future we'd need to distinguish between non-tail exits and
121-
// tail exits for better information preservation.
122-
return patchSled(Enable, FuncId, Sled, __xray_FunctionExit);
120+
return patchSled(Enable, FuncId, Sled, __xray_FunctionTailExit);
123121
}
124122

125123
} // namespace __xray

compiler-rt/lib/xray/xray_trampoline_AArch64.S

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,54 @@ FunctionExit_restore:
8787
LDP X3, X4, [SP], #16
8888
LDP X1, X2, [SP], #16
8989
RET
90+
91+
/* Word-aligned function entry point */
92+
.p2align 2
93+
/* Let C/C++ see the symbol */
94+
.global __xray_FunctionTailExit
95+
.type __xray_FunctionTailExit, %function
96+
/* In C++ it is void extern "C" __xray_FunctionTailExit(uint32_t FuncId)
97+
with FuncId passed in W0 register. */
98+
__xray_FunctionTailExit:
99+
/* Move the return address beyond the end of sled data. The 12 bytes of
100+
data are inserted in the code of the runtime patch, between the call
101+
instruction and the instruction returned into. The data contains 32
102+
bits of instrumented function ID and 64 bits of the address of
103+
the current trampoline. */
104+
ADD X30, X30, #12
105+
/* Push the registers which may be modified by the handler function */
106+
STP X1, X2, [SP, #-16]!
107+
STP X3, X4, [SP, #-16]!
108+
STP X5, X6, [SP, #-16]!
109+
STP X7, X30, [SP, #-16]!
110+
/* Push the parameters of the tail called function */
111+
STP Q0, Q1, [SP, #-32]!
112+
STP Q2, Q3, [SP, #-32]!
113+
STP Q4, Q5, [SP, #-32]!
114+
STP Q6, Q7, [SP, #-32]!
115+
/* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
116+
LDR X1, =_ZN6__xray19XRayPatchedFunctionE
117+
/* Load the handler function pointer into X2 */
118+
LDR X2, [X1]
119+
/* Handler address is nullptr if handler is not set */
120+
CMP X2, #0
121+
BEQ FunctionTailExit_restore
122+
/* Function ID is already in W0 (the first parameter).
123+
X1=2 means that we are tracing a tail exit event, but before the
124+
logging part of XRay is ready, we pretend that here a normal function
125+
exit happens, so we give the handler code 1 */
126+
MOV X1, #1
127+
/* Call the handler with 2 parameters in W0 and X1 */
128+
BLR X2
129+
FunctionTailExit_restore:
130+
/* Pop the parameters of the tail called function */
131+
LDP Q6, Q7, [SP], #32
132+
LDP Q4, Q5, [SP], #32
133+
LDP Q2, Q3, [SP], #32
134+
LDP Q0, Q1, [SP], #32
135+
/* Pop the registers which may be modified by the handler function */
136+
LDP X7, X30, [SP], #16
137+
LDP X5, X6, [SP], #16
138+
LDP X3, X4, [SP], #16
139+
LDP X1, X2, [SP], #16
140+
RET

0 commit comments

Comments
 (0)