c++ - ThreadSanitizer 的抑制文件不起作用 : What is wrong?

标签 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 库的所有警告。)

最佳答案

终于,我成功了。

根据documentation ,每行必须以有效的“suppression_type”开头(racethreadmutexsignal死锁,或called_from_lib)。

在我的示例中,正确的suppression_type是race

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

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

关于c++ - ThreadSanitizer 的抑制文件不起作用 : What is wrong?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19163477/

相关文章:

c++ - QImage 调整大小事件

c++ - 如何使我的依赖项调用我的全局运算符 new?

c++ - 删除与删除[]

C++ 将 32 位整数复制到字节数组

c++ - 内联静态数据的初始化

android - Clang 链接 .so 库 libc++_shared.so

c++ - 为什么没有 std::stou?

gcc - 有没有办法单独输出单个函数的程序集?

macos - 铿锵 5.1 fpmath

c++ - 关于C++类定义的问题 ": 1"