ThreadSanitizer的抑制文件不起作用:出了什么问题?

时间:2013-10-03 15:44:08

标签: c++ clang

Clang有-fsanitize-blacklist编译开关来禁止ThreadSanitizer发出警告。不幸的是,我无法让它发挥作用。

以下是我要压制的示例:

WARNING: ThreadSanitizer: data race (pid=21502)
  Read of size 8 at 0x7f0dcf5b31a8 by thread T6:
    #0 tbb::interface6::internal::auto_partition_type_base<tbb::interface6::internal::auto_partition_type>::check_being_stolen(tbb::task&) /usr/include/tbb/partitioner.h:305 (exe+0x000000388b38)
    #1 <null> <null>:0 (libtbb.so.2+0x0000000224d9)

  Previous write of size 8 at 0x7f0dcf5b31a8 by thread T1:
    #0 auto_partition_type_base /usr/include/tbb/partitioner.h:299 (exe+0x000000388d9a)
    #1 <null> <null>:0 (libtbb.so.2+0x0000000224d9)
    #2 GhostSearch::Ghost3Search::SearchTask::execute_impl() /home/phil/ghost/search/ghost3/ghost3_search_alg.cpp:1456 (exe+0x000000387a8a)
    #3 <null> <null>:0 (libtbb.so.2+0x0000000224d9)
    #4 GhostSearch::Ghost3Search::Ghost3SearchAlg::NullWindowSearch(int, MOVE, int, std::vector<MOVE, std::allocator<MOVE> >&) /home/phil/ghost/search/ghost3/ghost3_search_alg.cpp:1640 (exe+0x000000388310)
    #5 GhostSearch::PureMTDSearchAlg::FullWindowSearch(GhostSearch::SearchWindow, GhostSearch::SearchWindow, MOVE, int, std::vector<MOVE, std::allocator<MOVE> >&) /home/phil/ghost/search/pure_mtd_search_alg.cpp:41 (exe+0x000000370e3f)
    #6 GhostSearch::PureSearchAlgWrapper::RequestHandlerThread::EnterHandlerMainLoop() /home/phil/ghost/search/pure_search_alg_wrapper.cpp:124 (exe+0x000000372d1b)
    #7 operator() /home/phil/ghost/search/pure_search_alg_wrapper.cpp:94 (exe+0x000000374683)
    #8 execute_native_thread_routine /home/phil/tmp/gcc/src/gcc-4.8-20130725/libstdc++-v3/src/c++11/thread.cc:84 (libstdc++.so.6+0x0000000b26cf)

  Thread T6 (tid=21518, running) created by thread T3 at:
    #0 pthread_create ??:0 (exe+0x0000002378e1)
    #1 <null> <null>:0 (libtbb.so.2+0x0000000198c0)

  Thread T1 (tid=21513, running) created by main thread at:
    #0 pthread_create ??:0 (exe+0x0000002378e1)
    #1 __gthread_create /home/phil/tmp/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:662 (libstdc++.so.6+0x0000000b291e)
    #2 GhostSearch::PureSearchAlgWrapper::StartRequestHandlerThread() /home/phil/ghost/search/pure_search_alg_wrapper.cpp:77 (exe+0x0000003715c3)
    #3 GhostSearch::Search::ExecuteSearch(GhostSearch::SEARCH_SETTINGS const&) /home/phil/ghost/search.cpp:243 (exe+0x00000033063f)
    #4 GhostSearch::Search::StartSearch(GhostSearch::SEARCH_SETTINGS const&, UserBoard const&, GhostInterfaces::UserInterface*) /home/phil/ghost/search.cpp:176 (exe+0x00000033037a)
    #5 GhostInterfaces::UserInterface::StartSearch(GhostSearch::SEARCH_SETTINGS const&, UserBoard const&) /home/phil/ghost/interface.cpp:1072 (exe+0x0000002ea220)
    #6 GhostInterfaces::UserInterface::MainLoop() /home/phil/ghost/interface.cpp:576 (exe+0x0000002e9464)
    #7 GhostInterfaces::Command_Analyze::Execute(GhostInterfaces::UserInterfaceData&) /home/phil/ghost/commands.cpp:1005 (exe+0x00000028756c)
    #8 GhostInterfaces::UserInterface::FinishNextCommand() /home/phil/ghost/interface.cpp:1161 (exe+0x0000002e9ed0)
    #9 GhostInterfaces::UserInterface::MainLoop() /home/phil/ghost/interface.cpp:571 (exe+0x0000002e9447)
    #10 main /home/phil/ghost/ghost.cpp:54 (exe+0x000000274efd)

SUMMARY: ThreadSanitizer: data race /usr/include/tbb/partitioner.h:305 tbb::interface6::internal::auto_partition_type_base<tbb::interface6::internal::auto_partition_type>::check_being_stolen(tbb::task&)

到目前为止,我尝试了抑制文件(但它不起作用):

# TBB
fun:tbb::*
src:/usr/include/tbb/partitioner.h

你知道为什么它不起作用吗?

(顺便说一句,我很乐意压制TBB库中的所有警告。)

1 个答案:

答案 0 :(得分:2)

最后,我开始工作了。

根据documentation,每一行必须以有效的&#34; suppress_type&#34;开头。 (racethreadmutexsignaldeadlockcalled_from_lib)。

在我的示例中,正确的suppress_type为race

这是一个名为&#34; sanitizer-thread-suppressions.txt&#34;的示例文件,它抑制了两个已知包含数据争用的函数:

race:Function1
race:MyNamespace::Function2

要测试抑制文件,请设置TSAN_OPTIONS环境变量并调用应用程序(使用-fsanitize=thread编译):

$ TSAN_OPTIONS="suppressions=sanitizer-thread-suppressions.txt" ./myapp

如果可行,您可以在编译时应用设置:

-fsanitize=thread -fsanitize-blacklist=sanitizer-thread-suppressions.txt