[libcxx-commits] [PATCH] D60176: [libc++][libc++abi] Don't provide new/delete when built with ASan, HWASan or TSan

Petr Hosek via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 2 20:40:31 PDT 2019


phosek created this revision.
phosek added reviewers: EricWF, ldionne, vitalybuka, eugenis.
Herald added subscribers: libcxx-commits, dexonsmith, christof, mehdi_amini.
Herald added a project: libc++.

ASan, HWASan and TSan provide their own operator new/delete to intercept
all allocations and deallocations. Currently, they rely on overriding
weak symbols that are already provided by libc++abi and libc++, but that
solution is fragile and breaks in certain scenarios, e.g. when libc++abi
is statically linked into a shared libc++.

Rather we should avoid providing new/delete operators when built with
ASan, HWASan and TSan altogether and rely on new/delete operators
provided by the sanitizer runtimes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60176

Files:
  libcxx/src/new.cpp
  libcxxabi/src/stdlib_new_delete.cpp


Index: libcxxabi/src/stdlib_new_delete.cpp
===================================================================
--- libcxxabi/src/stdlib_new_delete.cpp
+++ libcxxabi/src/stdlib_new_delete.cpp
@@ -17,6 +17,11 @@
 #error The _THROW_BAD_ALLOC, _NOEXCEPT, and _LIBCXXABI_WEAK libc++ macros must \
        already be defined by libc++.
 #endif
+
+#if !__has_feature(address_sanitizer) && \
+    !__has_feature(hwaddress_sanitizer) && \
+    !__has_feature(thread_sanitizer)
+
 // Implement all new and delete operators as weak definitions
 // in this shared library, so that they can be overridden by programs
 // that define non-weak copies of the functions.
@@ -259,4 +264,6 @@
     ::operator delete[](ptr, alignment);
 }
 
+#endif
+
 #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Index: libcxx/src/new.cpp
===================================================================
--- libcxx/src/new.cpp
+++ libcxx/src/new.cpp
@@ -55,7 +55,10 @@
 
 #if !defined(__GLIBCXX__) &&                                                   \
     !defined(_LIBCPP_ABI_VCRUNTIME) &&      \
-    !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
+    !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) && \
+    !__has_feature(address_sanitizer) && \
+    !__has_feature(hwaddress_sanitizer) && \
+    !__has_feature(thread_sanitizer)
 
 // Implement all new and delete operators as weak definitions
 // in this shared library, so that they can be overridden by programs


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60176.193425.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190403/99478f35/attachment-0001.bin>


More information about the libcxx-commits mailing list