There is a typo in helgrind's wrapper function for pthread_spin_destroy. It is written as "pthreadZuspinZusdestroy" (note the extra 's' before destroy) in hg_intercepts.c. I was encountering very strange errors with helgrind complaining that pthread_rwlock_XYZ calls are using pthread_mutex arguments. I've tracked it down to the fact that evh__hg_PTHREAD_SPIN_DESTROY_PRE is never invoked to clean up the lock mapping. Eventually, a pthread_rwlock would be allocated to the same memory address and the error would occur. Reproducible: Always Steps to Reproduce: 1. pthread_spin_init at memory address X 2. pthread_spin_destroy at memory address X 3. pthread_rwlock_init at same memory address X 4. pthread_rwlock_destroy at memory address X Actual Results: Error message: "pthread_rwlock_{rd,rw}lock with a pthread_mutex_t* argument" if pthread_rwlock_*lock invoked "pthread_rwlock_destroy with invalid argument" and assert failure if pthread_rwlock_destroy invoked Expected Results: Life is good -- no error, no crash --- valgrind-3.11.0/helgrind/hg_intercepts.old 2016-01-11 16:57:00.912000000 -0500 +++ valgrind-3.11.0/helgrind/hg_intercepts.c 2016-01-11 16:57:19.519000000 -0500 @@ -1854,13 +1854,13 @@ return ret; } #if defined(VGO_linux) - PTH_FUNC(int, pthreadZuspinZusdestroy, // pthread_spin_destroy + PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy pthread_spinlock_t *lock) { return pthread_spin_destroy_WRK(lock); } #elif defined(VGO_darwin) #elif defined(VGO_solaris) - PTH_FUNC(int, pthreadZuspinZusdestroy, // pthread_spin_destroy + PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy pthread_spinlock_t *lock) { return pthread_spin_destroy_WRK(lock); }
Thank you reporting this bug. Good catch! Would you be able to provide a small test case which can showcase this (currently wrong) behaviour?
Created attachment 96601 [details] Reproducer
==5502== Helgrind, a thread error detector ==5502== Copyright (C) 2007-2015, and GNU GPL'd, by OpenWorks LLP et al. ==5502== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==5502== Command: ./a.out ==5502== ==5502== ---Thread-Announcement------------------------------------------ ==5502== ==5502== Thread #1 is the program's root thread ==5502== ==5502== ---------------------------------------------------------------- ==5502== ==5502== Thread #1: pthread_rwlock_destroy with invalid argument ==5502== at 0x4C2E40E: ??? (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so) ==5502== by 0x4C31146: pthread_rwlock_destroy (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so) ==5502== by 0x40077E: main (in /home/jdillaman/a.out) ==5502== ==5502== ==5502== For counts of detected and suppressed errors, rerun with: -v ==5502== Use --history-level=approx or =none to gain increased speed, at ==5502== the cost of reduced accuracy of conflicting-access information ==5502== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Fixed in SVN r15756.
Thank you for the patch and provided test case. I.