[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #26 from asharif at gcc dot gnu.org 2012-12-06 20:09:35 UTC --- Author: asharif Date: Thu Dec 6 20:09:25 2012 New Revision: 194264 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=194264 Log: 2012-12-03 Ahmad Sharif asha...@google.com Backport r185231 from trunk. 2012-03-12 Richard Guenther rguent...@suse.de * gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification. * gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. (__gthread_mutex_init_function): New function. * gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. PR gcov/49484 * libgcov.c: Include gthr.h. (__gcov_flush_mx): New global variable. (init_mx, init_mx_once): New functions. (__gcov_flush): Protect self with a mutex. (__gcov_fork): Re-initialize mutex after forking. * unwind-dw2-fde.c: Change condition under which to use __GTHREAD_MUTEX_INIT_FUNCTION. Modified: branches/google/gcc-4_7/ (props changed) branches/google/gcc-4_7/gcc/ (props changed) branches/google/gcc-4_7/gcc/testsuite/gcc.target/powerpc/ppc-round.c (props changed) branches/google/gcc-4_7/libgcc/ChangeLog branches/google/gcc-4_7/libgcc/ChangeLog.google-4_7 branches/google/gcc-4_7/libgcc/gthr-posix.h branches/google/gcc-4_7/libgcc/gthr-single.h branches/google/gcc-4_7/libgcc/gthr.h branches/google/gcc-4_7/libgcc/libgcov.c branches/google/gcc-4_7/libgcc/unwind-dw2-fde.c branches/google/gcc-4_7/libjava/classpath/ (props changed) Propchange: branches/google/gcc-4_7/ ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7/gcc/ ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7/gcc/testsuite/gcc.target/powerpc/ppc-round.c ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7/libjava/classpath/ ('svn:mergeinfo' modified)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #27 from asharif at gcc dot gnu.org 2012-12-07 02:35:42 UTC --- Author: asharif Date: Fri Dec 7 02:35:37 2012 New Revision: 194279 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=194279 Log: 2012-12-03 Ahmad Sharif asha...@google.com Backport r185231 from trunk. 2012-03-12 Richard Guenther rguent...@suse.de * gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification. * gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. (__gthread_mutex_init_function): New function. * gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. PR gcov/49484 * libgcov.c: Include gthr.h. (__gcov_flush_mx): New global variable. (init_mx, init_mx_once): New functions. (__gcov_flush): Protect self with a mutex. (__gcov_fork): Re-initialize mutex after forking. * unwind-dw2-fde.c: Change condition under which to use __GTHREAD_MUTEX_INIT_FUNCTION. Modified: branches/google/gcc-4_7-mobile/ (props changed) branches/google/gcc-4_7-mobile/gcc/ (props changed) branches/google/gcc-4_7-mobile/gcc/testsuite/gcc.target/powerpc/ppc-round.c (props changed) branches/google/gcc-4_7-mobile/libgcc/ChangeLog.google-4_7 branches/google/gcc-4_7-mobile/libgcc/gthr-posix.h branches/google/gcc-4_7-mobile/libgcc/gthr-single.h branches/google/gcc-4_7-mobile/libgcc/gthr.h branches/google/gcc-4_7-mobile/libgcc/libgcov.c branches/google/gcc-4_7-mobile/libgcc/unwind-dw2-fde.c branches/google/gcc-4_7-mobile/libjava/classpath/ (props changed) Propchange: branches/google/gcc-4_7-mobile/ ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7-mobile/gcc/ ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7-mobile/gcc/testsuite/gcc.target/powerpc/ppc-round.c ('svn:mergeinfo' modified) Propchange: branches/google/gcc-4_7-mobile/libjava/classpath/ ('svn:mergeinfo' modified)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #25 from asharif at gcc dot gnu.org 2012-05-02 22:52:36 UTC --- Author: asharif Date: Wed May 2 22:52:28 2012 New Revision: 187067 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=187067 Log: Backported r187026 from branches/google/gcc-4_6. 2012-03-12 Richard Guenther rguent...@suse.de * gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification. * gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. (__gthread_mutex_init_function): New function. * gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. PR gcov/49484 * libgcov.c: Include gthr.h. (__gcov_flush_mx): New global variable. (init_mx, init_mx_once): New functions. (__gcov_flush): Protect self with a mutex. (__gcov_fork): Re-initialize mutex after forking. * unwind-dw2-fde.c: Change condition under which to use __GTHREAD_MUTEX_INIT_FUNCTION. Modified: branches/google/gcc-4_6_3-mobile/ (props changed) branches/google/gcc-4_6_3-mobile/gcc/ChangeLog.google-4_6 branches/google/gcc-4_6_3-mobile/gcc/gthr-posix.h branches/google/gcc-4_6_3-mobile/gcc/gthr-single.h branches/google/gcc-4_6_3-mobile/gcc/gthr.h branches/google/gcc-4_6_3-mobile/gcc/libgcov.c branches/google/gcc-4_6_3-mobile/gcc/unwind-dw2-fde.c branches/google/gcc-4_6_3-mobile/libgcc/ChangeLog branches/google/gcc-4_6_3-mobile/libgcc/ChangeLog.google-4_6 Propchange: branches/google/gcc-4_6_3-mobile/ ('svn:mergeinfo' modified)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #24 from asharif at gcc dot gnu.org 2012-05-01 21:22:51 UTC --- Author: asharif Date: Tue May 1 21:22:47 2012 New Revision: 187026 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=187026 Log: Backported r185231 from trunk. 2012-03-12 Richard Guenther rguent...@suse.de * gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification. * gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. (__gthread_mutex_init_function): New function. * gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. PR gcov/49484 * libgcov.c: Include gthr.h. (__gcov_flush_mx): New global variable. (init_mx, init_mx_once): New functions. (__gcov_flush): Protect self with a mutex. (__gcov_fork): Re-initialize mutex after forking. * unwind-dw2-fde.c: Change condition under which to use __GTHREAD_MUTEX_INIT_FUNCTION. Modified: branches/google/gcc-4_6/ (props changed) branches/google/gcc-4_6/gcc/ChangeLog.google-4_6 branches/google/gcc-4_6/gcc/gthr-posix.h branches/google/gcc-4_6/gcc/gthr-single.h branches/google/gcc-4_6/gcc/gthr.h branches/google/gcc-4_6/gcc/libgcov.c branches/google/gcc-4_6/gcc/unwind-dw2-fde.c branches/google/gcc-4_6/libgcc/ChangeLog Propchange: branches/google/gcc-4_6/ ('svn:mergeinfo' modified)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #14 from Richard Guenther rguenth at gcc dot gnu.org 2012-03-12 14:23:32 UTC --- Author: rguenth Date: Mon Mar 12 14:23:27 2012 New Revision: 185231 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=185231 Log: 2012-03-12 Richard Guenther rguent...@suse.de * gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification. * gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. (__gthread_mutex_init_function): New function. * gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define. PR gcov/49484 * libgcov.c: Include gthr.h. (__gcov_flush_mx): New global variable. (init_mx, init_mx_once): New functions. (__gcov_flush): Protect self with a mutex. (__gcov_fork): Re-initialize mutex after forking. * unwind-dw2-fde.c: Change condition under which to use __GTHREAD_MUTEX_INIT_FUNCTION. Modified: trunk/libgcc/ChangeLog trunk/libgcc/gthr-posix.h trunk/libgcc/gthr-single.h trunk/libgcc/gthr.h trunk/libgcc/libgcov.c trunk/libgcc/unwind-dw2-fde.c
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 Richard Guenther rguenth at gcc dot gnu.org changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution||FIXED Target Milestone|--- |4.8.0 --- Comment #15 from Richard Guenther rguenth at gcc dot gnu.org 2012-03-12 14:25:08 UTC --- Fixed for GCC 4.8.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #16 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:00:46 UTC --- If a target defines _GTHREAD_USE_MUTEX_INIT_FUNC in lisbtdc++-v3/config/os/.../os_defines.h then following this patch line 80 in gthr-posix.h will redefine __GTHREAD_MUTEX_INIT_FUNCTION and there will be two conflicting definitions of __gthread_mutex_init_function on lines 749 and 757
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #17 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:06:52 UTC --- (In reply to comment #16) If a target defines _GTHREAD_USE_MUTEX_INIT_FUNC in e.g. this will break Tru64 (until Rainer removes support for it) http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/config/os/osf/os_defines.h?view=markuppathrev=184108
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #18 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:10:29 UTC --- Also, gthr.h says the signature should be: void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #19 from Richard Guenther rguenth at gcc dot gnu.org 2012-03-12 15:27:46 UTC --- (In reply to comment #18) Also, gthr.h says the signature should be: void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) I don't understand this? The current define is pre-existing #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC # undef __GTHREAD_MUTEX_INIT # define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function #endif I suppose it simply forgets to undef __GTHREAD_MUTEX_INIT_FUNCTION like the _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC does. I have no access to the weird platforms (but asked for help three month ago and again a week ago). Please open new bugs for issues you spot. Btw, the gthr-posix.h path with _GTHREAD_USE_MUTEX_INIT_FUNC could have never worked as there was no __gthread_mutex_init_function available in gthr-posix.h. Or how was that supposed to work?
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #20 from Richard Guenther rguenth at gcc dot gnu.org 2012-03-12 15:52:34 UTC --- I suppose Index: libgcc/gthr-posix.h === --- libgcc/gthr-posix.h (revision 185232) +++ libgcc/gthr-posix.h (working copy) @@ -77,7 +77,6 @@ typedef struct timespec __gthread_time_t #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 would fix it?
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #21 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:54:46 UTC --- (In reply to comment #19) (In reply to comment #18) Also, gthr.h says the signature should be: void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) I don't understand this? The current define is pre-existing #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC # undef __GTHREAD_MUTEX_INIT # define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function #endif I suppose it simply forgets to undef __GTHREAD_MUTEX_INIT_FUNCTION like the _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC does. No, that was intentional. Before your commit gthr-posix.h never defined __GTHREAD_MUTEX_INIT_FUNCTION (because all POSIX targets define PTHREAD_MUTEX_INITIALIZER) so there was no need to undef it. However, gthr-posix.h sometimes defines __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION (because not all POSIX targets provide PTHREAD_RECURSIVE_MUTEX_INITIALIZER) so I needed to undef it before (re-)defining it. I could have alternatively done: #ifndef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION ... #endif But I chose to just #undef it then #define it. I have no access to the weird platforms (but asked for help three month ago and again a week ago). Yes, sorry, I don't subscribe to gcc-patches so only saw it when the change was committed. Please open new bugs for issues you spot. OK, will do. Btw, the gthr-posix.h path with _GTHREAD_USE_MUTEX_INIT_FUNC could have never worked as there was no __gthread_mutex_init_function available in gthr-posix.h. Or how was that supposed to work? I added __gthread_mutex_init_function, that's why it's there twice now. Your patch added another copy of it right below mine! But my change was only made a month ago: http://gcc.gnu.org/viewcvs?root=gccview=revrev=183955 So when you first prepared your patch it was correct. Now it's not.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #22 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:56:07 UTC --- (In reply to comment #20) I suppose Index: libgcc/gthr-posix.h === --- libgcc/gthr-posix.h (revision 185232) +++ libgcc/gthr-posix.h (working copy) @@ -77,7 +77,6 @@ typedef struct timespec __gthread_time_t #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 would fix it? That fixes half the problem, then there's still the duplicate __gthread_mutex_init_function on line 749. That should be defined unconditionally, but according to the spec in gthr.h should return void
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #23 from rguenther at suse dot de rguenther at suse dot de 2012-03-12 16:02:34 UTC --- On Mon, 12 Mar 2012, redi at gcc dot gnu.org wrote: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #22 from Jonathan Wakely redi at gcc dot gnu.org 2012-03-12 15:56:07 UTC --- (In reply to comment #20) I suppose Index: libgcc/gthr-posix.h === --- libgcc/gthr-posix.h (revision 185232) +++ libgcc/gthr-posix.h (working copy) @@ -77,7 +77,6 @@ typedef struct timespec __gthread_time_t #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 would fix it? That fixes half the problem, then there's still the duplicate __gthread_mutex_init_function on line 749. That should be defined unconditionally, but according to the spec in gthr.h should return void Darn... I'm preparing a patch for testing overnight (if you beat me to it, the obvious patch is pre-approved, removing my copy of __gthread_mutex_init_function and making yours defined unconditionally). Richard.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #8 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-18 10:38:15 UTC --- (In reply to comment #5) It doesn't really help - there are more races. The following does seem to help though, but is certainly not applicable. Index: gcc/libgcov.c === --- gcc/libgcov.c (revision 183243) +++ gcc/libgcov.c (working copy) @@ -77,6 +77,7 @@ void __gcov_merge_delta (gcov_type *coun #include errno.h #include sys/stat.h #endif +#include pthread.h #ifdef L_gcov #include gcov-io.c @@ -584,7 +585,9 @@ void __gcov_flush (void) { const struct gcov_info *gi_ptr; + static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock (mx); gcov_exit (); for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr-next) { @@ -598,6 +601,7 @@ __gcov_flush (void) ci_ptr++; } } + pthread_mutex_unlock (mx); } #endif /* L_gcov */ Would be applicable when we compile a second libgcov_r which we'd use when linking with -pthread.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #9 from Jakub Jelinek jakub at gcc dot gnu.org 2012-01-18 10:57:07 UTC --- Why? Just use gthr.h stuff...
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #10 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-18 11:49:58 UTC --- Created attachment 26363 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=26363 draft patch Draft patch that doesn't work because we do not unconditionally provide __GTHREAD_MUTEX_INIT_FUNCTION.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 Richard Guenther rguenth at gcc dot gnu.org changed: What|Removed |Added Status|NEW |ASSIGNED AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org |gnu.org |
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 Richard Guenther rguenth at gcc dot gnu.org changed: What|Removed |Added Attachment #26363|0 |1 is obsolete|| --- Comment #11 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-18 13:26:01 UTC --- Created attachment 26364 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=26364 more complete patch Changes __GTHREAD_MUTEX_INIT_FUNCTION to be unconditionally available (but not for all configs). Still shows an issue when __GTHREAD_MUTEX_INIT is not available in the fork () path. While we can re-init the mutex there with __GTHREAD_MUTEX_INIT_FUNCTION, the non-__GTHREAD_MUTEX_INIT path will later use a broken once in init_mx_once (and of course initialize it again). Unless it is somehow guaranteed that already triggered gthread-once things will work fine after forking. Otherwise seems to work fine on x86_64-linux sofar.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #12 from Jakub Jelinek jakub at gcc dot gnu.org 2012-01-18 13:35:28 UTC --- Well, pthread_once can't be called in fork child if fork has been done from multi-threaded process (similarly to most other calls).
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #13 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-18 15:41:02 UTC --- Hmm, and as libgcov is static we can end up with multiple copies in shared libraries which means multiple mutexes and thus exposal to the fcntl file-locking ineffectiveness (in this case the library must fork, of course). At least we should not see crashes even in this case because we properly protect the non-shared __gcov_var.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 Richard Guenther rguenth at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2012-01-17 Ever Confirmed|0 |1 --- Comment #4 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-17 13:50:49 UTC --- Confirmed with the testcase in the RH bugzilla. I'm not sure why the issue does not reproduce with GCC 4.4 and up (I can't see changes in libgcov). But I can fix the issue by making the fcntl file locking effective for threads with Index: gcc/gcov-io.c === --- gcc/gcov-io.c (revision 183243) +++ gcc/gcov-io.c (working copy) @@ -32,6 +32,10 @@ static const gcov_unsigned_t *gcov_read_ static void gcov_allocate (unsigned); #endif +#if GCOV_LOCKED +#include sys/syscall.h +#endif + static inline gcov_unsigned_t from_file (gcov_unsigned_t value) { #if !IN_LIBGCOV @@ -70,9 +74,13 @@ gcov_open (const char *name, int mode) s_flock.l_whence = SEEK_SET; s_flock.l_start = 0; s_flock.l_len = 0; /* Until EOF. */ +#ifdef SYS_gettid + s_flock.l_pid = syscall(SYS_gettid); +#else s_flock.l_pid = getpid (); #endif - +#endif + gcc_assert (!gcov_var.file); gcov_var.start = 0; gcov_var.offset = gcov_var.length = 0;
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #5 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-17 14:39:47 UTC --- It doesn't really help - there are more races. The following does seem to help though, but is certainly not applicable. Index: gcc/libgcov.c === --- gcc/libgcov.c (revision 183243) +++ gcc/libgcov.c (working copy) @@ -77,6 +77,7 @@ void __gcov_merge_delta (gcov_type *coun #include errno.h #include sys/stat.h #endif +#include pthread.h #ifdef L_gcov #include gcov-io.c @@ -584,7 +585,9 @@ void __gcov_flush (void) { const struct gcov_info *gi_ptr; + static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock (mx); gcov_exit (); for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr-next) { @@ -598,6 +601,7 @@ __gcov_flush (void) ci_ptr++; } } + pthread_mutex_unlock (mx); } #endif /* L_gcov */
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #6 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-17 15:20:42 UTC --- Making __gcov_var TLS also works, with similar restrictions. Thus completely privatizing the state and allocating/deallocating it via gcov_open/close seems to be a proper re-working of libgcov.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #7 from Richard Guenther rguenth at gcc dot gnu.org 2012-01-17 15:39:19 UTC --- strace showing that file-locking, even with using gettid doesn't work: 16980 gettid( unfinished ... 16981 gettid() = 16981 16981 open(/tmp/t.gcda, O_RDWR|O_CREAT, 0666) = 3 16981 fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0 16981 fcntl(3, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE) 16981 close(3) = 0 16980 ... gettid resumed )= 16980 16980 open(/tmp/t.gcda, O_RDWR|O_CREAT, 0666) = 3 16980 fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0 16980 fcntl(3, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE) 16982 gettid() = 16982 16982 open(/tmp/t.gcda, O_RDWR|O_CREAT, 0666) = 3 16982 fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0} unfinished ... 16983 gettid() = 16983 16983 --- SIGABRT (Aborted) @ 0 (0) --- 16982 ... fcntl resumed ) = 0 16979 +++ killed by SIGABRT (core dumped) +++ 16982 fcntl(3, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE) 16982 close(3) = 0 it seems that the first close of fd 3 makes all further locks (even to different l_pid) noops. I suppose l_pid is simply ignored ofr F_SETLK[W] and the current PID is used. That makes the file-locking in libgcov non-thread-safe.
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 vijay vijay910 at gmail dot com changed: What|Removed |Added CC||vijay910 at gmail dot com --- Comment #3 from vijay vijay910 at gmail dot com 2011-10-07 12:12:49 UTC --- Have the same issue on sles 10 machine Back trace: #0 0x2b835b95 in raise () from /lib64/libc.so.6 #1 0x2b836f90 in abort () from /lib64/libc.so.6 #2 0x2b86c35b in __libc_message () from /lib64/libc.so.6 #3 0x2b87134e in malloc_printerr () from /lib64/libc.so.6 #4 0x2b87295c in free () from /lib64/libc.so.6 #5 0x2b862942 in fclose@@GLIBC_2.2.5 () from /lib64/libc.so.6 #6 0x0048e644 in __gcov_close () #7 0x0048eb35 in gcov_exit () #8 0x0048f48f in __gcov_flush () #9 0x0048f529 in __gcov_fork () gcc version 4.1.2 20070115 (prerelease) (SUSE Linux)
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #2 from cobexer at gmail dot com 2011-06-24 09:33:42 UTC --- I could not reproduce the crash using gcc 4.6. So I reported this to Red Hat: https://bugzilla.redhat.com/show_bug.cgi?id=716390
[Bug gcov-profile/49484] gcov crash if two(or more) forks happen at the same time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49484 --- Comment #1 from Mikael Pettersson mikpe at it dot uu.se 2011-06-21 09:24:20 UTC --- gcc-4.1.2 is no longer supported upstream. Please try again with gcc-4.3.5 or newer, preferably gcc-4.6.0 or 4.5.3. Or report this to Red Hat who delivered your 4.1.2-based compiler.