Bug 302630

Summary: Memcheck on multithreaded program fails with Assertion 'sizeof(UWord) == sizeof(UInt)' failed in m_syscall.c
Product: [Developer tools] valgrind Reporter: Markus Lindström <markus.lindstrom>
Component: memcheckAssignee: Rhys Kidd <rhyskidd>
Status: RESOLVED FIXED    
Severity: normal CC: czenger, markus.lindstrom, matthewmitchell
Priority: NOR    
Version: 3.10 SVN   
Target Milestone: ---   
Platform: unspecified   
OS: macOS   
See Also: https://bugs.kde.org/show_bug.cgi?id=326797
Latest Commit: Version Fixed In:
Sentry Crash Report:
Bug Depends on:    
Bug Blocks: 304259    
Attachments: Sample C code that causes the assertion failure.

Description Markus Lindström 2012-06-27 12:25:46 UTC
Created attachment 72166 [details]
Sample C code that causes the assertion failure.

I've written a simple multithreaded program and wanted to run memcheck 3.7.0 on it. It sometimes works, but sometimes fails due to an assertion failure which seems to occur randomly. The C source code of the sample program is attached. Removing manual thread stack size settings does not remedy the problem AFAICS.

I ran Valgrind on an early 2008 MacBook Pro with OS X 10.7.4, equipped with a 2.26 GHz Intel Core 2 Duo.

Here's the full output:

==26310== Memcheck, a memory error detector
==26310== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==26310== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==26310== Command: ./a.out
==26310== 

valgrind: m_syscall.c:152 (vgPlain_mk_SysRes_x86_darwin): Assertion 'sizeof(UWord) == sizeof(UInt)' failed.
==26310==    at 0x2380373EB: ???
==26310==    by 0x2380376BF: ???
==26310==    by 0x23804DC85: ???
==26310==    by 0x2380C12DD: ???
==26310==    by 0x2380A2202: ???
==26310==    by 0x2380A001F: ???
==26310==    by 0x2380CA4ED: ???

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable
==26310==    at 0x2BF67A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==26310==    by 0x2BA847: thread_terminate (in /usr/lib/system/libsystem_kernel.dylib)
==26310==    by 0x17F157: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000D69: main (dirthread.c:76)

Thread 7: status = VgTs_WaitSys
==26310==    at 0x2BF67A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==26310==    by 0x2B7D38: semaphore_create (in /usr/lib/system/libsystem_kernel.dylib)
==26310==    by 0x17E0F7: new_sem_from_pool (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F199: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000B8F: handleFile (dirthread.c:43)
==26310==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)

Thread 8: status = VgTs_Yielding
==26310==    at 0x1D1367: spin_lock$VARIANT$mp (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F199: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000B8F: handleFile (dirthread.c:43)
==26310==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)

Thread 10: status = VgTs_WaitSys
==26310==    at 0x1D1385: spin_lock$VARIANT$mp (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F199: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000B8F: handleFile (dirthread.c:43)
==26310==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)

Thread 14: status = VgTs_WaitSys
==26310==    at 0x1D1385: spin_lock$VARIANT$mp (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F199: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000B8F: handleFile (dirthread.c:43)
==26310==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)

Thread 18: status = VgTs_WaitSys
==26310==    at 0x1D1385: spin_lock$VARIANT$mp (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F199: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x100000B8F: handleFile (dirthread.c:43)
==26310==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==26310==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)
Comment 1 Julian Seward 2012-07-05 13:08:47 UTC
This seems like some build time configuration error, or something.  I doubt it is related
to the test program.  Does this still happen with a clean build of valgrind?
Comment 2 Christoph Zenger 2012-07-09 10:26:17 UTC
I was just about to file what seems the same bug.

I have a MacBookPro 15-inch Mid 2010 running Mac OS X Lion 10.7.4 (11E53).
I 'm also running valgrind 3.7.0 and I built it very recently.

It occurred to me after inserting pthread_exit into the main thread which I did
in order to wait for the other threads to shutdown before exiting.

valgrind: m_syscall.c:152 (vgPlain_mk_SysRes_x86_darwin): Assertion 'sizeof(UWord) == sizeof(UInt)' failed.
==80767==    at 0x2380373EB: ???
==80767==    by 0x2380376BF: ???
==80767==    by 0x23804DC85: ???
==80767==    by 0x2380C12DD: ???
==80767==    by 0x2380A2202: ???
==80767==    by 0x2380A001F: ???
==80767==    by 0x2380CA4ED: ???

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable
==80767==    at 0x2BF67A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==80767==    by 0x2BA847: thread_terminate (in /usr/lib/system/libsystem_kernel.dylib)
==80767==    by 0x17F157: _pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==80767==    by 0x17F27C: pthread_exit (in /usr/lib/system/libsystem_c.dylib)
==80767==    by 0x1000A5488: main (in ./main_simple_Main)



Thread 2: status = VgTs_WaitSys
==80767==    at 0x2C0BF2: __psynch_mutexwait (in /usr/lib/system/libsystem_kernel.dylib)
==80767==    by 0x1C5209: flockfile (in /usr/lib/system/libsystem_c.dylib)
==80767==    by 0x170FA5: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==80767==    by 0x1000A3D17: gc_log (in ./main_simple_Main)
==80767==    by 0x1000A376D: thread_main (in ./main_simple_Main)
==80767==    by 0x17D8BE: _pthread_start (in /usr/lib/system/libsystem_c.dylib)
==80767==    by 0x180B74: thread_start (in /usr/lib/system/libsystem_c.dylib)
Comment 3 Markus Lindström 2012-07-09 10:30:49 UTC
(In reply to comment #1)
> Does this still happen with a clean build of valgrind?

Yes, it's with a clean build of 3.7.0 using the Xcode 4.3.2 toolchain.
Comment 4 Rhys Kidd 2015-05-27 13:06:10 UTC
Discovered reproducible with the below regression test on affected platforms:

$ perl tests/vg_regtest none/tests/pth_exit

This was with the below clang compiler and OS X version:

$ clang --version
Apple LLVM version 5.1 (clang-503.0.40)  (based on LLVM 3.4svn)
Target: x86_64-apple-darwin-12.0.0
Thread model: posix
$ uname -mrs
Darwin 12.0.0 x86_64

It is not present on OS X 10.9 (clang-600.0.57 based on LLVM 3.5svn) or OS X 10.10.
Comment 5 Rhys Kidd 2015-05-27 13:06:35 UTC
*** Bug 326797 has been marked as a duplicate of this bug. ***
Comment 6 Rhys Kidd 2015-06-08 11:08:15 UTC
Resolved in r15329.