]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions
authorJakub Jelinek <jakub@redhat.com>
Thu, 5 Sep 2024 10:20:57 +0000 (12:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 5 Sep 2024 10:22:19 +0000 (12:22 +0200)
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
https://github.com/llvm/llvm-project/pull/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  <jakub@redhat.com>

* sanitizer_common/sanitizer_asm.h: Cherry-pick llvm-project revision
1c792d24e0a228ad49cc004a1c26bbd7cd87f030.
* interception/interception.h: Likewise.

libsanitizer/interception/interception.h
libsanitizer/sanitizer_common/sanitizer_asm.h

index 58e969378a90822ce727dc24af74944f225da189..73135b34bee21c2839e2370e58221d36f397af2f 100644 (file)
@@ -204,11 +204,11 @@ const interpose_substitution substitution_##func_name[]             \
        ".type  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "                    \
          ASM_TYPE_FUNCTION_STR "\n"                                            \
        SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n"                             \
-       SANITIZER_STRINGIFY(CFI_STARTPROC) "\n"                                 \
+       C_ASM_STARTPROC "\n"                                                    \
        C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)),                  \
                        "__interceptor_"                                        \
                          SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n"  \
-       SANITIZER_STRINGIFY(CFI_ENDPROC) "\n"                                   \
+       C_ASM_ENDPROC "\n"                                                      \
        ".size  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "                    \
             ".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n"                    \
      );
index 3af66a4e44998822dc300e308c53f9582cbd4088..30e9d15184e5d55690576306ec8eadde93424d80 100644 (file)
 # define CFI_RESTORE(reg)
 #endif
 
+#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
+# define ASM_STARTPROC CFI_STARTPROC; hint #34
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC) "\nhint #34"
+#else
+# define ASM_STARTPROC CFI_STARTPROC
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC)
+#endif
+#define ASM_ENDPROC CFI_ENDPROC
+#define C_ASM_ENDPROC SANITIZER_STRINGIFY(CFI_ENDPROC)
+
 #if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
 # define ASM_TAIL_CALL jmp
 #elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
          .globl __interceptor_trampoline_##name;                               \
          ASM_TYPE_FUNCTION(__interceptor_trampoline_##name);                   \
          __interceptor_trampoline_##name:                                      \
-                 CFI_STARTPROC;                                                \
+                 ASM_STARTPROC;                                                \
                  ASM_TAIL_CALL ASM_PREEMPTIBLE_SYM(__interceptor_##name);      \
-                 CFI_ENDPROC;                                                  \
+                 ASM_ENDPROC;                                                  \
          ASM_SIZE(__interceptor_trampoline_##name)
 #  define ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT 1
 # endif  // Architecture supports interceptor trampoline