From patchwork Mon Jan 18 13:54:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 569548 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 87B4914076E for ; Tue, 19 Jan 2016 00:54:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=WF0Cw9c0; 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 :message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version; q=dns; s=default; b=b+uxZLg51RMU/d+v KBmhoGtU1P6payg55G8MAkzEn/tMkIVG9v/pVFRhNr8fMD/+YhaIwTC7V7Y/HIbN P8U5M72pJl+yiB80n2wO1fnZ2/FdEZ2GuWS4u/01S6Szb1eLPDm1IgAZs4NxoPYJ vsmG69rfQJZrjTGWE0PRjjkrFuw= 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 :message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version; s=default; bh=IP0DKmj75xjJ/iNg2ztP4j VlzJE=; b=WF0Cw9c03bIxNxsBrDi/wS9bHGXYySgpGNZpSmlBDXifr3i2y78NFw AoKLLnZno1KMj310tow+A0dqB4GVWYQgXnnqN6QbuI5CwTMtjxC0goAe9sWioliM NYh2ftwWC13a/xYv88EzEg93U9VuAuidpdY/WL9UPI0gPqC2FWr3I= Received: (qmail 27346 invoked by alias); 18 Jan 2016 13:54:49 -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 27320 invoked by uid 89); 18 Jan 2016 13:54:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 spammy=4413, remainder 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, 18 Jan 2016 13:54:47 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 4696BA852; Mon, 18 Jan 2016 13:54:46 +0000 (UTC) Received: from [10.36.7.207] (vpn1-7-207.ams2.redhat.com [10.36.7.207]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0IDsgUL024875 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Mon, 18 Jan 2016 08:54:44 -0500 Message-ID: <1453125282.26597.422.camel@localhost.localdomain> Subject: Re: [PATCH v2] libstdc++: Make certain exceptions transaction_safe. From: Torvald Riegel To: David Edelsohn Cc: Jakub Jelinek , Jonathan Wakely , GCC Patches , "libstdc++@gcc.gnu.org" , Jason Merrill Date: Mon, 18 Jan 2016 14:54:42 +0100 In-Reply-To: References: <20160116124323.GM15084@redhat.com> <20160116133521.GN3017@tucnak.redhat.com> <1453062105.26597.419.camel@localhost.localdomain> Mime-Version: 1.0 X-IsSubscribed: yes On Sun, 2016-01-17 at 18:30 -0500, David Edelsohn wrote: > On Sun, Jan 17, 2016 at 3:21 PM, Torvald Riegel wrote: > > On Sat, 2016-01-16 at 15:38 -0500, David Edelsohn wrote: > >> On Sat, Jan 16, 2016 at 8:35 AM, Jakub Jelinek wrote: > >> > On Sat, Jan 16, 2016 at 07:47:33AM -0500, David Edelsohn wrote: > >> >> stage1 libstdc++ builds just fine. the problem is stage2 configure > >> >> fails due to missing ITM_xxx symbols when configure tries to compile > >> >> and run conftest programs. > >> > > >> > On x86_64-linux, the _ITM_xxx symbols are undef weak ones and thus it is > >> > fine to load libstdc++ without libitm and libstdc++ doesn't depend on > >> > libitm. > >> > > >> > So, is AIX defining __GXX_WEAK__ or not? Perhaps some other macro or > >> > configure check needs to be used to determine if undefined weak symbols > >> > work the way libstdc++ needs them to. > >> > >> __GXX_WEAK__ appears to be defined by gcc/c-family/c-cppbuiltin.c > >> based on SUPPORTS_ONE_ONLY. gcc/defaults.h defines SUPPORTS_ONE_ONLY > >> if the target supports MAKE_DECL_ONE_ONLY and link-once semantics. > >> AIX weak correctly supports link-once semantics. AIX also supports > >> the definition of __GXX_WEAK__ in gcc/doc/cpp.texi, namely collapsing > >> symbols with vague linkage in multiple translation units. > >> > >> libstdc++/src/c++11/cow-stdexcept.cc appears to be using __GXX_WEAK__ > >> and __attribute__ ((weak)) for references to symbols that may not be > >> defined at link time or run time. AIX does not allow undefined symbol > >> errors by default. And the libstdc++ inference about the semantics of > >> __GXX_WEAK__ are different than the documentation. > >> > >> AIX supports MAKE_DECL_ONE_ONLY and the documented meaning of > >> __GXX_WEAK__. AIX does not support extension of the meaning to > >> additional SVR4 semantics not specified in the documentation. > > > > I see, so we might be assuming that __GXX_WEAK__ means more than it > > actually does (I'm saying "might" because personally, I don't know; your > > information supports this is the case, but the initial info I got was > > that __GXX_WEAK__ would mean we could have weak decls without > > definitions). > > I believe that libstdc++ must continue with the weak undefined > references to the symbols as designed, but protect them with a > different macro. For example, __GXX_WEAK_REF__ or __GXX_WEAK_UNDEF__ > defined in defaults.h based on configure test or simply overridden in > config/rs6000/aix.h. Or the macro could be local to libstdc++ and > overridden in config/os/aix/os_defines.h. OK. I'm currently testing the attached patch on x86_64-linux. David, if there are no objections from you and those CC'ed, could you give this one a try on AIX, please? * include/bits/c++config (_GLIBCXX_USE_WEAK_REF): New. (_GLIBCXX_TXN_SAFE, _GLIBCXX_TXN_SAFE_DYN): Use _GLIBCXX_USE_WEAK_REF and move after its definition. * config/os/aix/os_defines.h (_GLIBCXX_USE_WEAK_REF): Override. * src/c++11/cow-stdexcept.cc: Use _GLIBCXX_USE_WEAK_REF instead of __GXX_WEAK__, and only provide transactional clones if _GLIBCXX_USE_WEAK_REF is true. Don't provide stubs of libitm functions. commit a5a8819bce824815a94ef8d58f6d4123db92f1d4 Author: Torvald Riegel Date: Mon Jan 18 14:42:21 2016 +0100 libstdc++: Fix usage of __GXX_WEAK__ in TM TS support. * include/bits/c++config (_GLIBCXX_USE_WEAK_REF): New. (_GLIBCXX_TXN_SAFE, _GLIBCXX_TXN_SAFE_DYN): Use _GLIBCXX_USE_WEAK_REF and move after its definition. * config/os/aix/os_defines.h (_GLIBCXX_USE_WEAK_REF): Override. * src/c++11/cow-stdexcept.cc: Use _GLIBCXX_USE_WEAK_REF instead of __GXX_WEAK__, and only provide transactional clones if _GLIBCXX_USE_WEAK_REF is true. Don't provide stubs of libitm functions. diff --git a/libstdc++-v3/config/os/aix/os_defines.h b/libstdc++-v3/config/os/aix/os_defines.h index d895471..0949446 100644 --- a/libstdc++-v3/config/os/aix/os_defines.h +++ b/libstdc++-v3/config/os/aix/os_defines.h @@ -48,4 +48,7 @@ #define __COMPATMATH__ #endif +// No support for referencing weak symbols without a definition. +#define _GLIBCXX_USE_WEAK_REF 0 + #endif diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 387a7bb..57024e4 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -483,20 +483,6 @@ namespace std #define _GLIBCXX_USE_ALLOCATOR_NEW -// Conditionally enable annotations for the Transactional Memory TS on C++11. -// Most of the following conditions are due to limitations in the current -// implementation. -#if __cplusplus >= 201103L && _GLIBCXX_USE_CXX11_ABI \ - && _GLIBCXX_USE_DUAL_ABI && __cpp_transactional_memory >= 201505L \ - && !_GLIBCXX_FULLY_DYNAMIC_STRING && __GXX_WEAK__ \ - && _GLIBCXX_USE_ALLOCATOR_NEW -#define _GLIBCXX_TXN_SAFE transaction_safe -#define _GLIBCXX_TXN_SAFE_DYN transaction_safe_dynamic -#else -#define _GLIBCXX_TXN_SAFE -#define _GLIBCXX_TXN_SAFE_DYN -#endif - #else // !__cplusplus # define _GLIBCXX_BEGIN_EXTERN_C # define _GLIBCXX_END_EXTERN_C @@ -524,6 +510,28 @@ namespace std # define _GLIBCXX_WEAK_DEFINITION #endif +// By default, we assume that __GXX_WEAK__ also means that there is support +// for declaring functions as weak while not defining such functions. This +// allows for referring to functions provided by other libraries (e.g., +// libitm) without depending on them if the respective features are not used. +#ifndef _GLIBCXX_USE_WEAK_REF +# define _GLIBCXX_USE_WEAK_REF __GXX_WEAK__ +#endif + +// Conditionally enable annotations for the Transactional Memory TS on C++11. +// Most of the following conditions are due to limitations in the current +// implementation. +#if __cplusplus >= 201103L && _GLIBCXX_USE_CXX11_ABI \ + && _GLIBCXX_USE_DUAL_ABI && __cpp_transactional_memory >= 201505L \ + && !_GLIBCXX_FULLY_DYNAMIC_STRING && _GLIBCXX_USE_WEAK_REF \ + && _GLIBCXX_USE_ALLOCATOR_NEW +#define _GLIBCXX_TXN_SAFE transaction_safe +#define _GLIBCXX_TXN_SAFE_DYN transaction_safe_dynamic +#else +#define _GLIBCXX_TXN_SAFE +#define _GLIBCXX_TXN_SAFE_DYN +#endif + // The remainder of the prewritten config is automatic; all the // user hooks are listed above. diff --git a/libstdc++-v3/src/c++11/cow-stdexcept.cc b/libstdc++-v3/src/c++11/cow-stdexcept.cc index eddb36b..a0f505c 100644 --- a/libstdc++-v3/src/c++11/cow-stdexcept.cc +++ b/libstdc++-v3/src/c++11/cow-stdexcept.cc @@ -179,6 +179,13 @@ _GLIBCXX_END_NAMESPACE_VERSION // Furthermore, _Rep will always have been allocated or deallocated via // global new or delete, so nontransactional writes we do to _Rep cannot // interfere with transactional accesses. + +// We depend on having support for referencing functions declared weak that +// are not defined by us. Without such support, the exceptions will not be +// declared transaction-safe, so we just don't provide transactional clones +// in this case. +#if _GLIBCXX_USE_WEAK_REF + extern "C" { #ifndef _GLIBCXX_MANGLE_SIZE_T @@ -195,7 +202,6 @@ extern "C" { # define ITM_REGPARM #endif -#if __GXX_WEAK__ // Declare all libitm symbols we rely on, but make them weak so that we do // not depend on libitm. extern void* _ZGTtnaX (size_t sz) __attribute__((weak)); @@ -213,19 +219,6 @@ extern void _ITM_memcpyRnWt(void *, const void *, size_t) extern void _ITM_addUserCommitAction(void (*)(void *), uint64_t, void *) ITM_REGPARM __attribute__((weak)); -#else -// If there is no support for weak symbols, create dummies. The exceptions -// will not be declared transaction_safe in this case. -void* _ZGTtnaX (size_t) { return NULL; } -void _ZGTtdlPv (void*) { } -uint8_t _ITM_RU1(const uint8_t *) { return 0; } -uint32_t _ITM_RU4(const uint32_t *) { return 0; } -uint64_t _ITM_RU8(const uint64_t *) { return 0; } -void _ITM_memcpyRtWn(void *, const void *, size_t) { } -void _ITM_memcpyRnWt(void *, const void *, size_t) { } -void _ITM_addUserCommitAction(void (*)(void *), uint64_t, void *) { }; -#endif - } // A transactional version of basic_string::basic_string(const char *s) @@ -441,3 +434,5 @@ CTORDTOR(14overflow_error, std::overflow_error, runtime_error) CTORDTOR(15underflow_error, std::underflow_error, runtime_error) } + +#endif // _GLIBCXX_USE_WEAK_REF