aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Hunt <oliver@apple.com>2025-09-02 15:59:58 -0700
committerOliver Hunt <oliver@apple.com>2025-09-02 18:20:55 -0700
commita8e66fde5ed0d3fa4cd80f167fff76f693aec7e6 (patch)
tree9b560f3ccde162cca9738d09d0db2ac0542bfb30
parente88ad93aa935f0ae7babc05f328a9b65cb22d4db (diff)
downloadllvm-a8e66fde5ed0d3fa4cd80f167fff76f693aec7e6.zip
llvm-a8e66fde5ed0d3fa4cd80f167fff76f693aec7e6.tar.gz
llvm-a8e66fde5ed0d3fa4cd80f167fff76f693aec7e6.tar.bz2
Update for feature check changesusers/ojhunt/pointer-authenticated-unwinding
-rw-r--r--compiler-rt/lib/builtins/crtbegin.c10
-rw-r--r--compiler-rt/lib/builtins/gcc_personality_v0.c8
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h2
-rw-r--r--compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp4
-rw-r--r--compiler-rt/test/asan/TestCases/zero_page_pc.cpp4
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp2
-rw-r--r--compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp9
-rw-r--r--libcxx/src/include/overridable_function.h6
-rw-r--r--libcxxabi/include/__cxxabi_config.h6
-rw-r--r--libcxxabi/src/cxa_exception.h4
-rw-r--r--libcxxabi/src/cxa_personality.cpp8
-rw-r--r--libcxxabi/src/private_typeinfo.cpp4
-rw-r--r--libunwind/include/libunwind.h13
-rw-r--r--libunwind/src/DwarfInstructions.hpp4
-rw-r--r--libunwind/src/DwarfParser.hpp6
-rw-r--r--libunwind/src/Registers.hpp14
-rw-r--r--libunwind/src/UnwindCursor.hpp12
-rw-r--r--libunwind/src/UnwindLevel1.c6
-rw-r--r--libunwind/src/UnwindRegistersRestore.S4
-rw-r--r--libunwind/src/UnwindRegistersSave.S4
-rw-r--r--libunwind/src/libunwind.cpp5
21 files changed, 65 insertions, 70 deletions
diff --git a/compiler-rt/lib/builtins/crtbegin.c b/compiler-rt/lib/builtins/crtbegin.c
index 8b5f98f..b743ee4 100644
--- a/compiler-rt/lib/builtins/crtbegin.c
+++ b/compiler-rt/lib/builtins/crtbegin.c
@@ -16,6 +16,12 @@
#include <ptrauth.h>
#endif
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
+#define __crtbegin_has_ptrauth 1
+#else
+#define __crtbegin_has_ptrauth 0
+#endif
+
__attribute__((visibility("hidden"))) void *__dso_handle = &__dso_handle;
#ifdef EH_USE_FRAME_REGISTRY
@@ -66,7 +72,7 @@ __attribute__((section(".init_array"), used)) static void *__init =
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
__ptrauth_init_fini_discriminator);
# endif
-# elif __has_feature(ptrauth_calls)
+# elif __crtbegin_has_ptrauth
# ifdef __aarch64__
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
// pointers in .init_array. Use inline assembly to avoid implicit signing of
@@ -148,7 +154,7 @@ __attribute__((section(".fini_array"), used)) static void *__fini =
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
__ptrauth_init_fini_discriminator);
# endif
-# elif __has_feature(ptrauth_calls)
+# elif __crtbegin_has_ptrauth
# ifdef __aarch64__
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
// pointers in .fini_array. Use inline assembly to avoid implicit signing of
diff --git a/compiler-rt/lib/builtins/gcc_personality_v0.c b/compiler-rt/lib/builtins/gcc_personality_v0.c
index 36a50fa..b7e2d5b 100644
--- a/compiler-rt/lib/builtins/gcc_personality_v0.c
+++ b/compiler-rt/lib/builtins/gcc_personality_v0.c
@@ -30,8 +30,11 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
_Unwind_Personality_Fn);
#endif
-#if __has_feature(ptrauth_qualifier)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
#include <ptrauth.h>
+
+#define __gcc_personality_has_ptrauth 1
+
#if __has_feature(ptrauth_restricted_intptr_qualifier)
#define __ptrauth_gcc_personality_intptr(key, addressDiscriminated, \
discriminator) \
@@ -42,6 +45,7 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
__ptrauth(key, addressDiscriminated, discriminator)
#endif
#else
+#define __gcc_personality_has_ptrauth 0
#define __ptrauth_gcc_personality_intptr(...)
#endif
@@ -283,7 +287,7 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
size_t __ptrauth_gcc_personality_lpad landingPad =
funcStart + landingPadOffset;
-#if __has_feature(ptrauth_qualifier)
+#if __gcc_personality_has_ptrauth
uintptr_t stackPointer = _Unwind_GetGR(context, -2);
const uintptr_t existingDiscriminator =
ptrauth_blend_discriminator(&landingPad,
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h b/compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
index 265a992..e480365 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
@@ -9,7 +9,7 @@
#ifndef SANITIZER_PTRAUTH_H
#define SANITIZER_PTRAUTH_H
-#if __has_feature(ptrauth_intrinsics)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
# include <ptrauth.h>
#elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__)
// On the stack the link register is protected with Pointer
diff --git a/compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp b/compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp
index d404af6..0ccdfef 100644
--- a/compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp
+++ b/compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp
@@ -10,7 +10,7 @@
#include <string.h>
#include "sanitizer/asan_interface.h"
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
# include <ptrauth.h>
#endif
@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
// CHECK: =-1=
char *mainptr;
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
mainptr = (char *)ptrauth_strip((void *)&main, ptrauth_key_return_address);
#else
mainptr = (char *)&main;
diff --git a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
index 66396a8..5b2a0d3 100644
--- a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
+++ b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
@@ -9,14 +9,14 @@
# define __has_feature(x) 0
#endif
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
# include <ptrauth.h>
#endif
typedef void void_f();
int main() {
void_f *func = (void_f *)0x4;
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
func = ptrauth_sign_unauthenticated(
func, ptrauth_key_function_pointer, 0);
#endif
diff --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
index 5223af0..1dae589 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
@@ -8,7 +8,7 @@
#include <cstdint>
#include <cstdio>
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
#include <ptrauth.h>
#else
#define ptrauth_strip(__value, __key) (__value)
diff --git a/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp b/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp
index 9c47b69..ccee5ee 100644
--- a/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp
+++ b/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp
@@ -6,8 +6,11 @@
#include <typeinfo>
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
+#define __has_ptrauth 1
#include <ptrauth.h>
+#else
+#define __has_ptrauth 0
#endif
struct S {
@@ -28,7 +31,7 @@ int main(int argc, char **argv) {
S Obj;
void *Ptr = &Obj;
void *VtablePtr = *reinterpret_cast<void**>(Ptr);
-#if __has_feature(ptrauth_calls)
+#if __has_ptrauth
VtablePtr = ptrauth_strip(VtablePtr, 0);
#endif
VtablePrefix* Prefix = reinterpret_cast<VtablePrefix*>(VtablePtr) - 1;
@@ -39,7 +42,7 @@ int main(int argc, char **argv) {
// Hack Vtable ptr for Obj.
void *FakeVtablePtr = static_cast<void*>(&FakePrefix[1]);
-#if __has_feature(ptrauth_calls)
+#if __has_ptrauth
FakeVtablePtr = ptrauth_sign_unauthenticated(
FakeVtablePtr, ptrauth_key_cxx_vtable_pointer, 0);
#endif
diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h
index 0b43f27..1f75f5e6 100644
--- a/libcxx/src/include/overridable_function.h
+++ b/libcxx/src/include/overridable_function.h
@@ -13,7 +13,7 @@
#include <__config>
#include <cstdint>
-#if __has_feature(ptrauth_calls)
+#if __ptrauth_cxxabi_has_ptrauth
# include <ptrauth.h>
#endif
@@ -83,7 +83,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept {
uintptr_t __end = reinterpret_cast<uintptr_t>(&__lcxx_override_end);
uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
-# if __has_feature(ptrauth_calls)
+# if __ptrauth_cxxabi_has_ptrauth
// We must pass a void* to ptrauth_strip since it only accepts a pointer type. Also, in particular,
// we must NOT pass a function pointer, otherwise we will strip the function pointer, and then attempt
// to authenticate and re-sign it when casting it to a uintptr_t again, which will fail because we just
@@ -117,7 +117,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept {
uintptr_t __end = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
-# if __has_feature(ptrauth_calls)
+# if __ptrauth_cxxabi_has_ptrauth
// We must pass a void* to ptrauth_strip since it only accepts a pointer type. See full explanation above.
__ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
# endif
diff --git a/libcxxabi/include/__cxxabi_config.h b/libcxxabi/include/__cxxabi_config.h
index 769f73c..d49c291 100644
--- a/libcxxabi/include/__cxxabi_config.h
+++ b/libcxxabi/include/__cxxabi_config.h
@@ -107,7 +107,9 @@
# include <ptrauth.h>
#endif
-#if __has_extension(ptrauth_qualifier)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
+
+# define __ptrauth_cxxabi_has_ptrauth 1
// ptrauth_string_discriminator("__cxa_exception::actionRecord") == 0xFC91
# define __ptrauth_cxxabi_action_record \
@@ -139,6 +141,8 @@
#else
+# define __ptrauth_cxxabi_has_ptrauth 0
+
# define __ptrauth_cxxabi_action_record
# define __ptrauth_cxxabi_lsd
# define __ptrauth_cxxabi_catch_temp
diff --git a/libcxxabi/src/cxa_exception.h b/libcxxabi/src/cxa_exception.h
index d59ddce..97be422 100644
--- a/libcxxabi/src/cxa_exception.h
+++ b/libcxxabi/src/cxa_exception.h
@@ -47,7 +47,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
// In Wasm, a destructor returns its argument
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
#else
- void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
+ void (_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
exceptionDestructor)(void*);
#endif
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
@@ -89,7 +89,7 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
#endif
std::type_info *exceptionType;
- void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
+ void (_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
exceptionDestructor)(void*);
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
diff --git a/libcxxabi/src/cxa_personality.cpp b/libcxxabi/src/cxa_personality.cpp
index 22a70c6..1d9e554 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -22,11 +22,7 @@
#include "private_typeinfo.h"
#include "unwind.h"
-#if __has_include(<ptrauth.h>)
-# include <ptrauth.h>
-#endif
-
-#if __has_extension(ptrauth_qualifier)
+#if __ptrauth_cxxabi_has_ptrauth
// The actual value of the discriminators listed below is not important.
// The derivation of the constants is only being included for the purpose
// of maintaining a record of how they were originally produced.
@@ -630,7 +626,7 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
reinterpret_cast<uintptr_t>(unwind_exception));
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1),
static_cast<uintptr_t>(results.ttypeIndex));
-#if __has_feature(ptrauth_qualifier)
+#if __ptrauth_cxxabi_has_ptrauth
auto stackPointer = _Unwind_GetGR(context, UNW_REG_SP);
// We manually re-sign the IP as the __ptrauth qualifiers cannot
// express the required relationship with the destination address
diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp
index 01a1d26..f3cf1e5 100644
--- a/libcxxabi/src/private_typeinfo.cpp
+++ b/libcxxabi/src/private_typeinfo.cpp
@@ -53,13 +53,13 @@
#include <atomic>
#endif
-#if __has_feature(ptrauth_calls)
+#if __ptrauth_cxxabi_has_ptrauth
#include <ptrauth.h>
#endif
template <typename T>
static inline T* strip_vtable(T* vtable) {
-#if __has_feature(ptrauth_calls)
+#if __ptrauth_cxxabi_has_ptrauth
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer);
#endif
return vtable;
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 19d53f3..1160a8a 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -43,11 +43,13 @@
#define LIBUNWIND_AVAIL
#endif
-#if __has_extension(ptrauth_qualifier)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
- #if __has_include(<ptrauth.h>)
- #include <ptrauth.h>
- #endif
+ #include <ptrauth.h>
+
+ // Local "has pointer auth" macro to for backwards compatibility
+ // with compilers that do not provide the __PTRAUTH__ macro
+ #define __libunwind_has_ptrauth 1
#if __has_extension(ptrauth_restricted_intptr_qualifier)
#define __unwind_ptrauth_restricted_intptr(...) \
@@ -122,6 +124,9 @@
__ptrauth_unwind_cie_info_personality_disc)
#else
+ // We explicitly define the not enabled case so that checks fail if they
+ // do not include the correct definitions.
+ #define __libunwind_has_ptrauth 0
#define __ptrauth_unwind_upi_handler
#define __ptrauth_unwind_upi_handler_intptr
diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp
index 7039d81..b34d9d7 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -22,10 +22,6 @@
#include "dwarf2.h"
#include "libunwind_ext.h"
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
-
namespace libunwind {
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 04e0164..5e494de 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -23,10 +23,6 @@
#include "config.h"
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
-
namespace libunwind {
/// CFI_Parser does basic parsing of a CFI (Call Frame Information) records.
@@ -402,7 +398,7 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
pint_t personality = addressSpace.getEncodedP(
p, cieContentEnd, cieInfo->personalityEncoding,
/*datarelBase=*/0, &resultAddr);
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
if (personality) {
// The GOT for the personality function was signed address
// authenticated. Manually re-sign with the CIE_Info::personality
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 8c81882..6233d70 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -20,10 +20,6 @@
#include "shadow_stack_unwind.h"
#include "libunwind_ext.h"
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
-
namespace libunwind {
// For emulating 128-bit registers
@@ -1869,7 +1865,7 @@ public:
void setSP(uint64_t value) { _registers.__sp = value; }
uint64_t getIP() const {
uint64_t value = _registers.__pc;
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// Note the value of the PC was signed to its address in the register state
// but everyone else expects it to be sign by the SP, so convert on return.
value = (uint64_t)ptrauth_auth_and_resign((void *)_registers.__pc,
@@ -1881,7 +1877,7 @@ public:
return value;
}
void setIP(uint64_t value) {
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// Note the value which was set should have been signed with the SP.
// We then resign with the slot we are being stored in to so that both SP
// and LR can't be spoofed at the same time.
@@ -1896,7 +1892,7 @@ public:
uint64_t getFP() const { return _registers.__fp; }
void setFP(uint64_t value) { _registers.__fp = value; }
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
void
loadAndAuthenticateLinkRegister(reg_t inplaceAuthedLinkRegister,
link_reg_t *referenceAuthedLinkRegister) {
@@ -1948,7 +1944,7 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
memcpy(_vectorHalfRegisters,
static_cast<const uint8_t *>(registers) + sizeof(GPRs),
sizeof(_vectorHalfRegisters));
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// We have to do some pointer authentication fixups after this copy,
// and as part of that we need to load the source pc without
// authenticating so that we maintain the signature for the resigning
@@ -1968,7 +1964,7 @@ inline Registers_arm64& Registers_arm64::operator=(const Registers_arm64& other)
memcpy(&_registers, &other._registers, sizeof(_registers));
memcpy(_vectorHalfRegisters, &other._vectorHalfRegisters,
sizeof(_vectorHalfRegisters));
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// We perform this step to ensure that we correctly authenticate and re-sign
// the pc after the bitwise copy.
setIP(other.getIP());
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7a978b5..dea7eff 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -111,10 +111,6 @@ extern "C" _Unwind_Reason_Code __libunwind_seh_personality(
#endif
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
-
namespace libunwind {
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
@@ -1055,7 +1051,7 @@ private:
const UnwindInfoSections &sects,
uint32_t fdeSectionOffsetHint = 0);
int stepWithDwarfFDE(bool stage2) {
-#if __has_extension(ptrauth_calls)
+#if __libunwind_has_ptrauth
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
typename R::link_reg_t pc;
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
@@ -1999,7 +1995,7 @@ bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(
personalityIndex * sizeof(uint32_t));
pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;
personality = _addressSpace.getP(personalityPointer);
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// The GOT for the personality function was signed address authenticated.
// Resign it as a regular function pointer.
const auto discriminator =
@@ -2686,7 +2682,7 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
#endif
typename R::link_reg_t pc;
-#if __has_extension(ptrauth_calls)
+#if __libunwind_has_ptrauth
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
#else
pc = rawPC;
@@ -3241,7 +3237,7 @@ void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {
template <typename A, typename R>
bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
unw_word_t *offset) {
-#if __has_extension(ptrauth_calls)
+#if __libunwind_has_ptrauth
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
typename R::link_reg_t pc;
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 1df6543..d924a71 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -31,10 +31,6 @@
#include "shadow_stack_unwind.h"
#include "unwind.h"
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
-
#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
!defined(__wasm__)
@@ -612,7 +608,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
unw_word_t result;
__unw_get_reg(cursor, UNW_REG_IP, &result);
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// If we are in an arm64e frame, then the PC should have been signed with the
// sp
{
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index 3ab9477..cfbe030 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -685,7 +685,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
ldr x16, [x0, #0x0F8] // load sp into scratch
ldr lr, [x0, #0x100] // restore pc into lr
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
// The LR is signed with its address inside the register state. Time
// to resign to be a regular ROP protected signed pointer
add x1, x0, #0x100
@@ -706,7 +706,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
Lnogcs:
#endif
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
retab
#else
ret x30 // jump to pc
diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S
index 74c5301..5ab3ca5 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -768,7 +768,7 @@ LnoR2Fix:
.p2align 2
DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
pacibsp
#endif
@@ -813,7 +813,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
#endif
mov x0, #0 // return UNW_ESUCCESS
-#if __has_feature(ptrauth_calls)
+#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
retab
#else
ret
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index a5c9456..0dce8de 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -14,9 +14,6 @@
#include "config.h"
#include "libunwind_ext.h"
-#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
-#endif
#include <stdlib.h>
#include <sys/types.h>
@@ -131,7 +128,7 @@ _LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
pint_t sp = (pint_t)co->getReg(UNW_REG_SP);
-#if __has_feature(ptrauth_calls)
+#if __libunwind_has_ptrauth
// It is only valid to set the IP within the current function.
// This is important for ptrauth, otherwise the IP cannot be correctly
// signed.