[compiler-rt] [compiler-rt] Fix interceptors with BTI and PAC (PR #84061)

Marco Elver via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 11:53:24 PST 2024


https://github.com/melver created https://github.com/llvm/llvm-project/pull/84061

On AArch64 with BTI and/or PAC, we have to prefix the function body with the appropriate hints/checks. PACIASP is an implicit branch target identification instructions which is equivalent to BTI c.

>From b45b55f260fa4522ec9f2a43d6adbf1fcd8973cc Mon Sep 17 00:00:00 2001
From: Marco Elver <elver at google.com>
Date: Tue, 5 Mar 2024 20:45:25 +0100
Subject: [PATCH] [compiler-rt] Fix interceptors with BTI and PAC

On AArch64 with BTI and/or PAC, we have to prefix the function body with
the appropriate hints/checks. PACIASP is an implicit branch target
identification instructions which is equivalent to BTI c.
---
 compiler-rt/lib/interception/interception.h      | 1 +
 compiler-rt/lib/sanitizer_common/sanitizer_asm.h | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 00bcd979638b53..5a8fb24a9ccb2c 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -205,6 +205,7 @@ const interpose_substitution substitution_##func_name[]             \
          ASM_TYPE_FUNCTION_STR "\n"                                            \
        SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n"                             \
        SANITIZER_STRINGIFY(CFI_STARTPROC) "\n"                                 \
+       SANITIZER_STRINGIFY(ASM_PAC_STARTPROC) "\n"                             \
        C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)),                  \
                        "__interceptor_"                                        \
                          SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n"  \
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
index 3af66a4e449988..bd4421b1991c2b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
@@ -42,6 +42,12 @@
 # define CFI_RESTORE(reg)
 #endif
 
+#if defined(__aarch64__)
+# define ASM_PAC_STARTPROC paciasp
+#else
+# define ASM_PAC_STARTPROC
+#endif
+
 #if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
 # define ASM_TAIL_CALL jmp
 #elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
@@ -115,6 +121,7 @@
          ASM_TYPE_FUNCTION(__interceptor_trampoline_##name);                   \
          __interceptor_trampoline_##name:                                      \
                  CFI_STARTPROC;                                                \
+                 ASM_PAC_STARTPROC;                                            \
                  ASM_TAIL_CALL ASM_PREEMPTIBLE_SYM(__interceptor_##name);      \
                  CFI_ENDPROC;                                                  \
          ASM_SIZE(__interceptor_trampoline_##name)



More information about the llvm-commits mailing list