[libcxx-commits] [libcxx] r358602 - [libc++] Use the no_destroy attribute to avoid destroying debug DB statics
    Louis Dionne via libcxx-commits 
    libcxx-commits at lists.llvm.org
       
    Wed Apr 17 11:20:19 PDT 2019
    
    
  
Author: ldionne
Date: Wed Apr 17 11:20:19 2019
New Revision: 358602
URL: http://llvm.org/viewvc/llvm-project?rev=358602&view=rev
Log:
[libc++] Use the no_destroy attribute to avoid destroying debug DB statics
Summary:
Otherwise, we can run into problems when the program has static variables
that need to use the debug database during their deinitialization, if
the debug DB has already been deinitialized.
Reviewers: EricWF
Subscribers: christof, jkorous, dexonsmith, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D60830
Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/src/debug.cpp
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=358602&r1=358601&r2=358602&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Apr 17 11:20:19 2019
@@ -1120,6 +1120,12 @@ template <unsigned> struct __static_asse
 #endif
 #endif
 
+#if __has_attribute(no_destroy)
+#  define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
+#else
+#  define _LIBCPP_NO_DESTROY
+#endif
+
 #ifndef _LIBCPP_HAS_NO_ASAN
 _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
   const void *, const void *, const void *, const void *);
Modified: libcxx/trunk/src/debug.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/debug.cpp?rev=358602&r1=358601&r2=358602&view=diff
==============================================================================
--- libcxx/trunk/src/debug.cpp (original)
+++ libcxx/trunk/src/debug.cpp Wed Apr 17 11:20:19 2019
@@ -42,7 +42,7 @@ _LIBCPP_FUNC_VIS
 __libcpp_db*
 __get_db()
 {
-    static __libcpp_db db;
+    static _LIBCPP_NO_DESTROY __libcpp_db db;
     return &db;
 }
 
@@ -64,7 +64,7 @@ typedef lock_guard<mutex_type> RLock;
 mutex_type&
 mut()
 {
-    static mutex_type m;
+    static _LIBCPP_NO_DESTROY mutex_type m;
     return m;
 }
 #endif // !_LIBCPP_HAS_NO_THREADS
    
    
More information about the libcxx-commits
mailing list