]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Print assertion messages to stderr [PR59675]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 3 Nov 2021 16:06:29 +0000 (16:06 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 12 Nov 2021 12:23:10 +0000 (12:23 +0000)
This replaces the printf used by failed debug assertions with fprintf,
so we can write to stderr.

To avoid including <stdio.h> the assert function is moved into the
library. To avoid programs using a vague linkage definition of the old
inline function, the function is renamed. Code compiled with old
versions of GCC might still call the old function, but code compiled
with the newer GCC will call the new function and write to stderr.

libstdc++-v3/ChangeLog:

PR libstdc++/59675
* acinclude.m4 (libtool_VERSION): Bump version.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Add version and
export new symbol.
* configure: Regenerate.
* include/bits/c++config (__replacement_assert): Remove, declare
__glibcxx_assert_fail instead.
* src/c++11/debug.cc (__glibcxx_assert_fail): New function to
replace __replacement_assert, writing to stderr instead of
stdout.
* testsuite/util/testsuite_abi.cc: Update latest version.

libstdc++-v3/acinclude.m4
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/configure
libstdc++-v3/include/bits/c++config
libstdc++-v3/src/c++11/debug.cc
libstdc++-v3/testsuite/util/testsuite_abi.cc

index 497af5723e158abdadf8fdd7932d9f5e45cfd1f5..4adfdf646acbcb63c9c8bb5199d17ac5c9970366 100644 (file)
@@ -3798,7 +3798,7 @@ changequote([,])dnl
 fi
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:29:0
+libtool_VERSION=6:30:0
 
 # Everything parsed; figure out what files and settings to use.
 case $enable_symvers in
index 5323c7f06043722ed04da133153dec8161900472..8f3c7b3827ead76b35ccc3d29e8f91563947b92e 100644 (file)
@@ -2397,6 +2397,12 @@ GLIBCXX_3.4.29 {
 
 } GLIBCXX_3.4.28;
 
+GLIBCXX_3.4.30 {
+
+    _ZSt21__glibcxx_assert_fail*;
+
+} GLIBCXX_3.4.29;
+
 # Symbols in the support library (libsupc++) have their own tag.
 CXXABI_1.3 {
 
index 21371031b66174a301fa00145815d282ccf0ef6c..3a572475546f1d8eab8b7b2629eeb33d8bb22134 100755 (executable)
@@ -74892,7 +74892,7 @@ $as_echo "$as_me: WARNING: === Symbol versioning will be disabled." >&2;}
 fi
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:29:0
+libtool_VERSION=6:30:0
 
 # Everything parsed; figure out what files and settings to use.
 case $enable_symvers in
index a64958096718126a49e8767694e913ed96108df2..4b7fa6593001f4ca3370f75ffdd7eff3a09d0575 100644 (file)
@@ -526,22 +526,17 @@ namespace std
   // Avoid the use of assert, because we're trying to keep the <cassert>
   // include out of the mix.
   extern "C++" _GLIBCXX_NORETURN
-  inline void
-  __replacement_assert(const char* __file, int __line,
-                      const char* __function, const char* __condition)
-  _GLIBCXX_NOEXCEPT
-  {
-    __builtin_printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
-                    __function, __condition);
-    __builtin_abort();
-  }
+  void
+  __glibcxx_assert_fail(const char* __file, int __line,
+                       const char* __function, const char* __condition)
+  _GLIBCXX_NOEXCEPT;
 }
-#define __glibcxx_assert_impl(_Condition)                             \
-  if (__builtin_expect(!bool(_Condition), false))                     \
-  {                                                                   \
-    __glibcxx_constexpr_assert(false);                                \
-    std::__replacement_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
-                             #_Condition);                            \
+#define __glibcxx_assert_impl(_Condition)                              \
+  if (__builtin_expect(!bool(_Condition), false))                      \
+  {                                                                    \
+    __glibcxx_constexpr_assert(false);                                 \
+    std::__glibcxx_assert_fail(__FILE__, __LINE__, __PRETTY_FUNCTION__,        \
+                              #_Condition);                            \
   }
 # else // ! VERBOSE_ASSERT
 # define __glibcxx_assert_impl(_Condition)             \
@@ -550,7 +545,7 @@ namespace std
     __glibcxx_constexpr_assert(false);                 \
     __builtin_abort();                                 \
   }
-#endif
+# endif
 #endif
 
 #if defined(_GLIBCXX_ASSERTIONS)
index 0128535135e0672ccbb47c9b53894720285596a7..77cb2a2c7edb1a1bb49692828509c7a4c61eb790 100644 (file)
@@ -33,7 +33,8 @@
 #include <debug/vector>
 
 #include <cassert>
-#include <cstdio>
+#include <cstdio>      // for std::fprintf, stderr
+#include <cstdlib>     // for std::abort
 #include <cctype>      // for std::isspace.
 #include <cstring>     // for std::strstr.
 
 
 #include "mutex_pool.h"
 
+#ifdef _GLIBCXX_VERBOSE_ASSERT
+namespace std
+{
+  [[__noreturn__]]
+  void
+  __glibcxx_assert_fail(const char* file, int line,
+                       const char* function, const char* condition) noexcept
+  {
+    fprintf(stderr, "%s:%d: %s: Assertion '%s' failed.\n",
+                     file, line, function, condition);
+    abort();
+  }
+}
+#endif
+
 using namespace std;
 
 namespace
index 3af5dc593c28050e91ba86ccbc49eeae8c6ad28c..1ca7da4fcd03b67b6342be14bd22e30aee7766df 100644 (file)
@@ -210,6 +210,7 @@ check_version(symbol& test, bool added)
       known_versions.push_back("GLIBCXX_3.4.27");
       known_versions.push_back("GLIBCXX_3.4.28");
       known_versions.push_back("GLIBCXX_3.4.29");
+      known_versions.push_back("GLIBCXX_3.4.30");
       known_versions.push_back("GLIBCXX_LDBL_3.4.29");
       known_versions.push_back("GLIBCXX_IEEE128_3.4.29");
       known_versions.push_back("CXXABI_1.3");
@@ -245,7 +246,7 @@ check_version(symbol& test, bool added)
        test.version_status = symbol::incompatible;
 
       // Check that added symbols are added in the latest pre-release version.
-      bool latestp = (test.version_name == "GLIBCXX_3.4.29"
+      bool latestp = (test.version_name == "GLIBCXX_3.4.30"
          // XXX remove next 3 lines when baselines have been regenerated
          // to include {IEEE128,LDBL} symbols:
                     || test.version_name == "GLIBCXX_LDBL_3.4.29"