llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[TSan] Automatically define the libstdc++ macros for annotating happens before and after

Open chandlerc opened this issue 13 years ago • 24 comments

Bugzilla Link 17066
Resolution FIXED
Resolved on Dec 01, 2015 12:27
Version trunk
OS All
CC @eugenis,@ramosian-glider,@kcc

Extended Description

Currently, TSan is very hard to use with a generic libstdc++. The reason is that the GLIBCXX_SYNCHRONIZATION_HAPPENS{BEFORE,AFTER} macros are not defined and thus the annotations in the library are not available to the race detector.

When using '-fsanitize=thread', Clang should directly provide definitions for these standard library macros that enable appropriate annotations for TSan.

See http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.races for the documentation of these macros.

chandlerc avatar Sep 03 '13 00:09 chandlerc

Landed r189791 with the suppression. Tested on kcc's repro -- the report goes away.

Chandler, please sync to head.

KernelAddress avatar Sep 03 '13 13:09 KernelAddress

minimized test is this:

#include int main() { std::thread t1{[=] {}}; t1.join(); }

clang++ --gcc-toolchain=$FRESH_GCC_INST -pthread -fsanitize=thread -fPIE -pie -std=c++11 -g test.cc

kcc avatar Sep 03 '13 11:09 kcc

_Sp_counted_ptr_inplace<std::thread is the thing to suppress

Ah, that also makes sense -- so that we only suppress the shared ptr bits coming from the internals of std::thread?

Either way seems reasonable to me...

chandlerc avatar Sep 03 '13 11:09 chandlerc

I don't see how you would suppress these. E.g. if you build the same test with -O1, the report looks like this: (no reasonable frame to suppress)

WARNING: ThreadSanitizer: data race (pid=9660) Write of size 8 at 0x7d0c0000efd8 by thread T1: #​0 operator delete /home/kcc/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:542 (exe+0x00000001337c) #​1 __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std: :_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>

::deallocate(std::_Sp_counted_ptr_inplace<std::thread::_Impl<std:: _Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>*, unsigned long) /usr/local/google/kcc/gcc-inst/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../. ./../include/c++/4.9.0/ext/new_allocator.h:110 (exe+0x00000005f165)

This one seems reasonable?

Specifically:

"__gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<T, std::allocator, (__gnu_cxx::_Lock_policy)2> >::deallocate(std::_Sp_counted_ptr_inplace<T, std::allocator, (__gnu_cxx::_Lock_policy)2>*, unsigned long)"

For any type T. This should only be used to deallocate already destroyed memory. It should be calling operator delete(void*) which isn't going to actually do anything in user code that we might accidentally suppress.

Is that do-able? I don't know how the suppression mechanisms work.

chandlerc avatar Sep 03 '13 11:09 chandlerc

_Sp_counted_ptr_inplace<std::thread is the thing to suppress

KernelAddress avatar Sep 03 '13 11:09 KernelAddress

I don't see how you would suppress these. E.g. if you build the same test with -O1, the report looks like this: (no reasonable frame to suppress)

WARNING: ThreadSanitizer: data race (pid=9660) Write of size 8 at 0x7d0c0000efd8 by thread T1: #​0 operator delete /home/kcc/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:542 (exe+0x00000001337c) #​1 __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >::deallocate(std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>*, unsigned long) /usr/local/google/kcc/gcc-inst/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/ext/new_allocator.h:110 (exe+0x00000005f165) #​2 :0 (libstdc++.so.6+0x00000006ccd5)

Previous atomic write of size 4 at 0x7d0c0000efd8 by main thread: #​0 __tsan_atomic32_fetch_add /home/kcc/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cc:465 (exe+0x000000039dc7) #​1 __gnu_cxx::__exchange_and_add_dispatch(int*, int) /usr/local/google/kcc/gcc-inst/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/ext/atomicity.h:81 (exe+0x00000005e73e) #​2 __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226 (libc.so.6+0x00000002176c)

kcc avatar Sep 03 '13 11:09 kcc

I am inclining towards including such suppression (at least in short term). This particular race can not appear in other unrelated places. The probability that a user will rebuild libstdc++ with tsan is about 0.

Cool, I'll verify when it goes in. Hopefully with this, tsan will be largely functional with C++11 and libstdc++.

