[Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 25 20:58:25 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch for stage 1:

--- a/libstdc++-v3/src/c++11/shared_ptr.cc
+++ b/libstdc++-v3/src/c++11/shared_ptr.cc
@@ -28,6 +28,11 @@

 namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
 {
+  namespace
+  {
+    alignas(64) unsigned char __mutex_storage[64 * (mask + 1)];
+  }
+
   /* Returns different instances of __mutex depending on the passed index
    * in order to limit contention.
    */
@@ -36,7 +41,7 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
   {
     // increase alignment to put each lock on a separate cache line
     struct alignas(64) M : __gnu_cxx::__mutex { };
-    static M m[mask + 1];
+    static M* m = ::new(__mutex_storage) M[mask + 1];
     return m[i];
   }
 }


More information about the Gcc-bugs mailing list