Index: compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h +++ compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h @@ -11,6 +11,24 @@ #if __has_feature(ptrauth_calls) #include +#elif defined(__aarch64__) +inline unsigned long ptrauth_strip(unsigned long __value, unsigned int __key) { + // On the stack the link register could be protected with Pointer + // Authentication Code when compiled with -mbranch-protection. + // Let's stripping the PAC unconditionally because xpaclri is in + // the NOP space so will do nothing when it is not enabled or not available. + unsigned long ret; + asm volatile( + "mov x30, %1\n\t" + "hint #7\n\t" // xpaclri + "mov %0, x30\n\t" + : "=r"(ret) + : "r"(__value) + : "x30"); + return ret; +} +#define ptrauth_auth_data(__value, __old_key, __old_data) __value +#define ptrauth_string_discriminator(__string) ((int)0) #else // Copied from #define ptrauth_strip(__value, __key) __value @@ -18,6 +36,6 @@ #define ptrauth_string_discriminator(__string) ((int)0) #endif -#define STRIP_PC(pc) ((uptr)ptrauth_strip(pc, 0)) +#define STRIP_PC(pc) ((uptr)ptrauth_strip((uptr)pc, 0)) #endif // SANITIZER_PTRAUTH_H Index: compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp +++ compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp @@ -15,6 +15,7 @@ #include "sanitizer_common.h" #include "sanitizer_flags.h" #include "sanitizer_platform.h" +#include "sanitizer_ptrauth.h" namespace __sanitizer { @@ -121,6 +122,8 @@ #elif defined(__riscv) // frame[-1] contains the return address uhwptr pc1 = frame[-1]; +#elif defined(__aarch64__) + uhwptr pc1 = ptrauth_strip(frame[1], 0); #else uhwptr pc1 = frame[1]; #endif