Generally, I agree with folks that the only really good long-term solution is to have instrumented C++ stdlib... Hopefully something we can work on for the long-term solution.

chandlerc avatar Sep 03 '13 10:09 chandlerc

I am inclining towards including such suppression (at least in short term). This particular race can not appear in other unrelated places. The probability that a user will rebuild libstdc++ with tsan is about 0.

KernelAddress avatar Sep 03 '13 09:09 KernelAddress

Suppressing race reports caused by a non-intercepted synchronization is a road to hell. We've been there, returned, and don't want to come back :( If the tool missed some synchronization, the resulting false positives may appear in any random part of the code, not just something that has libstdc++ code in the call stack.

While I share your trepidation, I'm unsure what else to do...

I would like to encourage use of TSan without an instrumented STL, and so far I have seen no errors other than this specific one, but I see this one literally everywhere.

Long term, I agree that instrumenting the STL is a much better strategy, but we're not there just yet.

chandlerc avatar Sep 03 '13 09:09 chandlerc

Suppressing race reports caused by a non-intercepted synchronization is a road to hell. We've been there, returned, and don't want to come back :( If the tool missed some synchronization, the resulting false positives may appear in any random part of the code, not just something that has libstdc++ code in the call stack.

kcc avatar Sep 03 '13 09:09 kcc

OK, can we at least add suppressions?

It should be possible to suppress only the specializations of shared_ptr which are actually in libstdc++.so, and there-by avoid suppressing races out of user destructors that are run inside of shared_ptr. You could probably catch most of these by just covering the builtin types that get hit by the extern template declarations.

chandlerc avatar Sep 03 '13 09:09 chandlerc

It's in there:

$ nm -A libstdc++.so.6.0.19 | egrep "shared|counted" libstdc++.so.6.0.19:00000000000bb9c0 W _ZNKSbIwSt11char_traitsIwESaIwEE4_Rep12_M_is_sharedEv libstdc++.so.6.0.19:00000000000b9020 W _ZNKSs4_Rep12_M_is_sharedEv libstdc++.so.6.0.19:00000000000b0b50 t ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEaSERKS2 libstdc++.so.6.0.19:00000000000b0c20 t _ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE10_M_releaseEv libstdc++.so.6.0.19:00000000000b0d80 T _ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE

_Sp_counted_base::_M_release has lots of atomics, and it's compiled into libstdc++.so w/o instrumentation. If you remove -static-libstdc++, then you should see stack frames in libstdc++.so in the report.

KernelAddress avatar Sep 03 '13 09:09 KernelAddress

Do you mean that msan-instrumented libstdc++ distributed with clang and linked in when -fsanitize=memory?

No. It's less of an issue for MSan, or rather we have much bigger deployment issues than that. Users have to rebuild the rest of their dependencies from source anyway.

Also, I think Rafael wanted to do something like what you describe with libc++, see "Driver interaction with -fsanitize=memory" thread in cfe-dev.

eugenis avatar Sep 03 '13 09:09 eugenis

I am not sure how it works. libstdc++ binary still contains non-instrumented versions, can't they be used at runtime anyway?

Based on my investigation, I don't think that any of the synchronization is compiled into the library. It appears to all be inline in the headers.

chandlerc avatar Sep 03 '13 09:09 chandlerc

Sure I have a plan: build it from source!

Do you mean that msan-instrumented libstdc++ distributed with clang and linked in when -fsanitize=memory?

What is the preferred solution? Suppression? This is kind of a fundamental part of libstdc++...

The preferred solution is to re-compile the source. That's what we do with user code, listdc++ is not special in this context.

It's a bit sad to me because there are hooks that we could use at compile time to inject instrumentation.

The full set of hooks is tsan instrumentation. It is too expensive to have in normal build.

The other possibility might be to preclude the use of extern templates so that the compile sees all the code for templates like this?

I am not sure how it works. libstdc++ binary still contains non-instrumented versions, can't they be used at runtime anyway?

KernelAddress avatar Sep 03 '13 09:09 KernelAddress

Actually, I don't get it yet. Dmitry, please help. =] Feel free to grab me on IRC if interactive would go faster.

All of the source code I'm about to reference is in the revision of libstdc++ I mentioned previously. Paths relative to the root of the include tree.

So I see the start of the racy code as beneath the call to _M_destroy() on line 161 of bits/shared_ptr_base.h inside of the _M_release() method:

  _M_release() noexcept
  {
    // Be race-detector-friendly.  For more info see bits/c++config.
    _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count);
    if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
      {
        _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count);
        _M_dispose();
        // There must be a memory barrier between dispose() and destroy()
        // to ensure that the effects of dispose() are observed in the
        // thread that runs destroy().
        // See http://gcc.gnu.org/ml/libstdc++/2005-11/msg00136.html
        if (_Mutex_base<_Lp>::_S_need_barriers)
          {
            _GLIBCXX_READ_MEM_BARRIER;
            _GLIBCXX_WRITE_MEM_BARRIER;
          }

        // Be race-detector-friendly.  For more info see bits/c++config.
        _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
        if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count,
                                                   -1) == 1)
          {
            _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count);
            _M_destroy();
          }
      }
  }

