From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24782 invoked by alias); 5 Mar 2012 12:17:52 -0000 Received: (qmail 24768 invoked by uid 22791); 5 Mar 2012 12:17:46 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Mar 2012 12:17:31 +0000 Received: by iaag37 with SMTP id g37so5584326iaa.20 for ; Mon, 05 Mar 2012 04:17:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.181.169 with SMTP id dx9mr5174628igc.62.1330949850474; Mon, 05 Mar 2012 04:17:30 -0800 (PST) Received: by 10.42.222.194 with HTTP; Mon, 5 Mar 2012 04:17:30 -0800 (PST) In-Reply-To: References: Date: Mon, 05 Mar 2012 12:17:00 -0000 Message-ID: Subject: Re: [PATCH] Fix PR49484, gthr requirements update (target maintainers have a looksee) From: Richard Guenther To: Richard Guenther Cc: gcc-patches@gcc.gnu.org, Ian Lance Taylor Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg00271.txt.bz2 On Wed, Jan 18, 2012 at 3:21 PM, Richard Guenther wrote: > > This fixes PR49484 by protecting __gcov_flush against concurrent > execution. =A0To be able to use the gthread facility I have to > introduce the requirement that __GTHREAD_MUTEX_INIT_FUNCTION > is always available, even if __GTHREAD_MUTEX_INIT is available as > otherwise no dynamic initialization of a mutex is possible. > I have adjusted gthr-posix.h and gthr-single.h only - target > maintainers, please update your ports accordingly in advance. > > Boostrap and regtest on x86_64-unknown-linux-gnu is ongoing, > but this looks like something for stage1 anyway. Bootstrap and regtest finished ok. I am going to commit this without "fixi= ng" eventually broken targets that I know nothing of. See above. Unless I hear objections until tomorrow. Thanks, Richard. > Richard. > > 2012-01-18 =A0Richard Guenther =A0 > > =A0 =A0 =A0 =A0* gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specifica= tion. > =A0 =A0 =A0 =A0* gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. > =A0 =A0 =A0 =A0(__gthread_mutex_init_function): New function. > =A0 =A0 =A0 =A0* gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. > > =A0 =A0 =A0 =A0PR gcov/49484 > =A0 =A0 =A0 =A0* libgcov.c: Include gthr.h. > =A0 =A0 =A0 =A0(__gcov_flush_mx): New global variable. > =A0 =A0 =A0 =A0(init_mx, init_mx_once): New functions. > =A0 =A0 =A0 =A0(__gcov_flush): Protect self with a mutex. > =A0 =A0 =A0 =A0(__gcov_fork): Re-initialize mutex after forking. > =A0 =A0 =A0 =A0* unwind-dw2-fde.c: Change condition under which to use > =A0 =A0 =A0 =A0__GTHREAD_MUTEX_INIT_FUNCTION. > > Index: libgcc/libgcov.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > *** libgcc/libgcov.c =A0 =A0(revision 183270) > --- libgcc/libgcov.c =A0 =A0(working copy) > *************** see the files COPYING3 and COPYING.RUNTI > *** 30,35 **** > --- 30,36 ---- > =A0#include "coretypes.h" > =A0#include "tm.h" > =A0#include "libgcc_tm.h" > + #include "gthr.h" > > =A0#if defined(inhibit_libc) > =A0#define IN_LIBGCOV (-1) > *************** __gcov_init (struct gcov_info *info) > *** 705,710 **** > --- 706,730 ---- > =A0 =A0info->version =3D 0; > =A0} > > + #ifdef __GTHREAD_MUTEX_INIT > + ATTRIBUTE_HIDDEN __gthread_mutex_t __gcov_flush_mx =3D __GTHREAD_MUTEX_= INIT; > + #define init_mx_once() > + #else > + __gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN; > + > + static void > + init_mx (void) > + { > + =A0 __GTHREAD_MUTEX_INIT_FUNCTION (&mx); > + } > + static void > + init_mx_once (void) > + { > + =A0 static __gthread_once_t once =3D __GTHREAD_ONCE_INIT; > + =A0 __gthread_once (&once, init_mx); > + } > + #endif > + > =A0/* Called before fork or exec - write out profile information gathered= so > =A0 =A0 far and reset it to zero. =A0This avoids duplication or loss of t= he > =A0 =A0 profile information gathered so far. =A0*/ > *************** __gcov_flush (void) > *** 714,719 **** > --- 734,742 ---- > =A0{ > =A0 =A0const struct gcov_info *gi_ptr; > > + =A0 init_mx_once (); > + =A0 __gthread_mutex_lock (&__gcov_flush_mx); > + > =A0 =A0gcov_exit (); > =A0 =A0for (gi_ptr =3D gcov_list; gi_ptr; gi_ptr =3D gi_ptr->next) > =A0 =A0 =A0{ > *************** __gcov_flush (void) > *** 737,742 **** > --- 760,767 ---- > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0} > =A0 =A0 =A0} > + > + =A0 __gthread_mutex_unlock (&__gcov_flush_mx); > =A0} > > =A0#endif /* L_gcov */ > *************** __gcov_ior_profiler (gcov_type *counters > *** 975,982 **** > =A0pid_t > =A0__gcov_fork (void) > =A0{ > =A0 =A0__gcov_flush (); > ! =A0 return fork (); > =A0} > =A0#endif > > --- 1000,1012 ---- > =A0pid_t > =A0__gcov_fork (void) > =A0{ > + =A0 pid_t pid; > + =A0 extern __gthread_mutex_t __gcov_flush_mx; > =A0 =A0__gcov_flush (); > ! =A0 pid =3D fork (); > ! =A0 if (pid =3D=3D 0) > ! =A0 =A0 __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx); > ! =A0 return pid; > =A0} > =A0#endif > > Index: libgcc/unwind-dw2-fde.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > *** libgcc/unwind-dw2-fde.c =A0 =A0 (revision 183270) > --- libgcc/unwind-dw2-fde.c =A0 =A0 (working copy) > *************** static struct object *seen_objects; > *** 47,57 **** > > =A0#ifdef __GTHREAD_MUTEX_INIT > =A0static __gthread_mutex_t object_mutex =3D __GTHREAD_MUTEX_INIT; > =A0#else > =A0static __gthread_mutex_t object_mutex; > - #endif > > - #ifdef __GTHREAD_MUTEX_INIT_FUNCTION > =A0static void > =A0init_object_mutex (void) > =A0{ > --- 47,56 ---- > > =A0#ifdef __GTHREAD_MUTEX_INIT > =A0static __gthread_mutex_t object_mutex =3D __GTHREAD_MUTEX_INIT; > + #define init_object_mutex_once() > =A0#else > =A0static __gthread_mutex_t object_mutex; > > =A0static void > =A0init_object_mutex (void) > =A0{ > *************** init_object_mutex_once (void) > *** 64,71 **** > =A0 =A0static __gthread_once_t once =3D __GTHREAD_ONCE_INIT; > =A0 =A0__gthread_once (&once, init_object_mutex); > =A0} > - #else > - #define init_object_mutex_once() > =A0#endif > > =A0/* Called from crtbegin.o to register the unwind info for an object. = =A0*/ > --- 63,68 ---- > Index: libgcc/gthr-posix.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > *** libgcc/gthr-posix.h (revision 183270) > --- libgcc/gthr-posix.h (working copy) > *************** typedef struct timespec __gthread_time_t > *** 63,68 **** > --- 63,69 ---- > =A0#define __GTHREAD_HAS_COND =A0 =A01 > > =A0#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER > + #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function > =A0#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT > =A0#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) > =A0#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIAL= IZER > *************** __gthread_setspecific (__gthread_key_t _ > *** 731,736 **** > --- 732,745 ---- > =A0} > > =A0static inline int > + __gthread_mutex_init_function (__gthread_mutex_t *__mutex) > + { > + =A0 if (__gthread_active_p ()) > + =A0 =A0 return __gthrw_(pthread_mutex_init) (__mutex, NULL); > + =A0 return 0; > + } > + > + static inline int > =A0__gthread_mutex_destroy (__gthread_mutex_t *__mutex) > =A0{ > =A0 =A0if (__gthread_active_p ()) > Index: libgcc/gthr-single.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > *** libgcc/gthr-single.h =A0 =A0 =A0 =A0(revision 183270) > --- libgcc/gthr-single.h =A0 =A0 =A0 =A0(working copy) > *************** typedef int __gthread_recursive_mutex_t; > *** 36,41 **** > --- 36,42 ---- > > =A0#define __GTHREAD_ONCE_INIT 0 > =A0#define __GTHREAD_MUTEX_INIT 0 > + #define __GTHREAD_MUTEX_INIT_FUNCTION (mx) > =A0#define __GTHREAD_RECURSIVE_MUTEX_INIT 0 > > =A0#define UNUSED __attribute__((unused)) > Index: libgcc/gthr.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- libgcc/gthr.h =A0 =A0 =A0 (revision 183270) > +++ libgcc/gthr.h =A0 =A0 =A0 (working copy) > @@ -52,11 +52,12 @@ see the files COPYING3 and COPYING.RUNTI > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0to initialize __gthread_mutex_t to get a f= ast > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0non-recursive mutex. > =A0 =A0 =A0__GTHREAD_MUTEX_INIT_FUNCTION > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 some systems can't initialize a mutex witho= ut a > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 function call. =A0On such systems, define t= his to a > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 function which looks like this: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 to initialize __gthread_mutex_t to get a fa= st > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 non-recursive mutex. > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 Define this to a function which looks like = this: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0void __GTHREAD_MUTEX_INIT_FUNCTION (__= gthread_mutex_t *) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 Don't define __GTHREAD_MUTEX_INIT in this c= ase > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 Some systems can't initialize a mutex witho= ut a > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 function call. =A0Don't define __GTHREAD_MU= TEX_INIT in this case. > =A0 =A0 =A0__GTHREAD_RECURSIVE_MUTEX_INIT > =A0 =A0 =A0__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0as above, but for a recursive mutex.