From 723a13c41dca89e37f3e02120c9385b33ee73439 Mon Sep 17 00:00:00 2001 From: Tulio Magno Quites Machado Filho Date: Mon, 17 Jun 2024 16:47:04 -0300 Subject: [PATCH] [tsan][aarch64] Fix branch protection in interceptors Start functions with BTI in order to identify the function as a valid branch target. Also add the BTI marker to tsan_rtl_aarch64.S. With this patch, libclang_rt.tsan.so can now be generated with DT_AARCH64_BTI_PLT when built with -mbranch-protection=standard. --- compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S b/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S index c6162659b8766..7d920bee4a2db 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S @@ -2,6 +2,7 @@ #if defined(__aarch64__) #include "sanitizer_common/sanitizer_asm.h" +#include "builtins/assembly.h" #if !defined(__APPLE__) .section .text @@ -16,6 +17,7 @@ ASM_HIDDEN(__tsan_setjmp) ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp)) ASM_SYMBOL_INTERCEPTOR(setjmp): CFI_STARTPROC + BTI_C // Save frame/link register stp x29, x30, [sp, -32]! @@ -66,6 +68,7 @@ ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp)) ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp)) ASM_SYMBOL_INTERCEPTOR(_setjmp): CFI_STARTPROC + BTI_C // Save frame/link register stp x29, x30, [sp, -32]! @@ -116,6 +119,7 @@ ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp)) ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp)) ASM_SYMBOL_INTERCEPTOR(sigsetjmp): CFI_STARTPROC + BTI_C // Save frame/link register stp x29, x30, [sp, -32]! @@ -168,6 +172,7 @@ ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp)) ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)) ASM_SYMBOL_INTERCEPTOR(__sigsetjmp): CFI_STARTPROC + BTI_C // Save frame/link register stp x29, x30, [sp, -32]! @@ -217,4 +222,6 @@ ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)) NO_EXEC_STACK_DIRECTIVE +GNU_PROPERTY_BTI_PAC + #endif