Skip to content

Commit 521d207

Browse files
committed
[PAC][libunwind] Fix gcc build of libunwind and compiler-rt
This adds guards on the ptrauth feature checks so that they are only performed if __has_feature is actually available.
1 parent 1906c3e commit 521d207

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

compiler-rt/lib/builtins/gcc_personality_v0.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
3030
_Unwind_Personality_Fn);
3131
#endif
3232

33+
#ifndef __has_feature
34+
#define __has_feature(__feature) 0
35+
#endif
36+
3337
#if __has_feature(ptrauth_calls)
3438
#include <ptrauth.h>
3539

libunwind/include/__libunwind_config.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@
212212
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 287
213213
#endif // _LIBUNWIND_IS_NATIVE_ONLY
214214

215-
#if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
216-
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
217-
#elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
218-
# error "Either both or none of ptrauth_calls and ptrauth_returns "\
219-
"is allowed to be enabled"
215+
#if defined(__has_feature)
216+
# if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
217+
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
218+
# elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
219+
# error "Either both or none of ptrauth_calls and ptrauth_returns "\
220+
"is allowed to be enabled"
221+
# endif
220222
#endif
221223

222224
#endif // ____LIBUNWIND_CONFIG_H__

libunwind/src/UnwindRegistersRestore.S

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ Lnovec:
634634

635635
#elif defined(__aarch64__)
636636

637+
#ifdef __has_feature
638+
#define __has_ptrauth_calls __has_feature(ptrauth_calls)
639+
#else
640+
#define __has_ptrauth_calls 0
641+
#endif
642+
637643
#if defined(__ARM_FEATURE_GCS_DEFAULT)
638644
.arch_extension gcs
639645
#endif
@@ -690,7 +696,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
690696
ldr x16, [x0, #0x0F8] // load sp into scratch
691697
ldr lr, [x0, #0x100] // restore pc into lr
692698

693-
#if __has_feature(ptrauth_calls)
699+
#if __has_ptrauth_calls
694700
// The LR is signed with its address inside the register state. Time
695701
// to resign to be a regular ROP protected signed pointer
696702
add x1, x0, #0x100
@@ -711,7 +717,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
711717
Lnogcs:
712718
#endif
713719

714-
#if __has_feature(ptrauth_calls)
720+
#if __has_ptrauth_calls
715721
retab
716722
#else
717723
ret x30 // jump to pc

libunwind/src/UnwindRegistersSave.S

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ LnoR2Fix:
763763

764764
#elif defined(__aarch64__)
765765

766+
#ifdef __has_feature
767+
#define __has_ptrauth_calls __has_feature(ptrauth_calls)
768+
#else
769+
#define __has_ptrauth_calls 0
770+
#endif
771+
766772
//
767773
// extern int __unw_getcontext(unw_context_t* thread_state)
768774
//
@@ -772,7 +778,7 @@ LnoR2Fix:
772778
.p2align 2
773779
DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
774780

775-
#if __has_feature(ptrauth_calls)
781+
#if __has_ptrauth_calls
776782
pacibsp
777783
#endif
778784

@@ -817,7 +823,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
817823
#endif
818824
mov x0, #0 // return UNW_ESUCCESS
819825

820-
#if __has_feature(ptrauth_calls)
826+
#if __has_ptrauth_calls
821827
retab
822828
#else
823829
ret

0 commit comments

Comments
 (0)