Skip to content

Commit 4bc3292

Browse files
committed
[libc++][libc++abi] Minor follow-up changes after ptrauth upstreaming
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.
1 parent 98244c4 commit 4bc3292

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

libcxx/include/typeinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct __type_info_implementations {
275275
__impl;
276276
};
277277

278-
# if defined(__arm64__) && __has_cpp_attribute(clang::ptrauth_vtable_pointer)
278+
# if __has_cpp_attribute(clang::ptrauth_vtable_pointer)
279279
# if __has_feature(ptrauth_type_info_discriminated_vtable_pointer)
280280
# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
281281
[[clang::ptrauth_vtable_pointer(process_independent, address_discrimination, type_discrimination)]]

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

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

88-
#if defined(__arm64e__) && __has_feature(ptrauth_calls)
88+
# if __has_feature(ptrauth_calls)
8989
// We must pass a void* to ptrauth_strip since it only accepts a pointer type. Also, in particular,
9090
// we must NOT pass a function pointer, otherwise we will strip the function pointer, and then attempt
9191
// to authenticate and re-sign it when casting it to a uintptr_t again, which will fail because we just
9292
// stripped the function pointer. See rdar://122927845.
9393
__ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
94-
#endif
94+
# endif
9595

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

libcxxabi/src/private_typeinfo.cpp

Lines changed: 8 additions & 15 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,8 +114,7 @@ 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);
117+
void **vtable = strip_vtable(*static_cast<void ** const *>(static_ptr));
122118
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
123119
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
124120
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
@@ -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,8 +1512,7 @@ __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);
1515+
const char* vtable = strip_vtable(*static_cast<const char*const*>(current_ptr));
15221516
offset_to_base = update_offset_to_base(vtable, offset_to_base);
15231517
}
15241518
__base_type->search_above_dst(info, dst_ptr,
@@ -1538,8 +1532,7 @@ __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);
1535+
const char* vtable = strip_vtable(*static_cast<const char*const*>(current_ptr));
15431536
offset_to_base = update_offset_to_base(vtable, offset_to_base);
15441537
}
15451538
__base_type->search_below_dst(info,

0 commit comments

Comments
 (0)