From: Paul Floyd Date: Sat, 12 Oct 2024 07:10:21 +0000 (+0200) Subject: FreeBSD helgrind: temporary (?) fix for Bug 494337 X-Git-Tag: VALGRIND_3_24_0~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b670ae69185908bd3ed70c047545d1614dbaf06;p=thirdparty%2Fvalgrind.git FreeBSD helgrind: temporary (?) fix for Bug 494337 FreeBSD 15 has added a pthread lock to exit() to ensure that atexit handling is thread safe. Unfortunately that lock gets leaked which messes up just about all of the Helgrind tests. Supression won't work as the callstack is the same for both genuine leaks and this deliberate leak. This change simply turns off the check for FreeBSD >= 15. I see two possible proper fixes. One would be to allow one lock on exit. The problem with that is that we will need to tell apart a clean exit (1 lock allowed) and any kind of abort that doesn't call exit (no locks allowed). That's going to be tricky as the Helgrind check is done before we get back to core and know whether it is an abort or a clean exit. The other thing would be to hack the lock counting. If we can detect that it's a pthread_mutex_lock called from exit() then we could ignore that for counting purposes. That would mean a possibly significant overhead for each call to pthread_mutex_lock on FreeBSD. --- diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index bf1af3b4a..8522b593f 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -1716,12 +1716,14 @@ void evh__pre_thread_ll_exit ( ThreadId quit_tid ) /* Complain if this thread holds any locks. */ nHeld = HG_(cardinalityWS)( univ_lsets, thr_q->locksetA ); tl_assert(nHeld >= 0); +#if !defined(VGO_freebsd) || (FREEBSD_VERS < FREEBSD_15) if (nHeld > 0) { HChar buf[80]; VG_(sprintf)(buf, "Exiting thread still holds %d lock%s", nHeld, nHeld > 1 ? "s" : ""); HG_(record_error_Misc)( thr_q, buf ); } +#endif /* Not much to do here: - tell libhb the thread is gone diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index 0f2a5ef85..d7101ed1a 100755 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -87,6 +87,7 @@ EXTRA_DIST = \ tc03_re_excl.stderr.exp \ tc04_free_lock.vgtest tc04_free_lock.stdout.exp \ tc04_free_lock.stderr.exp \ + tc04_free_lock.stderr.exp-freebsd15 \ tc05_simple_race.vgtest tc05_simple_race.stdout.exp \ tc05_simple_race.stderr.exp \ tc06_two_races.vgtest tc06_two_races.stdout.exp \ @@ -99,6 +100,7 @@ EXTRA_DIST = \ tc09_bad_unlock.vgtest tc09_bad_unlock.stdout.exp \ tc09_bad_unlock.stderr.exp tc09_bad_unlock.stderr.exp-solaris \ tc09_bad_unlock.stderr.exp-freebsd \ + tc09_bad_unlock.stderr.exp-freebsd15 \ tc10_rec_lock.vgtest tc10_rec_lock.stdout.exp tc10_rec_lock.stderr.exp \ tc11_XCHG.vgtest tc11_XCHG.stdout.exp tc11_XCHG.stderr.exp \ tc12_rwl_trivial.vgtest tc12_rwl_trivial.stdout.exp \ @@ -137,6 +139,7 @@ EXTRA_DIST = \ tc22_exit_w_lock.stderr.exp \ tc22_exit_w_lock.stderr.exp-kfail-x86 \ tc22_exit_w_lock.stderr.exp-solaris \ + tc22_exit_w_lock.stderr.exp-freebsd15 \ tc23_bogus_condwait.vgtest tc23_bogus_condwait.stdout.exp \ tc23_bogus_condwait.stderr.exp \ tc23_bogus_condwait.stderr.exp-mips32 \