Skip to content

Commit 26b7d70

Browse files
committed
Update for feature check changes
1 parent 61ec1ad commit 26b7d70

File tree

21 files changed

+65
-70
lines changed

21 files changed

+65
-70
lines changed

compiler-rt/lib/builtins/crtbegin.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include <ptrauth.h>
1717
#endif
1818

19+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
20+
#define __crtbegin_has_ptrauth 1
21+
#else
22+
#define __crtbegin_has_ptrauth 0
23+
#endif
24+
1925
__attribute__((visibility("hidden"))) void *__dso_handle = &__dso_handle;
2026

2127
#ifdef EH_USE_FRAME_REGISTRY
@@ -66,7 +72,7 @@ __attribute__((section(".init_array"), used)) static void *__init =
6672
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
6773
__ptrauth_init_fini_discriminator);
6874
# endif
69-
# elif __has_feature(ptrauth_calls)
75+
# elif __crtbegin_has_ptrauth
7076
# ifdef __aarch64__
7177
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
7278
// pointers in .init_array. Use inline assembly to avoid implicit signing of
@@ -148,7 +154,7 @@ __attribute__((section(".fini_array"), used)) static void *__fini =
148154
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
149155
__ptrauth_init_fini_discriminator);
150156
# endif
151-
# elif __has_feature(ptrauth_calls)
157+
# elif __crtbegin_has_ptrauth
152158
# ifdef __aarch64__
153159
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
154160
// pointers in .fini_array. Use inline assembly to avoid implicit signing of

compiler-rt/lib/builtins/gcc_personality_v0.c

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

33-
#if __has_feature(ptrauth_qualifier)
33+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
3434
#include <ptrauth.h>
35+
36+
#define __gcc_personality_has_ptrauth 1
37+
3538
#if __has_feature(ptrauth_restricted_intptr_qualifier)
3639
#define __ptrauth_gcc_personality_intptr(key, addressDiscriminated, \
3740
discriminator) \
@@ -42,6 +45,7 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
4245
__ptrauth(key, addressDiscriminated, discriminator)
4346
#endif
4447
#else
48+
#define __gcc_personality_has_ptrauth 0
4549
#define __ptrauth_gcc_personality_intptr(...)
4650
#endif
4751

