Bug 494327 - Crash when running Helgrind built with #define TRACE_PTH_FNS 1
Summary: Crash when running Helgrind built with #define TRACE_PTH_FNS 1
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: helgrind (show other bugs)
Version: 3.24 GIT
Platform: Other FreeBSD
: NOR crash
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-09 06:22 UTC by Paul Floyd
Modified: 2024-11-03 19:45 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Floyd 2024-10-09 06:22:47 UTC
I get this segfault:

==68279== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==68279==  Bad permissions for mapped region at address 0x1FFEDFFFF8
==68279==    at 0x49B4F5C: vfprintf_l (in /lib/libc.so.7)
==68279==    by 0x49ADA3E: fprintf (in /lib/libc.so.7)
==68279==    by 0x4857A7E: mutex_lock_WRK (hg_intercepts.c:931)
==68279==    by 0x49AB6D6: flockfile (in /lib/libc.so.7)
==68279==    by 0x49B4FB1: vfprintf_l (in /lib/libc.so.7)
==68279==    by 0x49ADA3E: fprintf (in /lib/libc.so.7)
==68279==    by 0x4857A7E: mutex_lock_WRK (hg_intercepts.c:931)
==68279==    by 0x49AB6D6: flockfile (in /lib/libc.so.7)
==68279==    by 0x49B4FB1: vfprintf_l (in /lib/libc.so.7)
==68279==    by 0x49ADA3E: fprintf (in /lib/libc.so.7)
==68279==    by 0x4857A7E: mutex_lock_WRK (hg_intercepts.c:931)
==68279==    by 0x49AB6D6: flockfile (in /lib/libc.so.7)

The code

static int mutex_lock_WRK(pthread_mutex_t *mutex)
{
   int    ret;
   OrigFn fn;
   VALGRIND_GET_ORIG_FN(fn);
   if (TRACE_PTH_FNS) {
      fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr);
   }

My guess here is that FreeBSD libc fprintf makes a call to pthread_mutex_lock with the result that the code gets stuck in infinite recursion.
Comment 1 Paul Floyd 2024-11-03 19:45:31 UTC
commit a2ef9690458cf472cb8a4da3793657b2c5a8cda6 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Sun Nov 3 20:42:43 2024 +0100

    Bug 494327 - Crash when running Helgrind built with #define TRACE_PTH_FNS 1
    
    Use write() rather than 'fprintf()' for the TRACE_PTH_FNS blocks for
    pthread_mutex_lock and pthread_mutex_lock. Mixing FILE and fd isn't
    great, but this is to stderr which gets flushed on every line, and
    it is only for developer builds that modify that TRACE_PTH_FNS macro.