Skip to content

ThreadSanitizer broke between nightly build 07-06 and 07-07 #44002

Closed
@spacejam

Description

@spacejam

While working on my lock-free persistent b+ tree I updated my rustc and all of the sudden started having problems when running tsan.

λ uname -a

Linux eligos 4.12.6-1-ARCH #1 SMP PREEMPT Sat Aug 12 09:16:22 CEST 2017 x86_64 GNU/Linux 

λ cat src/main.rs

use std::thread;                                                                                                                                                                                                                                              

static mut ANSWER: i32 = 0;

fn main() {
    let t1 = thread::spawn(|| unsafe { ANSWER = 42 });
    unsafe {
        ANSWER = 24;
    }
    t1.join().ok();
}

λ RUSTFLAGS="-Z sanitizer=thread" rustup run nightly-2017-07-06-x86_64-unknown-linux-gnu cargo run --target x86_64-unknown-linux-gnu

    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs                                                               
     Running `target/x86_64-unknown-linux-gnu/debug/m`         
==================             
WARNING: ThreadSanitizer: data race (pid=23677)                
  Write of size 4 at 0x0017d33d9b84 by main thread:            
    #0 m::main /tmp/race/m/src/main.rs:8 (m+0xff7c)            
    #1 panic_unwind::__rust_maybe_catch_panic /checkout/src/libpanic_unwind/lib.rs:98 (m+0x2254c)                              
    #2 __libc_start_main ??:? (libc.so.6+0x204c9)              

  Previous write of size 4 at 0x0017d33d9b84 by thread T1:     
    #0 m::main::{{closure}} /tmp/race/m/src/main.rs:6 (m+0x1003c)                                                              
    #1 std::sys_common::backtrace::__rust_begin_short_backtrace<closure,()> /checkout/src/libstd/sys_common/backtrace.rs:136 (m+0xa775)
    #2 std::thread::{{impl}}::spawn::{{closure}}::{{closure}}<closure,()> /checkout/src/libstd/thread/mod.rs:364 (m+0xb54d)    
    #3 std::panic::{{impl}}::call_once<(),closure> /checkout/src/libstd/panic.rs:296 (m+0x9175)                                
    #4 std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure>,()> /checkout/src/libstd/panicking.rs:479 (m+0xb719) 
    #5 panic_unwind::__rust_maybe_catch_panic /checkout/src/libpanic_unwind/lib.rs:98 (m+0x2254c)                              
    #6 std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure>,()> /checkout/src/libstd/panic.rs:361 (m+0xa837)         
    #7 std::thread::{{impl}}::spawn::{{closure}}<closure,()> /checkout/src/libstd/thread/mod.rs:363 (m+0xb357)                 
    #8 alloc::boxed::{{impl}}::call_box<(),closure> /checkout/src/liballoc/boxed.rs:652 (m+0xeadf)                             
    #9 alloc::boxed::{{impl}}::call_once<(),()> /checkout/src/liballoc/boxed.rs:662 (m+0x1a76b)                                
    #10 std::sys_common::thread::start_thread /checkout/src/libstd/sys_common/thread.rs:21 (m+0x1a76b)                         
    #11 std::sys::imp::thread::{{impl}}::new::thread_start /checkout/src/libstd/sys/unix/thread.rs:84 (m+0x1a76b)              

  Location is global '<null>' at 0x000000000000 (m+0x0000002f5b84)                                                             

  Thread T1 (tid=23697, finished) created by main thread at:   
    #0 pthread_create /checkout/src/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:897 (m+0x56ff3)                              
    #1 std::sys::imp::thread::{{impl}}::new /checkout/src/libstd/sys/unix/thread.rs:72 (m+0x1a46e)                             
    #2 std::thread::spawn<closure,()> /checkout/src/libstd/thread/mod.rs:492 (m+0xa8dd)                                        
    #3 m::main /tmp/race/m/src/main.rs:6 (m+0xff6c)            
    #4 panic_unwind::__rust_maybe_catch_panic /checkout/src/libpanic_unwind/lib.rs:98 (m+0x2254c)                              
    #5 __libc_start_main ??:? (libc.so.6+0x204c9)              

SUMMARY: ThreadSanitizer: data race /tmp/race/m/src/main.rs:8 in m::main                                                       
==================             
ThreadSanitizer: reported 1 warnings                                                                                                                                                                                                                                         

λ RUSTFLAGS="-Z sanitizer=thread" rustup run nightly-2017-07-07-x86_64-unknown-linux-gnu cargo run --target x86_64-unknown-linux-gnu

    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs                                                                                                                                                                                              
     Running `target/x86_64-unknown-linux-gnu/debug/m`                                                                                                                                                                                                        
==26245==FATAL: ThreadSanitizer: failed to intercept pthread_mutex_lock

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions