Bug 357871 - pthread_spin_destroy not properly wrapped
Summary: pthread_spin_destroy not properly wrapped
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: helgrind (show other bugs)
Version: unspecified
Platform: Fedora RPMs Linux
: NOR crash
Target Milestone: ---
Assignee: Ivo Raisr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-11 22:17 UTC by Jason Dillaman
Modified: 2016-01-28 12:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Reproducer (340 bytes, text/x-csrc)
2016-01-12 14:11 UTC, Jason Dillaman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Dillaman 2016-01-11 22:17:01 UTC
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);
    }
Comment 1 Ivo Raisr 2016-01-12 03:04:04 UTC
Thank you reporting this bug. Good catch!
Would you be able to provide a small test case which can showcase this (currently wrong) behaviour?
Comment 2 Jason Dillaman 2016-01-12 14:11:46 UTC
Created attachment 96601 [details]
Reproducer
Comment 3 Jason Dillaman 2016-01-12 14:12:21 UTC
==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)
Comment 4 Ivo Raisr 2016-01-12 20:31:39 UTC
Fixed in SVN r15756.
Comment 5 Ivo Raisr 2016-01-12 20:35:11 UTC
Thank you for the patch and provided test case.
I.