Skip to content

Commit f53633b

Browse files
ldionnetru
authored andcommitted
[libc++][libc++abi] Minor follow-up changes after ptrauth upstreaming (#87481)
This patch applies the comments provided on #84573. This is done as a separate PR to avoid merge conflicts with downstreams that already had ptrauth support. (cherry picked from commit e64e745)
1 parent 0034169 commit f53633b

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

libcxx/include/typeinfo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,14 @@ struct __type_info_implementations {
275275
__impl;
276276
};
277277

278-
# if defined(__arm64__) && __has_cpp_attribute(clang::ptrauth_vtable_pointer)
279-
# if __has_feature(ptrauth_type_info_discriminated_vtable_pointer)
278+
# if __has_cpp_attribute(_Clang::__ptrauth_vtable_pointer__)
279+
# if __has_feature(ptrauth_type_info_vtable_pointer_discrimination)
280280
# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
281-
[[clang::ptrauth_vtable_pointer(process_independent, address_discrimination, type_discrimination)]]
281+
[[_Clang::__ptrauth_vtable_pointer__(process_independent, address_discrimination, type_discrimination)]]
282282
# else
283283
# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
284-
[[clang::ptrauth_vtable_pointer(process_independent, no_address_discrimination, no_extra_discrimination)]]
284+
[[_Clang::__ptrauth_vtable_pointer__( \
285+
process_independent, no_address_discrimination, no_extra_discrimination)]]
285286
# endif
286287
# else
287288
# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH

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 defined(__arm64e__) && __has_feature(ptrauth_calls)
16+
#if __has_feature(ptrauth_calls)
1717
# include <ptrauth.h>
1818
#endif
1919

@@ -83,13 +83,13 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
8383
uintptr_t __end = reinterpret_cast<uintptr_t>(&__lcxx_override_end);
8484
uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
8585

86-
#if defined(__arm64e__) && __has_feature(ptrauth_calls)
86+
# if __has_feature(ptrauth_calls)
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
9090
// stripped the function pointer. See rdar://122927845.
9191
__ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
92-
#endif
92+
# endif
9393

9494
// Finally, the function was overridden if it falls outside of the section's bounds.
9595
return __ptr < __start || __ptr > __end;

libcxxabi/src/private_typeinfo.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,12 @@
5555
#include <ptrauth.h>
5656
#endif
5757

58-
59-
template<typename T>
60-
static inline
61-
T *
62-
get_vtable(T *vtable) {
58+
template <typename T>
59+
static inline T* strip_vtable(T* vtable) {
6360
#if __has_feature(ptrauth_calls)
64-
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer);
61+
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer);
6562
#endif
66-
return vtable;
63+
return vtable;
6764
}
6865

6966
static inline
@@ -117,11 +114,10 @@ void dyn_cast_get_derived_info(derived_object_info* info, const void* static_ptr
117114
reinterpret_cast<const uint8_t*>(vtable) + offset_to_ti_proxy;
118115
info->dynamic_type = *(reinterpret_cast<const __class_type_info* const*>(ptr_to_ti_proxy));
119116
#else
120-
void **vtable = *static_cast<void ** const *>(static_ptr);
121-
vtable = get_vtable(vtable);
122-
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
123-
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
124-
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
117+
void** vtable = strip_vtable(*static_cast<void** const*>(static_ptr));
118+
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
119+
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
120+
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
125121
#endif
126122
}
127123

@@ -576,8 +572,7 @@ __base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
576572
find the layout. */
577573
offset_to_base = __offset_flags >> __offset_shift;
578574
if (is_virtual) {
579-
const char* vtable = *static_cast<const char* const*>(adjustedPtr);
580-
vtable = get_vtable(vtable);
575+
const char* vtable = strip_vtable(*static_cast<const char* const*>(adjustedPtr));
581576
offset_to_base = update_offset_to_base(vtable, offset_to_base);
582577
}
583578
} else if (!is_virtual) {
@@ -1517,9 +1512,8 @@ __base_class_type_info::search_above_dst(__dynamic_cast_info* info,
15171512
ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
15181513
if (__offset_flags & __virtual_mask)
15191514
{
1520-
const char* vtable = *static_cast<const char*const*>(current_ptr);
1521-
vtable = get_vtable(vtable);
1522-
offset_to_base = update_offset_to_base(vtable, offset_to_base);
1515+
const char* vtable = strip_vtable(*static_cast<const char* const*>(current_ptr));
1516+
offset_to_base = update_offset_to_base(vtable, offset_to_base);
15231517
}
15241518
__base_type->search_above_dst(info, dst_ptr,
15251519
static_cast<const char*>(current_ptr) + offset_to_base,
@@ -1538,9 +1532,8 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
15381532
ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
15391533
if (__offset_flags & __virtual_mask)
15401534
{
1541-
const char* vtable = *static_cast<const char*const*>(current_ptr);
1542-
vtable = get_vtable(vtable);
1543-
offset_to_base = update_offset_to_base(vtable, offset_to_base);
1535+
const char* vtable = strip_vtable(*static_cast<const char* const*>(current_ptr));
1536+
offset_to_base = update_offset_to_base(vtable, offset_to_base);
15441537
}
15451538
__base_type->search_below_dst(info,
15461539
static_cast<const char*>(current_ptr) + offset_to_base,

0 commit comments

Comments
 (0)