In turn, the atomic operations are routed through routins in ext/atomicity.h which defines __exchange_and_add_dispatch, which in turn calls through to __exchange_and_add which is a wrapper around __atomic_fetch_add which we should be able to intercept (that is one of the GNU atomic builtin functions).

All of this code is within headers, and all of it appears to be instrumented during the compilation. What's more, the full TSan report for my test case shows TSan successfully intercepting the __atomic_fetch_add which is the eventual result of the same synchronization call stack but rooted earlier in _M_release(), bits/shared_ptr_base.h:141.

So I think TSan can see the synchronization here. What am I missing? Below is the full reproduction that I am looking at:


% cat tsan/bug.cpp #include #include #include <condition_variable> #include #include #include

class A { public: virtual void F() { std::lock_guardstd::mutex l(m); std::cout << "The bad function was called!" << std::endl; std::quick_exit(1); } void Done() { F(); // This will crash unless the dynamic type is B.

std::lock_guard<std::mutex> l(m);
is_done = true;
cv.notify_one();
std::cout << "Called Done..." << std::endl;

} virtual ~A() { std::unique_lockstd::mutex l(m); std::cout << "Waiting for Done..." << std::endl; cv.wait(l, [&]{ return is_done; }); std::cout << "Destroying object..." << std::endl; }

protected: std::mutex m; std::condition_variable cv; bool is_done = false; };

class B : public A { public: virtual void F() { std::lock_guardstd::mutex l(m); std::cout << "The good function was called!" << std::endl; } virtual ~B() {} };

int main() { A *obj = new B{};

std::thread t1{[=] { obj->F(); obj->Done(); }}; std::thread t2{[=] { std::this_thread::sleep_for(std::chrono::seconds(1));

// This is safe: the destructor waits for the call to Done.
delete obj;

}};

t1.join(); t2.join(); }

% ~/bin/clang++ -pthread -static-libstdc++ -o tsan_bug -std=c++11 -g -fsanitize=thread tsan/bug.cpp

% ./tsan_bug
The good function was called! The good function was called! Called Done...

WARNING: ThreadSanitizer: data race (pid=12714) Write of size 8 at 0x7d100000dfc8 by thread T1: #​0 operator delete /home/chandlerc/src/llvm.git/opt-build/../projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:542 (exe+0x00000001462c) #​1 __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >::deallocate(std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::all ocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>, unsigned long) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/ext/new_allocator.h:116 (exe+0x00000006516f) #​2 std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> > >::deallocate(std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_sim ple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >&, std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>, unsigned lo ng) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/alloc_traits.h:377 (exe+0x000000065090) #​3 std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>::_M_destroy() /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/share d_ptr_base.h:417 (exe+0x0000000659c5) #​4 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /home/chandlerc/src/gcc-google-main.svn/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/shared_ptr_base.h:161 (exe+0x0000000a3eaa)

Previous atomic write of size 4 at 0x7d100000dfc8 by main thread: #​0 __tsan_atomic32_fetch_add /home/chandlerc/src/llvm.git/opt-build/../projects/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cc:465 (exe+0x00000003c2ad) #​1 __gnu_cxx::__exchange_and_add(int volatile*, int) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/ext/atomicity.h:47 (exe+0x000000061675) #​2 __gnu_cxx::__exchange_and_add_dispatch(int*, int) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/ext/atomicity.h:80 (exe+0x00000006153c) #​3 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr_base.h:141 (exe+0x000000066f21) #​4 ~__shared_count /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr_base.h:553 (exe+0x000000066ec0) #​5 ~__shared_count /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr_base.h:551 (exe+0x000000066e40) #​6 ~__shared_ptr /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr_base.h:810 (exe+0x000000067089) #​7 ~shared_ptr /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr.h:93 (exe+0x000000067033) #​8 ~shared_ptr /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr.h:93 (exe+0x000000066df0) #​9 thread<<lambda at tsan/bug.cpp:50:18>> /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/thread:135 (exe+0x0000000640a3) #​10 main /home/chandlerc/src/llvm.git/build/gn_2013/tsan/bug.cpp:50 (exe+0x000000061030)

