[libcxx-commits] [PATCH] D91359: [libc++] Only check for GCC's empty string storage on macOS and iOS

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 13 07:49:03 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2728293bbc34: [libc++] Only check for GCC's empty string storage on macOS and iOS (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91359

Files:
  libcxx/src/include/refstring.h


Index: libcxx/src/include/refstring.h
===================================================================
--- libcxx/src/include/refstring.h
+++ libcxx/src/include/refstring.h
@@ -13,12 +13,25 @@
 #include <stdexcept>
 #include <cstddef>
 #include <cstring>
-#ifdef __APPLE__
-#include <dlfcn.h>
-#include <mach-o/dyld.h>
-#endif
 #include "atomic_support.h"
 
+// MacOS and iOS used to ship with libstdc++, and still support old applications
+// linking against libstdc++. The libc++ and libstdc++ exceptions are supposed
+// to be ABI compatible, such that they can be thrown from one library and caught
+// in the other.
+//
+// For that reason, we must look for libstdc++ in the same process and if found,
+// check the string stored in the exception object to see if it is the GCC empty
+// string singleton before manipulating the reference count. This is done so that
+// if an exception is created with a zero-length string in libstdc++, libc++abi
+// won't try to delete the memory.
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \
+    defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
+#   define _LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE
+#   include <dlfcn.h>
+#   include <mach-o/dyld.h>
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace __refstring_imp { namespace {
@@ -40,7 +53,7 @@
     return data + sizeof(*rep);
 }
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE)
 inline
 const char* compute_gcc_empty_string_storage() _NOEXCEPT
 {
@@ -115,7 +128,7 @@
 
 inline
 bool __libcpp_refstring::__uses_refcount() const {
-#ifdef __APPLE__
+#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE)
     return __imp_ != get_gcc_empty_string_storage();
 #else
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91359.305144.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201113/c2ee474e/attachment.bin>


More information about the libcxx-commits mailing list