[libcxx-commits] [PATCH] D77606: [libcxxabi] Add macro for changing functions to support the relative vtables ABI
Leonard Chan via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 8 10:44:52 PDT 2020
leonardchan updated this revision to Diff 297013.
leonardchan edited the summary of this revision.
leonardchan added a comment.
Update to use the `__has_feature(cxx_abi_relative_vtable)` macro to check how we should find the dynamic_type.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77606/new/
https://reviews.llvm.org/D77606
Files:
libcxxabi/src/private_typeinfo.cpp
Index: libcxxabi/src/private_typeinfo.cpp
===================================================================
--- libcxxabi/src/private_typeinfo.cpp
+++ libcxxabi/src/private_typeinfo.cpp
@@ -615,10 +615,27 @@
// Possible future optimization: Take advantage of src2dst_offset
// Get (dynamic_ptr, dynamic_type) from static_ptr
- void **vtable = *static_cast<void ** const *>(static_ptr);
- ptrdiff_t offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
+#if __has_feature(cxx_abi_relative_vtable)
+ // The vtable address will point to the first virtual function, which is 8
+ // bytes after the start of the vtable (4 for the offset from top + 4 for the typeinfo component).
+ uint32_t* vtable = *reinterpret_cast<uint32_t* const*>(static_ptr);
+ uint32_t offset_to_derived = vtable[-2];
const void* dynamic_ptr = static_cast<const char*>(static_ptr) + offset_to_derived;
- const __class_type_info* dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
+
+ // The typeinfo component is now a relative offset to a proxy.
+ int32_t offset_to_ti_proxy = static_cast<int32_t>(vtable[-1]);
+ uint8_t* ptr_to_ti_proxy =
+ reinterpret_cast<uint8_t*>(vtable) + offset_to_ti_proxy;
+ const __class_type_info* dynamic_type =
+ *(reinterpret_cast<__class_type_info**>(ptr_to_ti_proxy));
+#else
+ void** vtable = *static_cast<void** const*>(static_ptr);
+ ptrdiff_t offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
+ const void* dynamic_ptr =
+ static_cast<const char*>(static_ptr) + offset_to_derived;
+ const __class_type_info* dynamic_type =
+ static_cast<const __class_type_info*>(vtable[-1]);
+#endif
// Initialize answer to nullptr. This will be changed from the search
// results if a non-null answer is found. Regardless, this is what will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77606.297013.patch
Type: text/x-patch
Size: 1876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201008/8d19b2ed/attachment-0001.bin>
More information about the libcxx-commits
mailing list