From patchwork Sun Feb 5 20:26:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 139661 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 C17B3B723B for ; Mon, 6 Feb 2012 07:27:12 +1100 (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=1329078433; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received: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=KjPsbnC HdGpR8DP6HSDi8rV7D1c=; b=HRJqGEi5RD+C5Xr3rKokbhvpKthakxrCD52Q7YV GJtpXg70I2NhtDPPuTPi0o1GHuZeCD3/xrtHE+kStowlhr0K/D8BiZIBbZ0DPP4t zzi+g2mkvvqMYjFUnwjuDzTBKjUymAMJV8w00W8+r0cyPIN2dJPqj7J5z0f5vWlu pZC0= 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: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=xvTeRs+9hMfu9/dOlLU19fd6rokVVgB3zDlOR+ZgbeDbG8N4YN5T7djGM0+LEU 8X6P2LCwiureR+7ik7N6SKWI6waA/WfHZBHfw5731MR7iMixsbK/xvv1eSpfvg99 ECadUKizM+SDI6w4DGAj2udFmSq+0Iy0darrBwUlyajb8=; Received: (qmail 7070 invoked by alias); 5 Feb 2012 20:27:05 -0000 Received: (qmail 6903 invoked by uid 22791); 5 Feb 2012 20:26:59 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_FN X-Spam-Check-By: sourceware.org Received: from mail-lpp01m010-f47.google.com (HELO mail-lpp01m010-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 05 Feb 2012 20:26:24 +0000 Received: by lahc1 with SMTP id c1so2766629lah.20 for ; Sun, 05 Feb 2012 12:26:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.147.202 with SMTP id tm10mr8624593lab.49.1328473582592; Sun, 05 Feb 2012 12:26:22 -0800 (PST) Received: by 10.112.39.42 with HTTP; Sun, 5 Feb 2012 12:26:22 -0800 (PST) Date: Sun, 5 Feb 2012 20:26:22 +0000 Message-ID: Subject: Gthreads patch to disable static initializer macros From: Jonathan Wakely To: gcc-patches Cc: Rainer Orth 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 PRs libstdc++/51296 and libstdc++/51906 are both caused by problems with the Pthreads static initializer macros such as PTHREAD_MUTEX_INITIALIZER. On Tru64 PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER can only be used for statically-initialized variables, as allowed by POSIX currently, but http://austingroupbugs.net/view.php?id=70#c127 removes that limitation for the next POSIX standard. C++11 needs to use those macros for variables with automatic and dynamic scope, because the init functions can't be used in constexpr constructors. On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy. This has shown up now because C++11 threads weren't enabled on darwin before 4.7 My suggestion is to modify gthr-posix.h with the attached patch, so that target maintainers can define e.g. _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC to force use of the init function instead of the __GTHREAD_RECURSIVE_MUTEX_INIT initializer. The patch includes a change to do that for darwin. This has been testing on darwin, if Rainer tests it successfully on Tru64 will the gthr-posix.h change be acceptable? diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h index 46054f6..45b15a8 100644 --- a/libgcc/gthr-posix.h +++ b/libgcc/gthr-posix.h @@ -74,6 +74,20 @@ typedef struct timespec __gthread_time_t; #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER #define __GTHREAD_TIME_INIT {0,0} +#ifdef _GTHREAD_USE_MUTEX_INIT_FUNC +# undef __GTHREAD_MUTEX_INIT +# define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function +#endif +#ifdef _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC +# undef __GTHREAD_RECURSIVE_MUTEX_INIT +# undef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION +# define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function +#endif +#ifdef _GTHREAD_USE_COND_INIT_FUNC +# undef __GTHREAD_COND_INIT +# define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function +#endif + #if SUPPORTS_WEAK && GTHREAD_USE_WEAK # ifndef __gthrw_pragma # define __gthrw_pragma(pragma) @@ -730,6 +744,15 @@ __gthread_setspecific (__gthread_key_t __key, const void *__ptr) return __gthrw_(pthread_setspecific) (__key, __ptr); } +#ifdef _GTHREAD_USE_MUTEX_INIT_FUNC +static inline void +__gthread_mutex_init_function (__gthread_mutex_t *__mutex) +{ + if (__gthread_active_p ()) + __gthrw_(pthread_mutex_init) (__mutex, NULL); +} +#endif + static inline int __gthread_mutex_destroy (__gthread_mutex_t *__mutex) { @@ -778,7 +801,8 @@ __gthread_mutex_unlock (__gthread_mutex_t *__mutex) return 0; } -#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \ + || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC) static inline int __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) { @@ -828,6 +852,15 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return __gthread_mutex_unlock (__mutex); } +#ifdef _GTHREAD_USE_COND_INIT_FUNC +static inline void +__gthread_cond_init_function (__gthread_cond_t *__cond) +{ + if (__gthread_active_p ()) + __gthrw_(pthread_cond_init) (__cond, NULL); +} +#endif + static inline int __gthread_cond_broadcast (__gthread_cond_t *__cond) { diff --git a/libstdc++-v3/config/os/bsd/darwin/os_defines.h b/libstdc++-v3/config/os/bsd/darwin/os_defines.h index ccefeaf..421478d 100644 --- a/libstdc++-v3/config/os/bsd/darwin/os_defines.h +++ b/libstdc++-v3/config/os/bsd/darwin/os_defines.h @@ -39,4 +39,7 @@ // -flat_namespace to work around the way that it doesn't. #define _GLIBCXX_WEAK_DEFINITION __attribute__ ((weak)) +// Static initializer macro is buggy in darwin, see libstdc++/51906 +#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC + #endif