From patchwork Sun Jul 22 16:46:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 172522 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]) by ozlabs.org (Postfix) with SMTP id B99992C012C for ; Mon, 23 Jul 2012 02:47:25 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343580447; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=h5kh7IhazepNbp9JZYxoj91B1Ao=; b=B+crqVupwG++FEP0/M16Cl46DSPBqLhyY2GJH1880mhc9kNnwAxaz2b6F/O2t9 jHXW+fLqMUT1X0SJk0KYhfwZNjy0qsBRHk0NG+Y0ZICGxDV8xvFYBUqaq68vYQSh 2AegrSbX7k8qZK6NYWa9MVd+8qD3yJfLUC0FQGiKMnM1k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=JW8RxdnSjSI8LMqqZqN14X6EaVkfkSzdSURzin1P+UL4tW4jn5KZcZEc4xPqWU /l0EH3fXlMgq3THd3ijsKwaLDoruNFopJXZWtpNG057bUB7995Tqd0rXSR+VuVG+ GQLlpF5gQu7FqWEyG2ojhtXePcYUofSyUWgSV5tkD9JSI=; Received: (qmail 15380 invoked by alias); 22 Jul 2012 16:47:14 -0000 Received: (qmail 15353 invoked by uid 22791); 22 Jul 2012 16:47:12 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CP X-Spam-Check-By: sourceware.org Received: from mail-lb0-f175.google.com (HELO mail-lb0-f175.google.com) (209.85.217.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 22 Jul 2012 16:46:56 +0000 Received: by lbol5 with SMTP id l5so9262009lbo.20 for ; Sun, 22 Jul 2012 09:46:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.88.34 with SMTP id bd2mr6009781lbb.33.1342975612851; Sun, 22 Jul 2012 09:46:52 -0700 (PDT) Received: by 10.112.27.228 with HTTP; Sun, 22 Jul 2012 09:46:52 -0700 (PDT) In-Reply-To: References: Date: Sun, 22 Jul 2012 17:46:52 +0100 Message-ID: Subject: Re: [v3] PR 53270 fix hppa-linux bootstrap regression From: Jonathan Wakely To: "libstdc++" , gcc-patches Cc: Jason Merrill , danglin@gcc.gnu.org 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 Here's a simpler solution for the 4.6 branch, which is a bit hacky but only affects hppa-linux with LinuxThreads in C++0x mode. PR libstdc++/53270 * acinclude.m4 (GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN): Define. * configure.ac (GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN): Use it. * config.h.in: Regenerate. * configure: Likewise. * include/ext/concurrence.h (__copy_gthr_type): Define. (__mutex::__mutex, __recursive_mutex::__recursive_mutex, __cond::__cond): Use it. * include/ext/rope (__copy_gthr_mutex): Define. (_Refcount_Base::_Refcount_Base, _Rope_RopeRep::_Rope_RopeRep): Use it. * src/condition_variable.cc (condition_variable::condition_variable): Use memcpy instead of assignment. Tested x86_64-linux, hppa-linux, powerpc64-linux, x86_64-netbsd, committed to the 4.6 branch, and I can finally close the PR as fixed. commit 36d2e77bb740df5f9ef68a52f7cac95f8306dfd1 Author: Jonathan Wakely Date: Sun Jul 22 02:02:09 2012 +0100 PR libstdc++/53270 * acinclude.m4 (GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN): Define. * configure.ac (GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN): Use it. * config.h.in: Regenerate. * configure: Likewise. * include/ext/concurrence.h (__copy_gthr_type): Define. (__mutex::__mutex, __recursive_mutex::__recursive_mutex, __cond::__cond): Use it. * include/ext/rope (__copy_gthr_mutex): Define. (_Refcount_Base::_Refcount_Base, _Rope_RopeRep::_Rope_RopeRep): Use it. * src/condition_variable.cc (condition_variable::condition_variable): Use memcpy instead of assignment. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index d6735e9..788966c 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -3213,6 +3213,58 @@ AC_DEFUN([AC_LC_MESSAGES], [ ]) ]) +dnl +dnl Check whether gthreads types can be copy-assigned in C++11 mode. +dnl +AC_DEFUN([GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x -I${toplevel_srcdir}/gcc" + + target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'` + case $target_thread_file in + posix) + CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS" + esac + + AC_MSG_CHECKING([whether gthreads types are copy-assignable in C++11 mode]) + + AC_TRY_COMPILE([#include "gthr.h"], + [ + #ifdef __GTHREAD_MUTEX_INIT + __gthread_mutex_t m1; + __gthread_mutex_t m2 = __GTHREAD_MUTEX_INIT; + m1 = m2; + #endif + #ifdef __GTHREAD_RECURSIVE_MUTEX_INIT + __gthread_recursive_mutex_t r1; + __gthread_recursive_mutex_t r2 = __GTHREAD_RECURSIVE_MUTEX_INIT; + r1 = r2; + #endif + #ifdef __GTHREAD_HAS_COND + #ifdef __GTHREAD_COND_INIT + __gthread_cond_t c1; + __gthread_cond_t c2 = __GTHREAD_COND_INIT; + c1 = c2; + #endif + #endif + ], [ac_gthread_cxx11_copy_assign=1], [ac_gthread_cxx11_copy_assign=0]) + + if test $ac_gthread_cxx11_copy_assign = 1 ; then res_gthr_copy_assign=yes ; + else res_gthr_copy_assign=no ; fi + AC_MSG_RESULT([$res_gthr_copy_assign]) + + if test x"$res_gthr_copy_assign" = x"no"; then + AC_DEFINE(_GLIBCXX_GTHREADS_NO_COPY_ASSIGN_IN_CXX11, 1, + [Define if gthreads types cannot be copy-assigned in C++11.]) + fi + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + # Macros from the top-level gcc directory. m4_include([../config/gc++filt.m4]) m4_include([../config/tls.m4]) diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index cc4c9bf..427cf0b 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -164,6 +164,9 @@ GLIBCXX_ENABLE_LIBSTDCXX_TIME([no]) # For gthread support GLIBCXX_CHECK_GTHREADS +# For copy-assignable gthreads types +GLIBCXX_GTHREADS_CXX11_COPY_ASSIGN + AC_LC_MESSAGES # Check for available headers. diff --git a/libstdc++-v3/include/ext/concurrence.h b/libstdc++-v3/include/ext/concurrence.h index 4719c84..ce999e5 100644 --- a/libstdc++-v3/include/ext/concurrence.h +++ b/libstdc++-v3/include/ext/concurrence.h @@ -1,6 +1,6 @@ // Support for concurrent programing -*- C++ -*- -// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -140,6 +140,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif + template + static inline void + __copy_gthr_type(_Tp& __to, const _Tp& __from) + { +#if defined __GXX_EXPERIMENTAL_CXX0X__ \ + && defined _GLIBCXX_GTHREADS_NO_COPY_ASSIGN_IN_CXX11 + __builtin_memcpy(&__to, &__from, sizeof(__to)); +#else + __to = __from; +#endif + } + class __mutex { private: @@ -156,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #if defined __GTHREAD_MUTEX_INIT __gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT; - _M_mutex = __tmp; + __copy_gthr_type(_M_mutex, __tmp); #else __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex); #endif @@ -214,7 +226,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #if defined __GTHREAD_RECURSIVE_MUTEX_INIT __gthread_recursive_mutex_t __tmp = __GTHREAD_RECURSIVE_MUTEX_INIT; - _M_mutex = __tmp; + __copy_gthr_type(_M_mutex, __tmp); #else __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex); #endif @@ -332,7 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #if defined __GTHREAD_COND_INIT __gthread_cond_t __tmp = __GTHREAD_COND_INIT; - _M_cond = __tmp; + __copy_gthr_type(_M_cond, __tmp); #else __GTHREAD_COND_INIT_FUNCTION(&_M_cond); #endif diff --git a/libstdc++-v3/include/ext/rope b/libstdc++-v3/include/ext/rope index 4292151..84837ac 100644 --- a/libstdc++-v3/include/ext/rope +++ b/libstdc++-v3/include/ext/rope @@ -1,7 +1,7 @@ // SGI's rope class -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 -// Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, +// 2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -445,6 +445,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION identity_element(_Rope_Concat_fn<_CharT, _Alloc>) { return rope<_CharT, _Alloc>(); } + static inline void + __copy_gthr_mutex(__gthread_mutex_t& __to, const __gthread_mutex_t& __from) + { +#if defined __GXX_EXPERIMENTAL_CXX0X__ \ + && defined _GLIBCXX_GTHREADS_NO_COPY_ASSIGN_IN_CXX11 + __builtin_memcpy(&__to, &__from, sizeof(__to)); +#else + __to = __from; +#endif + } + // Class _Refcount_Base provides a type, _RC_t, a data member, // _M_ref_count, and member functions _M_incr and _M_decr, which perform // atomic preincrement/predecrement. The constructor initializes @@ -464,7 +475,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #ifdef __GTHREAD_MUTEX_INIT __gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT; - _M_ref_count_lock = __tmp; + __copy_gthr_mutex(_M_ref_count_lock, __tmp); #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION) __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock); #else @@ -605,7 +616,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // Do not copy a POSIX/gthr mutex once in use. However, bits are bits. __gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT; - _M_c_string_lock = __tmp; + __copy_gthr_mutex(_M_c_string_lock, __tmp); } #else { __GTHREAD_MUTEX_INIT_FUNCTION (&_M_c_string_lock); } diff --git a/libstdc++-v3/src/condition_variable.cc b/libstdc++-v3/src/condition_variable.cc index 7f1e194..be22dc0 100644 --- a/libstdc++-v3/src/condition_variable.cc +++ b/libstdc++-v3/src/condition_variable.cc @@ -1,6 +1,6 @@ // condition_variable -*- C++ -*- -// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -34,7 +34,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #ifdef __GTHREAD_COND_INIT __native_type __tmp = __GTHREAD_COND_INIT; +#if defined __GXX_EXPERIMENTAL_CXX0X__ \ + && defined _GLIBCXX_GTHREADS_NO_COPY_ASSIGN_IN_CXX11 + __builtin_memcpy(&_M_cond, &__tmp, sizeof(_M_cond)); +#else _M_cond = __tmp; +#endif #else int __e = __gthread_cond_init(&_M_cond, 0);