From patchwork Fri Nov 12 12:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 47520 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 898B3385843E for ; Fri, 12 Nov 2021 12:27:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 898B3385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636720061; bh=yC8yRjqvasR69C2EXZiiIeSVADcQxqXdFp0WC4jX4ps=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A8CDzzcrlF97YVwec6Tn8wKhasoodORA1b1xAngGnUc5W5B6B3sfX++2LqQYl4RuA 3uFf+Ps6QPvtdmaSTe8sTDh3lHR7f1P04cJXUp4+qVthGRtvldMqJm61fqHwYqYVSK ugU1ICNK9MZqKuS3gfZIQKPzcGraq4E1MjaOkPCo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 29162385801E for ; Fri, 12 Nov 2021 12:25:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29162385801E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-i46SIbq2PeaaVwYmBfugcw-1; Fri, 12 Nov 2021 07:25:42 -0500 X-MC-Unique: i46SIbq2PeaaVwYmBfugcw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B18F192377C; Fri, 12 Nov 2021 12:25:34 +0000 (UTC) Received: from localhost (unknown [10.33.36.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC481604CC; Fri, 12 Nov 2021 12:25:33 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Print assertion messages to stderr [PR59675] Date: Fri, 12 Nov 2021 12:25:32 +0000 Message-Id: <20211112122532.3204337-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This replaces the printf used by failed debug assertions with fprintf, so we can write to stderr. To avoid including 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 | 2 +- libstdc++-v3/config/abi/pre/gnu.ver | 6 +++++ libstdc++-v3/configure | 2 +- libstdc++-v3/include/bits/c++config | 27 ++++++++------------ libstdc++-v3/src/c++11/debug.cc | 18 ++++++++++++- libstdc++-v3/testsuite/util/testsuite_abi.cc | 3 ++- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 497af5723e1..4adfdf646ac 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -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 diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 5323c7f0604..8f3c7b3827e 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -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 { diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 21371031b66..3a572475546 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -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 diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index a6495809671..4b7fa659300 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -526,22 +526,17 @@ namespace std // Avoid the use of assert, because we're trying to keep the // 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) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index 0128535135e..77cb2a2c7ed 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -33,7 +33,8 @@ #include #include -#include +#include // for std::fprintf, stderr +#include // for std::abort #include // for std::isspace. #include // for std::strstr. @@ -43,6 +44,21 @@ #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 diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc index 3af5dc593c2..1ca7da4fcd0 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.cc +++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc @@ -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"