[compiler-rt] a46effb - [compiler-rt][aarch64] Add PAC-RET/BTI support to HWASAN.

Daniel Kiss via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 08:02:51 PDT 2021


Author: Daniel Kiss
Date: 2021-04-12T17:02:45+02:00
New Revision: a46effbd2aec88012c8f94b81da51dfd5b9e141b

URL: https://github.com/llvm/llvm-project/commit/a46effbd2aec88012c8f94b81da51dfd5b9e141b
DIFF: https://github.com/llvm/llvm-project/commit/a46effbd2aec88012c8f94b81da51dfd5b9e141b.diff

LOG: [compiler-rt][aarch64] Add PAC-RET/BTI support to HWASAN.

Support for -mbranch-protection.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D100143

Added: 
    

Modified: 
    compiler-rt/lib/builtins/assembly.h
    compiler-rt/lib/hwasan/hwasan_setjmp.S
    compiler-rt/lib/hwasan/hwasan_tag_mismatch_aarch64.S

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/assembly.h b/compiler-rt/lib/builtins/assembly.h
index 80287f2c8bcfb..9c015059af5a6 100644
--- a/compiler-rt/lib/builtins/assembly.h
+++ b/compiler-rt/lib/builtins/assembly.h
@@ -105,9 +105,11 @@
   .popsection
 
 #if BTI_FLAG != 0
-#define BTI_C bti c
+#define BTI_C hint #34
+#define BTI_J hint #36
 #else
 #define BTI_C
+#define BTI_J
 #endif
 
 #if (BTI_FLAG | PAC_FLAG) != 0

diff  --git a/compiler-rt/lib/hwasan/hwasan_setjmp.S b/compiler-rt/lib/hwasan/hwasan_setjmp.S
index 0c1354331940e..381af63363cc3 100644
--- a/compiler-rt/lib/hwasan/hwasan_setjmp.S
+++ b/compiler-rt/lib/hwasan/hwasan_setjmp.S
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_common/sanitizer_asm.h"
+#include "builtins/assembly.h"
 
 #if HWASAN_WITH_INTERCEPTORS && defined(__aarch64__)
 #include "sanitizer_common/sanitizer_platform.h"
@@ -34,6 +35,7 @@
 ASM_TYPE_FUNCTION(__interceptor_setjmp)
 __interceptor_setjmp:
   CFI_STARTPROC
+  BTI_C
   mov	x1, #0
   b	__interceptor_sigsetjmp
   CFI_ENDPROC
@@ -46,6 +48,7 @@ ASM_SIZE(__interceptor_setjmp)
 ASM_TYPE_FUNCTION(__interceptor_setjmp_bionic)
 __interceptor_setjmp_bionic:
   CFI_STARTPROC
+  BTI_C
   mov	x1, #1
   b	__interceptor_sigsetjmp
   CFI_ENDPROC
@@ -56,6 +59,7 @@ ASM_SIZE(__interceptor_setjmp_bionic)
 ASM_TYPE_FUNCTION(__interceptor_sigsetjmp)
 __interceptor_sigsetjmp:
   CFI_STARTPROC
+  BTI_C
   stp	x19, x20, [x0, #0<<3]
   stp	x21, x22, [x0, #2<<3]
   stp	x23, x24, [x0, #4<<3]
@@ -98,3 +102,5 @@ ALIAS __interceptor_setjmp, _setjmp
 
 // We do not need executable stack.
 NO_EXEC_STACK_DIRECTIVE
+
+GNU_PROPERTY_BTI_PAC

diff  --git a/compiler-rt/lib/hwasan/hwasan_tag_mismatch_aarch64.S b/compiler-rt/lib/hwasan/hwasan_tag_mismatch_aarch64.S
index 08df12736bb4c..bcb0df4201902 100644
--- a/compiler-rt/lib/hwasan/hwasan_tag_mismatch_aarch64.S
+++ b/compiler-rt/lib/hwasan/hwasan_tag_mismatch_aarch64.S
@@ -1,4 +1,5 @@
 #include "sanitizer_common/sanitizer_asm.h"
+#include "builtins/assembly.h"
 
 // The content of this file is AArch64-only:
 #if defined(__aarch64__)
@@ -74,6 +75,8 @@
 .global __hwasan_tag_mismatch
 .type __hwasan_tag_mismatch, %function
 __hwasan_tag_mismatch:
+  BTI_J
+
   // Compute the granule position one past the end of the access.
   mov x16, #1
   and x17, x1, #0xf
@@ -106,6 +109,7 @@ __hwasan_tag_mismatch:
 .type __hwasan_tag_mismatch_v2, %function
 __hwasan_tag_mismatch_v2:
   CFI_STARTPROC
+  BTI_J
 
   // Set the CFA to be the return address for caller of __hwasan_check_*. Note
   // that we do not emit CFI predicates to describe the contents of this stack
@@ -150,3 +154,5 @@ __hwasan_tag_mismatch_v2:
 
 // We do not need executable stack.
 NO_EXEC_STACK_DIRECTIVE
+
+GNU_PROPERTY_BTI_PAC


        


More information about the llvm-commits mailing list