Skip to content

Commit 4b9bef7

Browse files
committed
[xray] Preserve x8 in trampoline on AArch64
Summary: Fixes an ABI violation in the trampoline code for AArch64 that causes the indirect result register to get overwritten if the XRay handler function is complex enough to use it. Reviewers: MaskRay, dberris, johnislarry Subscribers: kristof.beyls, danielkiss, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D78596
1 parent c8433a5 commit 4b9bef7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

compiler-rt/lib/xray/xray_trampoline_AArch64.S

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ __xray_FunctionEntry:
2727
STP Q2, Q3, [SP, #-32]!
2828
STP Q4, Q5, [SP, #-32]!
2929
STP Q6, Q7, [SP, #-32]!
30+
/* X8 is the indirect result register and needs to be preserved for the body
31+
of the function to use */
32+
STP X8, X0, [SP, #-16]!
33+
3034
/* Load the page address of _ZN6__xray19XRayPatchedFunctionE into X1 */
3135
ADRP X1, _ZN6__xray19XRayPatchedFunctionE
3236
/* Load the handler function pointer into X2 */
@@ -41,6 +45,7 @@ __xray_FunctionEntry:
4145
BLR X2
4246
FunctionEntry_restore:
4347
/* Pop the saved registers */
48+
LDP X8, X0, [SP], #16
4449
LDP Q6, Q7, [SP], #32
4550
LDP Q4, Q5, [SP], #32
4651
LDP Q2, Q3, [SP], #32
@@ -71,7 +76,14 @@ __xray_FunctionExit:
7176
STP X3, X4, [SP, #-16]!
7277
STP X5, X6, [SP, #-16]!
7378
STP X7, X30, [SP, #-16]!
74-
STR Q0, [SP, #-16]!
79+
STP Q0, Q1, [SP, #-32]!
80+
STP Q2, Q3, [SP, #-32]!
81+
STP Q4, Q5, [SP, #-32]!
82+
STP Q6, Q7, [SP, #-32]!
83+
/* X8 is the indirect result register and needs to be preserved for the body
84+
of the function to use */
85+
STP X8, X0, [SP, #-16]!
86+
7587
/* Load the page address of _ZN6__xray19XRayPatchedFunctionE into X1 */
7688
ADRP X1, _ZN6__xray19XRayPatchedFunctionE
7789
/* Load the handler function pointer into X2 */
@@ -85,7 +97,11 @@ __xray_FunctionExit:
8597
/* Call the handler with 2 parameters in W0 and X1 */
8698
BLR X2
8799
FunctionExit_restore:
88-
LDR Q0, [SP], #16
100+
LDP X8, X0, [SP], #16
101+
LDP Q6, Q7, [SP], #32
102+
LDP Q4, Q5, [SP], #32
103+
LDP Q2, Q3, [SP], #32
104+
LDP Q0, Q1, [SP], #32
89105
LDP X7, X30, [SP], #16
90106
LDP X5, X6, [SP], #16
91107
LDP X3, X4, [SP], #16

0 commit comments

Comments
 (0)