Skip to content

Commit 74d0a01

Browse files
committed
arm64e/ptrauth unified patch: libcxx/abi
1 parent fa02950 commit 74d0a01

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

libcxx/include/typeinfo

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,15 @@ struct __type_info_implementations {
299299
__impl;
300300
};
301301

302-
class _LIBCPP_EXPORTED_FROM_ABI type_info
302+
#if defined(__arm64__) && __has_cpp_attribute(clang::ptrauth_vtable_pointer)
303+
#define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
304+
[[clang::ptrauth_vtable_pointer(process_independent, no_address_discrimination, no_extra_discrimination)]]
305+
#else
306+
#define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH
307+
#endif
308+
309+
310+
class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH type_info
303311
{
304312
type_info& operator=(const type_info&);
305313
type_info(const type_info&);

libcxxabi/src/private_typeinfo.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
#include <atomic>
5151
#endif
5252

53+
#if __has_feature(ptrauth_calls)
54+
#include <ptrauth.h>
55+
#endif
56+
57+
58+
template<typename T>
59+
static inline
60+
T *
61+
get_vtable(T *vtable) {
62+
#if __has_feature(ptrauth_calls)
63+
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer);
64+
#endif
65+
return vtable;
66+
}
67+
5368
static inline
5469
bool
5570
is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp)
@@ -102,6 +117,7 @@ void dyn_cast_get_derived_info(derived_object_info* info, const void* static_ptr
102117
info->dynamic_type = *(reinterpret_cast<const __class_type_info* const*>(ptr_to_ti_proxy));
103118
#else
104119
void **vtable = *static_cast<void ** const *>(static_ptr);
120+
vtable = get_vtable(vtable);
105121
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
106122
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
107123
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
@@ -556,6 +572,7 @@ __base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
556572
if (__offset_flags & __virtual_mask)
557573
{
558574
const char* vtable = *static_cast<const char*const*>(adjustedPtr);
575+
vtable = get_vtable(vtable);
559576
offset_to_base = update_offset_to_base(vtable, offset_to_base);
560577
}
561578
}
@@ -1475,6 +1492,7 @@ __base_class_type_info::search_above_dst(__dynamic_cast_info* info,
14751492
if (__offset_flags & __virtual_mask)
14761493
{
14771494
const char* vtable = *static_cast<const char*const*>(current_ptr);
1495+
vtable = get_vtable(vtable);
14781496
offset_to_base = update_offset_to_base(vtable, offset_to_base);
14791497
}
14801498
__base_type->search_above_dst(info, dst_ptr,
@@ -1495,6 +1513,7 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
14951513
if (__offset_flags & __virtual_mask)
14961514
{
14971515
const char* vtable = *static_cast<const char*const*>(current_ptr);
1516+
vtable = get_vtable(vtable);
14981517
offset_to_base = update_offset_to_base(vtable, offset_to_base);
14991518
}
15001519
__base_type->search_below_dst(info,

0 commit comments

Comments
 (0)