@@ -283,7 +287,7 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
283287
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
284288
size_t __ptrauth_gcc_personality_lpad landingPad =
285289
funcStart + landingPadOffset;
286-
#if __has_feature(ptrauth_qualifier)
290+
#if __gcc_personality_has_ptrauth
287291
uintptr_t stackPointer = _Unwind_GetGR(context, -2);
288292
const uintptr_t existingDiscriminator =
289293
ptrauth_blend_discriminator(&landingPad,

compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef SANITIZER_PTRAUTH_H
1010
#define SANITIZER_PTRAUTH_H
1111

12-
#if __has_feature(ptrauth_intrinsics)
12+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
1313
# include <ptrauth.h>
1414
#elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__)
1515
// On the stack the link register is protected with Pointer

compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string.h>
1111

1212
#include "sanitizer/asan_interface.h"
13-
#if __has_feature(ptrauth_calls)
13+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
1414
# include <ptrauth.h>
1515
#endif
1616

@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
2727
// CHECK: =-1=
2828

2929
char *mainptr;
30-
#if __has_feature(ptrauth_calls)
30+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
3131
mainptr = (char *)ptrauth_strip((void *)&main, ptrauth_key_return_address);
3232
#else
3333
mainptr = (char *)&main;

compiler-rt/test/asan/TestCases/zero_page_pc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
# define __has_feature(x) 0
1010
#endif
1111

12-
#if __has_feature(ptrauth_calls)
12+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
1313
# include <ptrauth.h>
1414
#endif
1515

1616
typedef void void_f();
1717
int main() {
1818
void_f *func = (void_f *)0x4;
19-
#if __has_feature(ptrauth_calls)
19+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
2020
func = ptrauth_sign_unauthenticated(
2121
func, ptrauth_key_function_pointer, 0);
2222
#endif

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <cstdint>
1010
#include <cstdio>
11-
#if __has_feature(ptrauth_calls)
11+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
1212
#include <ptrauth.h>
1313
#else
1414
#define ptrauth_strip(__value, __key) (__value)

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
#include <typeinfo>
88

9-
#if __has_feature(ptrauth_calls)
9+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
10+
#define __has_ptrauth 1
1011
#include <ptrauth.h>
12+
#else
13+
#define __has_ptrauth 0
1114
#endif
1215

1316
struct S {
@@ -28,7 +31,7 @@ int main(int argc, char **argv) {
2831
S Obj;
2932
void *Ptr = &Obj;
3033
void *VtablePtr = *reinterpret_cast<void**>(Ptr);
31-
#if __has_feature(ptrauth_calls)
34+
#if __has_ptrauth
3235
VtablePtr = ptrauth_strip(VtablePtr, 0);
3336
#endif
3437
VtablePrefix* Prefix = reinterpret_cast<VtablePrefix*>(VtablePtr) - 1;
@@ -39,7 +42,7 @@ int main(int argc, char **argv) {
3942

4043
// Hack Vtable ptr for Obj.
4144
void *FakeVtablePtr = static_cast<void*>(&FakePrefix[1]);
42-
#if __has_feature(ptrauth_calls)
45+
#if __has_ptrauth
4346
FakeVtablePtr = ptrauth_sign_unauthenticated(
4447
FakeVtablePtr, ptrauth_key_cxx_vtable_pointer, 0);
4548
#endif

libcxx/src/include/overridable_function.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <__config>
1414
#include <cstdint>
1515

16-
#if __has_feature(ptrauth_calls)
16+
#if __ptrauth_cxxabi_has_ptrauth
1717
# include <ptrauth.h>
1818
#endif
1919

@@ -83,7 +83,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept {
8383
uintptr_t __end = reinterpret_cast<uintptr_t>(&__lcxx_override_end);
8484
uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
8585

86-
# if __has_feature(ptrauth_calls)
86+
# if __ptrauth_cxxabi_has_ptrauth
8787
// We must pass a void* to ptrauth_strip since it only accepts a pointer type. Also, in particular,
8888
// we must NOT pass a function pointer, otherwise we will strip the function pointer, and then attempt
8989
// 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 {
117117
uintptr_t __end = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
118118
uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
119119

120-
# if __has_feature(ptrauth_calls)
120+
# if __ptrauth_cxxabi_has_ptrauth
121121
// We must pass a void* to ptrauth_strip since it only accepts a pointer type. See full explanation above.
122122
__ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
123123
# endif

libcxxabi/include/__cxxabi_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@
107107
# include <ptrauth.h>
108108
#endif
109109

110-
#if __has_extension(ptrauth_qualifier)
110+
#if __has_feature(ptrauth_calls) || defined(__PTRAUTH__)
111+
112+
# define __ptrauth_cxxabi_has_ptrauth 1
111113

112114
// ptrauth_string_discriminator("__cxa_exception::actionRecord") == 0xFC91
113115
# define __ptrauth_cxxabi_action_record \
@@ -139,6 +141,8 @@
139141

140142
#else
141143

144+
# define __ptrauth_cxxabi_has_ptrauth 0
145+
142146
# define __ptrauth_cxxabi_action_record
143147
# define __ptrauth_cxxabi_lsd
144148
# define __ptrauth_cxxabi_catch_temp

libcxxabi/src/cxa_exception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
4747
// In Wasm, a destructor returns its argument
4848
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
4949
#else
50-
void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
50+
void (_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
5151
exceptionDestructor)(void*);
5252
#endif
5353
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
@@ -89,7 +89,7 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
8989
#endif
9090

9191
std::type_info *exceptionType;
92-
void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
92+
void (_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor
9393
exceptionDestructor)(void*);
9494
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
9595
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;

0 commit comments

Comments
 (0)