xref: /freebsd/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1// The content of this file is AArch64-only:
2#if defined(__aarch64__)
3
4#include "sanitizer_common/sanitizer_asm.h"
5#include "builtins/assembly.h"
6
7#if !defined(__APPLE__)
8.section .text
9#else
10.section __TEXT,__text
11.align 3
12#endif
13
14ASM_HIDDEN(__tsan_setjmp)
15.comm _ZN14__interception11real_setjmpE,8,8
16.globl ASM_SYMBOL_INTERCEPTOR(setjmp)
17ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
18ASM_SYMBOL_INTERCEPTOR(setjmp):
19  CFI_STARTPROC
20  BTI_C
21
22  // Save frame/link register
23  stp     x29, x30, [sp, -32]!
24  CFI_DEF_CFA_OFFSET (32)
25  CFI_OFFSET (29, -32)
26  CFI_OFFSET (30, -24)
27
28  // Adjust the SP for previous frame
29  add     x29, sp, 0
30  CFI_DEF_CFA_REGISTER (29)
31
32  // Save env parameter
33  str     x0, [sp, 16]
34  CFI_OFFSET (0, -16)
35
36  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
37  add     x0, x29, 32
38
39  // call tsan interceptor
40  bl      ASM_SYMBOL(__tsan_setjmp)
41
42  // Restore env parameter
43  ldr     x0, [sp, 16]
44  CFI_RESTORE (0)
45
46  // Restore frame/link register
47  ldp     x29, x30, [sp], 32
48  CFI_RESTORE (29)
49  CFI_RESTORE (30)
50  CFI_DEF_CFA (31, 0)
51
52  // tail jump to libc setjmp
53#if !defined(__APPLE__)
54  adrp    x1, :got:_ZN14__interception11real_setjmpE
55  ldr     x1, [x1, #:got_lo12:_ZN14__interception11real_setjmpE]
56  ldr     x1, [x1]
57#else
58  adrp    x1, _setjmp@GOTPAGE
59  ldr     x1, [x1, _setjmp@GOTPAGEOFF]
60#endif
61  br      x1
62
63  CFI_ENDPROC
64ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp))
65
66.comm _ZN14__interception12real__setjmpE,8,8
67.globl ASM_SYMBOL_INTERCEPTOR(_setjmp)
68ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
69ASM_SYMBOL_INTERCEPTOR(_setjmp):
70  CFI_STARTPROC
71  BTI_C
72
73  // Save frame/link register
74  stp     x29, x30, [sp, -32]!
75  CFI_DEF_CFA_OFFSET (32)
76  CFI_OFFSET (29, -32)
77  CFI_OFFSET (30, -24)
78
79  // Adjust the SP for previous frame
80  add     x29, sp, 0
81  CFI_DEF_CFA_REGISTER (29)
82
83  // Save env parameter
84  str     x0, [sp, 16]
85  CFI_OFFSET (0, -16)
86
87  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
88  add     x0, x29, 32
89
90  // call tsan interceptor
91  bl      ASM_SYMBOL(__tsan_setjmp)
92
93  // Restore env parameter
94  ldr     x0, [sp, 16]
95  CFI_RESTORE (0)
96
97  // Restore frame/link register
98  ldp     x29, x30, [sp], 32
99  CFI_RESTORE (29)
100  CFI_RESTORE (30)
101  CFI_DEF_CFA (31, 0)
102
103  // tail jump to libc setjmp
104#if !defined(__APPLE__)
105  adrp    x1, :got:_ZN14__interception12real__setjmpE
106  ldr     x1, [x1, #:got_lo12:_ZN14__interception12real__setjmpE]
107  ldr     x1, [x1]
108#else
109  adrp    x1, __setjmp@GOTPAGE
110  ldr     x1, [x1, __setjmp@GOTPAGEOFF]
111#endif
112  br      x1
113
114  CFI_ENDPROC
115ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp))
116
117.comm _ZN14__interception14real_sigsetjmpE,8,8
118.globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp)
119ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
120ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
121  CFI_STARTPROC
122  BTI_C
123
124  // Save frame/link register
125  stp     x29, x30, [sp, -32]!
126  CFI_DEF_CFA_OFFSET (32)
127  CFI_OFFSET (29, -32)
128  CFI_OFFSET (30, -24)
129
130  // Adjust the SP for previous frame
131  add     x29, sp, 0
132  CFI_DEF_CFA_REGISTER (29)
133
134  // Save env and savesigs parameter
135  stp     x0, x1, [sp, 16]
136  CFI_OFFSET (0, -16)
137  CFI_OFFSET (1, -8)
138
139  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
140  add     x0, x29, 32
141
142  // call tsan interceptor
143  bl      ASM_SYMBOL(__tsan_setjmp)
144
145  // Restore env and savesigs parameter
146  ldp     x0, x1, [sp, 16]
147  CFI_RESTORE (0)
148  CFI_RESTORE (1)
149
150  // Restore frame/link register
151  ldp     x29, x30, [sp], 32
152  CFI_RESTORE (29)
153  CFI_RESTORE (30)
154  CFI_DEF_CFA (31, 0)
155
156  // tail jump to libc sigsetjmp
157#if !defined(__APPLE__)
158  adrp    x2, :got:_ZN14__interception14real_sigsetjmpE
159  ldr     x2, [x2, #:got_lo12:_ZN14__interception14real_sigsetjmpE]
160  ldr     x2, [x2]
161#else
162  adrp    x2, _sigsetjmp@GOTPAGE
163  ldr     x2, [x2, _sigsetjmp@GOTPAGEOFF]
164#endif
165  br      x2
166  CFI_ENDPROC
167ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
168
169#if !defined(__APPLE__)
170.comm _ZN14__interception16real___sigsetjmpE,8,8
171.globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)
172ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
173ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
174  CFI_STARTPROC
175  BTI_C
176
177  // Save frame/link register
178  stp     x29, x30, [sp, -32]!
179  CFI_DEF_CFA_OFFSET (32)
180  CFI_OFFSET (29, -32)
181  CFI_OFFSET (30, -24)
182
183  // Adjust the SP for previous frame
184  add     x29, sp, 0
185  CFI_DEF_CFA_REGISTER (29)
186
187  // Save env and savesigs parameter
188  stp     x0, x1, [sp, 16]
189  CFI_OFFSET (0, -16)
190  CFI_OFFSET (1, -8)
191
192  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
193  add     x0, x29, 32
194
195  // call tsan interceptor
196  bl      ASM_SYMBOL(__tsan_setjmp)
197
198  // Restore env and savesigs parameter
199  ldp     x0, x1, [sp, 16]
200  CFI_RESTORE (0)
201  CFI_RESTORE (1)
202
203  // Restore frame/link register
204  ldp     x29, x30, [sp], 32
205  CFI_RESTORE (29)
206  CFI_RESTORE (30)
207  CFI_DEF_CFA (31, 0)
208
209  // tail jump to libc __sigsetjmp
210#if !defined(__APPLE__)
211  adrp    x2, :got:_ZN14__interception16real___sigsetjmpE
212  ldr     x2, [x2, #:got_lo12:_ZN14__interception16real___sigsetjmpE]
213  ldr     x2, [x2]
214#else
215  adrp    x2, ASM_SYMBOL(__sigsetjmp)@page
216  add     x2, x2, ASM_SYMBOL(__sigsetjmp)@pageoff
217#endif
218  br      x2
219  CFI_ENDPROC
220ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
221#endif
222
223NO_EXEC_STACK_DIRECTIVE
224
225GNU_PROPERTY_BTI_PAC
226
227#endif
228