From 6ffb70e650ee7cf4ada829557dd30ababb09e078 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Thu, 29 Dec 2022 22:00:53 +0100 Subject: [PATCH] =?utf8?q?Bug=C2=A0400793=20-=20pthread=5Frwlock=5Ftimedwr?= =?utf8?q?lock=20false=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add Helgrind intercepts for pthread_rwlock_timedwrlock (and pthread_rwlock_timedrdlock) Reuse the DRD trylock test --- NEWS | 1 + helgrind/hg_intercepts.c | 18 ++++++++++++------ helgrind/tests/Makefile.am | 3 ++- helgrind/tests/trylock.stderr.exp | 13 +++++++++++++ helgrind/tests/trylock.vgtest | 1 + 5 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 helgrind/tests/trylock.stderr.exp create mode 100644 helgrind/tests/trylock.vgtest diff --git a/NEWS b/NEWS index 071f654b50..16ae313dfc 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 170510 Don't warn about ioctl of size 0 without direction hint 351857 confusing error message about valid command line option 392331 Spurious lock not held error from inside pthread_cond_timedwait +400793 pthread_rwlock_timedwrlock false positive 444110 priv/guest_ppc_toIR.c:36198:31: warning: duplicated 'if' condition. 444488 Use glibc.pthread.stack_cache_size tunable 444568 drd/tests/pth_barrier_thr_cr fails on Fedora 38 diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c index 0d29cb3bfa..5a83996e36 100644 --- a/helgrind/hg_intercepts.c +++ b/helgrind/hg_intercepts.c @@ -2222,9 +2222,6 @@ static int pthread_spin_trylock_WRK(pthread_spinlock_t *lock) pthread_rwlock_unlock pthread_rwlock_tryrdlock pthread_rwlock_trywrlock - - Unhandled: pthread_rwlock_timedrdlock - pthread_rwlock_timedwrlock */ //----------------------------------------------------------- @@ -2676,7 +2673,7 @@ static int pthread_rwlock_tryrdlock_WRK(pthread_rwlock_t* rwlock) //----------------------------------------------------------- -// glibc: Unhandled +// glibc: pthread_rwlock_timedrdlock // darwin: Unhandled // Solaris: pthread_rwlock_timedrdlock // Solaris: pthread_rwlock_reltimedrdlock_np @@ -2712,6 +2709,11 @@ static int pthread_rwlock_timedrdlock_WRK(pthread_rwlock_t *rwlock, return ret; } #if defined(VGO_linux) +PTH_FUNC(int, pthreadZurwlockZutimedrdlock, // pthread_rwlock_timedrdlock + pthread_rwlock_t *rwlock, + const struct timespec *timeout) { + return pthread_rwlock_timedrdlock_WRK(rwlock, timeout); +} #elif defined(VGO_darwin) #elif defined(VGO_freebsd) PTH_FUNC(int, pthreadZurwlockZutimedrdlock, // pthread_rwlock_timedrdlock @@ -2779,8 +2781,7 @@ PTH_FUNC(int, pthreadZurwlockZuclockrdlock, // pthread_rwlock_clockrdlock //----------------------------------------------------------- -// glibc: Unhandled -// darwin: Unhandled +// glibc: pthread_rwlock_timedwrlock // Solaris: pthread_rwlock_timedwrlock // Solaris: pthread_rwlock_reltimedwrlock_np // FreeBSD: pthread_rwlock_timedwrlock @@ -2815,6 +2816,11 @@ static int pthread_rwlock_timedwrlock_WRK(pthread_rwlock_t *rwlock, return ret; } #if defined(VGO_linux) +PTH_FUNC(int, pthreadZurwlockZutimedwrlock, // pthread_rwlock_timedwrlock + pthread_rwlock_t *rwlock, + const struct timespec *timeout) { + return pthread_rwlock_timedwrlock_WRK(rwlock, timeout); +} #elif defined(VGO_darwin) #elif defined(VGO_freebsd) PTH_FUNC(int, pthreadZurwlockZutimedwrlock, // pthread_rwlock_timedwrlock diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index 28f4c61912..2157f7cd38 100755 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -134,7 +134,8 @@ EXTRA_DIST = \ tc24_nonzero_sem.vgtest tc24_nonzero_sem.stdout.exp \ tc24_nonzero_sem.stderr.exp \ tls_threads.vgtest tls_threads.stdout.exp \ - tls_threads.stderr.exp + tls_threads.stderr.exp \ + trylock.vgtest trylock.stderr.exp # Wrapper headers used by some check programs. noinst_HEADERS = safe-pthread.h safe-semaphore.h diff --git a/helgrind/tests/trylock.stderr.exp b/helgrind/tests/trylock.stderr.exp new file mode 100644 index 0000000000..e3aea4bd4e --- /dev/null +++ b/helgrind/tests/trylock.stderr.exp @@ -0,0 +1,13 @@ + +Locking rwlock via pthread_rwlock_wrlock(). +Locking rwlock via pthread_rwlock_trywrlock(). +Locking rwlock via pthread_rwlock_timedwrlock(). +Locking rwlock via pthread_rwlock_rdlock(). +Locking rwlock via pthread_rwlock_tryrdlock(). +Locking rwlock via pthread_rwlock_timedrdlock(). +Attempt to lock for writing recursively (not allowed). +Locking mutex via pthread_mutex_trylock(). +Locking mutex via pthread_mutex_lock(). +Locking mutex via pthread_mutex_timedlock(). + +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/helgrind/tests/trylock.vgtest b/helgrind/tests/trylock.vgtest new file mode 100644 index 0000000000..1d4f16d3b8 --- /dev/null +++ b/helgrind/tests/trylock.vgtest @@ -0,0 +1 @@ +prog: ../../drd/tests/trylock -- 2.47.2