Configure with thread sanitizer fails the thread test - Mailing list pgsql-hackers

From Ewan Higgs
Subject Configure with thread sanitizer fails the thread test
Date
Msg-id 1513971675.5870501.1439797066345.JavaMail.yahoo@mail.yahoo.com
Whole thread Raw
List pgsql-hackers
Hi all,
I throught I would try sqlsmith with more sanitizers. So, I tried the ThreadSanitizer. Building off HEAD (522400a5198f63823406202e18fdaf3621619d98), it fails to complete the thread check since the thread test because there are some volatile ints being accessed between threads[1]. Volatile prevents caching of the variable in each thread context but it doesn't provide all the guarantees needed for multithreaded programming. This should probably use _Atomic (C11) on platforms with C11 compilers and whatever else is needed for platforms that refuse to update their compilers past C89.

So I changed volatile to _Atomic and continued (patch is in thread_test_atomic.patch). I then ran it against sqlsmith. The good news: I didn't happen to find any problems in normal use. The bad news: I did find a lot of warnings about improper use of functions like malloc and free from signal handlers. I attached the log under 'errors.log'.

I haven't investigated this in depth yet since I figured if I flagged it on the list someone might be in a better position to determine if it's worth fixing and what the fix might be.

My configure flags:
./configure CFLAGS='-O1 -g -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls' LDFLAGS='-ltsan -ldl' --enable-cassert --prefix=$HOME/pkg

Yours,
Ewan


[1] Failed test in configure yields:
==================                                                             
WARNING: ThreadSanitizer: data race (pid=31420)                                
  Write of size 4 at 0x000000602100 by thread T2:                              
    #0 func_call_2 src/test/thread/thread_test.c:416 (conftest+0x000000400db9) 
    #1 <null> <null> (libtsan.so.0+0x0000000235b9)                             
                                                                               
  Previous read of size 4 at 0x000000602100 by thread T1:                      
    #0 func_call_1 src/test/thread/thread_test.c:326 (conftest+0x000000400f3a) 
    #1 <null> <null> (libtsan.so.0+0x0000000235b9)                             
                                                                               
  Location is global 'errno2_set' of size 4 at 0x000000602100 (conftest+0x000000602100)
                                                                               
  Thread T2 (tid=31423, running) created by main thread at:                    
    #0 pthread_create <null> (libtsan.so.0+0x000000027a67)                     
    #1 main src/test/thread/thread_test.c:165 (conftest+0x0000004010e1)        
                                                                               
  Thread T1 (tid=31422, running) created by main thread at:                    
    #0 pthread_create <null> (libtsan.so.0+0x000000027a67)                     
    #1 main src/test/thread/thread_test.c:158 (conftest+0x00000040107e)        
                                                                               
SUMMARY: ThreadSanitizer: data race src/test/thread/thread_test.c:416 func_call_2
==================                                                             
WARNING: ThreadSanitizer: data race (pid=31420)                                
  Read of size 4 at 0x000000602104 by thread T2:                               
    #0 func_call_2 src/test/thread/thread_test.c:417 (conftest+0x000000400dcd) 
    #1 <null> <null> (libtsan.so.0+0x0000000235b9)                             
                                                                               
  Previous write of size 4 at 0x000000602104 by thread T1:                     
    #0 func_call_1 src/test/thread/thread_test.c:325 (conftest+0x000000400f26) 
    #1 <null> <null> (libtsan.so.0+0x0000000235b9)                             
                                                                               
  Location is global 'errno1_set' of size 4 at 0x000000602104 (conftest+0x000000602104)
                                                                               
  Thread T2 (tid=31423, running) created by main thread at:                    
    #0 pthread_create <null> (libtsan.so.0+0x000000027a67)                     
    #1 main src/test/thread/thread_test.c:165 (conftest+0x0000004010e1)        
                                                                               
  Thread T1 (tid=31422, running) created by main thread at:                    
    #0 pthread_create <null> (libtsan.so.0+0x000000027a67)                     
    #1 main src/test/thread/thread_test.c:158 (conftest+0x00000040107e)        
                                                                               
SUMMARY: ThreadSanitizer: data race src/test/thread/thread_test.c:417 func_call_2
==================                                                             
errno not thread-safe **                                                       
exiting                                                                        
==================                                                             
WARNING: ThreadSanitizer: data race (pid=31420)                                
  Write of size 4 at 0x00000060210c by thread T1:                              
    #0 func_call_1 src/test/thread/thread_test.c:381 (conftest+0x000000400fc8) 
    #1 <null> <null> (libtsan.so.0+0x0000000235b9)                             
                                                                               
  Previous read of size 4 at 0x00000060210c by main thread (mutexes: write M6):
    #0 main src/test/thread/thread_test.c:176 (conftest+0x000000401123)        
                                                                               
  Location is global 'thread1_done' of size 4 at 0x00000060210c (conftest+0x00000060210c)
                                                                               
  Mutex M6 (0x000000602120) created at:                                        
    #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037776)                 
    #1 main src/test/thread/thread_test.c:156 (conftest+0x000000401066)        
                                                                               
  Thread T1 (tid=31422, running) created by main thread at:                    
    #0 pthread_create <null> (libtsan.so.0+0x000000027a67)                     
    #1 main src/test/thread/thread_test.c:158 (conftest+0x00000040107e)        
                                                                               
SUMMARY: ThreadSanitizer: data race src/test/thread/thread_test.c:381 func_call_1
==================                                                             
ThreadSanitizer: reported 3 warnings 
Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Raising our compiler requirements for 9.6
Next
From: Andres Freund
Date:
Subject: Re: checkpointer continuous flushing