Skip to content

Commit 1c792d2

Browse files
authored
[compiler-rt] Fix interceptors with AArch64 BTI (#84061)
On AArch64 with BTI, we have to start functions with the appropriate BTI hint to indicate that the function is a valid call target. To support interceptors with AArch64 BTI, add "BTI c".
1 parent 46682f4 commit 1c792d2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler-rt/lib/interception/interception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ const interpose_substitution substitution_##func_name[] \
204204
".type " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \
205205
ASM_TYPE_FUNCTION_STR "\n" \
206206
SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" \
207-
SANITIZER_STRINGIFY(CFI_STARTPROC) "\n" \
207+
C_ASM_STARTPROC "\n" \
208208
C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)), \
209209
"__interceptor_" \
210210
SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n" \
211-
SANITIZER_STRINGIFY(CFI_ENDPROC) "\n" \
211+
C_ASM_ENDPROC "\n" \
212212
".size " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \
213213
".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \
214214
);

compiler-rt/lib/sanitizer_common/sanitizer_asm.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
# define CFI_RESTORE(reg)
4343
#endif
4444

45+
#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
46+
# define ASM_STARTPROC CFI_STARTPROC; hint #34
47+
# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC) "\nhint #34"
48+
#else
49+
# define ASM_STARTPROC CFI_STARTPROC
50+
# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC)
51+
#endif
52+
#define ASM_ENDPROC CFI_ENDPROC
53+
#define C_ASM_ENDPROC SANITIZER_STRINGIFY(CFI_ENDPROC)
54+
4555
#if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
4656
# define ASM_TAIL_CALL jmp
4757
#elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
@@ -114,9 +124,9 @@
114124
.globl __interceptor_trampoline_##name; \
115125
ASM_TYPE_FUNCTION(__interceptor_trampoline_##name); \
116126
__interceptor_trampoline_##name: \
117-
CFI_STARTPROC; \
127+
ASM_STARTPROC; \
118128
ASM_TAIL_CALL ASM_PREEMPTIBLE_SYM(__interceptor_##name); \
119-
CFI_ENDPROC; \
129+
ASM_ENDPROC; \
120130
ASM_SIZE(__interceptor_trampoline_##name)
121131
# define ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT 1
122132
# endif // Architecture supports interceptor trampoline

0 commit comments

Comments
 (0)