[libcxx-commits] [libcxxabi] [libcxx] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 16 14:54:29 PST 2023


================
@@ -34,6 +56,37 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept
     return *this;
 }
 
+#  if defined(_LIBCPP_EXCEPTION_PTR_DIRECT_INIT)
+void *exception_ptr::__init_native_exception(size_t size, type_info* tinfo, void (_LIBCXX_DTOR_FUNC* dest)(void*)) noexcept
+{
+    __cxa_exception *(*cxa_init_primary_exception_fn)(void*, std::type_info*, void(_LIBCXX_DTOR_FUNC*)(void*)) = __cxa_init_primary_exception;
----------------
ldionne wrote:

Both libcxxrt and libsupc++ do implement the function, so this should not be an issue, right?

If you `LD_PRELOAD` an older version of libc++abi, then you must have provided the appropriate deployment target when compiling your program. If you do and the deployment target doesn't provide the new function, there's no issue cause the code will use the throw-dance. If you lie about the deployment target (e.g. use a recent one) but then run against an old libc++abi, you get a load-time error for the missing symbol, as you should.

https://github.com/llvm/llvm-project/pull/65534


More information about the libcxx-commits mailing list