Skip to content

Commit 2379cbb

Browse files
committed
libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions
When gcc is built with -mbranch-protection=standard, running sanitized programs doesn't work properly on bti enabled kernels. This has been fixed upstream with llvm/llvm-project#84061 The following patch cherry picks that from upstream. For trunk we should eventually do a full merge from upstream, but I'm hoping they will first fix up the _BitInt libubsan support mess. 2024-09-05 Jakub Jelinek <[email protected]> * sanitizer_common/sanitizer_asm.h: Cherry-pick llvm-project revision 1c792d24e0a228ad49cc004a1c26bbd7cd87f030. * interception/interception.h: Likewise.
1 parent a50f54c commit 2379cbb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

libsanitizer/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
);

libsanitizer/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)