From patchwork Mon Apr 27 21:06:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 465216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 08F161400DE for ; Tue, 28 Apr 2015 07:06:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=OlGBolkS; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=f2bvzvJC/qUvr5FN8 XM4zolQMjJ/Za3Zb6/i5cXusvoea8nVoPiZJapish5OpdF2lo7mapkwGxAP45JVl qh30rYnXGJYJ9eI2HKIPd6vjMx/D4ZUx+2uZefLMwSJeJXsfuOWVOyOaKr/mmAcg a6iTOd49nx2GD5f3l+Mb9/amqI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=X3djX9XAHP2/T5+9PDRz2Qt C62Y=; b=OlGBolkSnep4arEkxtK3E6CjJ2qR7R0/HodAYWb7kVq2MFFm53d7vnm L2TFtU1mAbacxTcPOnRaBER2DuWxD0UOkUF6HkFkDODE/6Zh6GkG1vhdIlHXc7Pv R/j+QmxiV98btpGvRsSHYp4+vJX28WTCBC2FTPmnc7YtyrKo6v1o= Received: (qmail 34292 invoked by alias); 27 Apr 2015 21:06:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 34269 invoked by uid 89); 27 Apr 2015 21:06:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 27 Apr 2015 21:06:30 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3RL6Tpd019559 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Apr 2015 17:06:29 -0400 Received: from localhost (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3RL6S2u021983; Mon, 27 Apr 2015 17:06:29 -0400 Date: Mon, 27 Apr 2015 22:06:28 +0100 From: Jonathan Wakely To: Federico Lenarduzzi Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions Message-ID: <20150427210628.GS3618@redhat.com> References: <1429024679-17856-1-git-send-email-federico.lenarduzzi@tallertechnologies.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1429024679-17856-1-git-send-email-federico.lenarduzzi@tallertechnologies.com> User-Agent: Mutt/1.5.23 (2014-03-12) On 14/04/15 12:17 -0300, Federico Lenarduzzi wrote: >When the libstdc++ is compiled, the compiler sets the std::terminate_handler function with __verbose_terminate_handler() or std::abort() depending on _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE being true or false. > >However, even if we compile with -fno-exceptions, the compiler will use __verbose_terminate_handler(), which uses exceptions. Therefore, the library is not fully exception-free. > >This patch adds a check for __EXCEPTIONS to the #if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE condition. If __EXCEPTIONS is defined, the compiler will use __verbose_terminate_handler() as a termination function; otherwise it'll use std::abort() which doesn't have exceptions. It also makes std::uncaught_exception() throw() return false if __EXCEPTIONS is not defined. I've committed this slightly revised version using __cpp_exceptions instead, and changing the new std::uncaught_exceptions() function too. Tested x86_64-linux and powerpc64le-linux, and also built with --enable-libstdcxx-flags=-fno-exceptions on x86_64-linux. commit 80bc538bd64c7f6b9a21ec5d1a3bc5b08bc8770b Author: Jonathan Wakely Date: Mon Apr 27 14:04:50 2015 +0100 2015-04-27 Federico Lenarduzzi Jonathan Wakely * libsupc++/eh_catch.cc (uncaught_exception, uncaught_exceptions): Return false or zero if the library is built without exceptions. * libsupc++/eh_term_handler.cc: Disable verbose terminate handler if the library is built without exceptions. diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc index 723ae56..44fde79 100644 --- a/libstdc++-v3/libsupc++/eh_catch.cc +++ b/libstdc++-v3/libsupc++/eh_catch.cc @@ -136,13 +136,21 @@ __cxxabiv1::__cxa_end_catch () bool std::uncaught_exception() throw() { +#if __cpp_exceptions __cxa_eh_globals *globals = __cxa_get_globals (); return globals->uncaughtExceptions != 0; +#else + return false; +#endif } int std::uncaught_exceptions() throw() { +#if __cpp_exceptions __cxa_eh_globals *globals = __cxa_get_globals (); return globals->uncaughtExceptions; +#else + return 0; +#endif } diff --git a/libstdc++-v3/libsupc++/eh_term_handler.cc b/libstdc++-v3/libsupc++/eh_term_handler.cc index 46acee8..0d6ea2b 100644 --- a/libstdc++-v3/libsupc++/eh_term_handler.cc +++ b/libstdc++-v3/libsupc++/eh_term_handler.cc @@ -32,7 +32,7 @@ --disable-libstdcxx-verbose and rebuilding the library. In a freestanding environment, we default to this latter approach. */ -#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE && __cpp_exceptions /* The current installed user handler. */ std::terminate_handler __cxxabiv1::__terminate_handler = __gnu_cxx::__verbose_terminate_handler;