Location is heap block of size 56 at 0x7d100000dfc0 allocated by main thread: #​0 operator new /home/chandlerc/src/llvm.git/opt-build/../projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:510 (exe+0x0000000141d3) #​1 __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-goo gle/../../../../include/c++/4.8.x-google/ext/new_allocator.h:104 (exe+0x000000066917) #​2 std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simpl e<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/alloc_traits.h:351 (exe+0x000000064e9a) #​3 __shared_count<std::thread::_Impl<std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > >, std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../ ../../include/c++/4.8.x-google/bits/shared_ptr_base.h:519 (exe+0x000000064bf1) #​4 __shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > >, std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr_base.h:987 (exe+0x000000064a64 ) #​5 shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > >, std::_Bind_simple<<lambda at tsan/bug.cpp:50:18> ()> > /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr.h:317 (exe+0x000000064968) #​6 _ZSt15allocate_sharedINSt6thread5_ImplISt12_Bind_simpleIFZ4mainE3$0vEEEESaIS6_EJS5_EESt10shared_ptrIT_ERKT0_DpOT1 /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr.h:597 (exe+0x0000000647b7) #​7 _ZSt11make_sharedINSt6thread5_ImplISt12_Bind_simpleIFZ4mainE3$0vEEEEJS5_EESt10shared_ptrIT_EDpOT0 /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/bits/shared_ptr.h:613 (exe+0x00000006465c) #​8 std::shared_ptr<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > > std::thread::_M_make_routine<std::_Bind_simple<main::$_0 ()> >(std::_Bind_simple<main::$_0 ()>&&) /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/thread:193 (exe+0x0000000641bb) #​9 thread<<lambda at tsan/bug.cpp:50:18>> /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/thread:135 (exe+0x00000006406b) #​10 main /home/chandlerc/src/llvm.git/build/gn_2013/tsan/bug.cpp:50 (exe+0x000000061030)

Thread T1 (tid=12716, running) created by main thread at: #​0 pthread_create /home/chandlerc/src/llvm.git/opt-build/../projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:820 (exe+0x000000016bb3) #​1 __gthread_create /home/chandlerc/src/gcc-google-main.svn/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:662 (exe+0x0000000a40ce) #​2 main /home/chandlerc/src/llvm.git/build/gn_2013/tsan/bug.cpp:50 (exe+0x000000061030)

SUMMARY: ThreadSanitizer: data race /home/chandlerc/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.x-google/../../../../include/c++/4.8.x-google/ext/new_allocator.h:116 __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::Bind simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2> >::deallocate(std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<main::$_0 ()> > >, (__gnu_cxx::_Lock_policy)2>*, unsigned long)

================== WARNING: ThreadSanitizer: data race on vptr (ctor/dtor vs virtual call) (pid=12714)


chandlerc avatar Sep 03 '13 08:09 chandlerc

preclude the use of extern templates

Yes, that's part of msan plan B, too.

eugenis avatar Sep 03 '13 08:09 eugenis

related discussion: https://groups.google.com/forum/#!topic/thread-sanitizer/vz_s-t226Vg

kcc avatar Sep 03 '13 08:09 kcc

Sure I have a plan: build it from source! It might be possible to deal with it by a combination of interceptors and whitelisted types, but that's a lot of work, and building from source works fine for now.

eugenis avatar Sep 03 '13 08:09 eugenis

With msan we use an instrumented libstdc++.

What is the preferred solution? Suppression? This is kind of a fundamental part of libstdc++...

It's a bit sad to me because there are hooks that we could use at compile time to inject instrumentation.

The other possibility might be to preclude the use of extern templates so that the compile sees all the code for templates like this?

chandlerc avatar Sep 03 '13 08:09 chandlerc