[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
Wed Aug 12 17:46:48 PDT 2020


leonardchan updated this revision to Diff 285224.
leonardchan retitled this revision from "[WIP][libcxxabi] Add macro for changing functions to support the relative vtables ABI" to "[libcxxabi] Add macro for changing functions to support the relative vtables ABI".
leonardchan edited the summary of this revision.
leonardchan removed 1 blocking reviewer(s): libc++abi.
leonardchan added a comment.
Herald added 1 blocking reviewer(s): libc++abi.

Ok. Ready for review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77606/new/

https://reviews.llvm.org/D77606

Files:
  libcxxabi/CMakeLists.txt
  libcxxabi/src/private_typeinfo.cpp


Index: libcxxabi/src/private_typeinfo.cpp
===================================================================
--- libcxxabi/src/private_typeinfo.cpp
+++ libcxxabi/src/private_typeinfo.cpp
@@ -615,10 +615,25 @@
     // 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]);
+#ifdef _LIBCXXABI_RELATIVE_VTABLES_ABI_ENABLED
+    // 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
Index: libcxxabi/CMakeLists.txt
===================================================================
--- libcxxabi/CMakeLists.txt
+++ libcxxabi/CMakeLists.txt
@@ -140,6 +140,11 @@
 set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
     "A list of parameters to run the Lit test suite with.")
 
+option(LIBCXXABI_RELATIVE_VTABLES_ABI_ENABLED
+  "Use different configurations of libcxxabi functions supported for the \
+  Relative VTables ABI, which replaces vtable function pointers with offsets \
+  between those virtual functions and the vtable itself." OFF)
+
 #===============================================================================
 # Configure System
 #===============================================================================
@@ -436,6 +441,10 @@
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
 
+if (LIBCXXABI_RELATIVE_VTABLES_ABI_ENABLED)
+  add_definitions(-D_LIBCXXABI_RELATIVE_VTABLES_ABI_ENABLED)
+endif()
+
 #===============================================================================
 # Setup Source Code
 #===============================================================================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77606.285224.patch
Type: text/x-patch
Size: 3054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200813/6998f6ce/attachment.bin>


More information about the libcxx-commits mailing list