1 tsan概念
可参考相应官网:https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual
2 bazel相应配置文件编写
build --action_env=BAZEL_LINKLIBS=-l%:libstdc++.a
build --action_env=BAZEL_LINKOPTS="-static-libstdc++:-lm"
build --action_env=CC
build --action_env=CXX
build --action_env=PATH
build --copt="-DENVOY_IGNORE_GLIBCXX_USE_CXX11_ABI_ERROR=1"
build --cxxopt="-std=c++17"
build --copt="-fPIC"
build --copt="-pie"
build:tsan --copt -fsanitize=thread
build:tsan --linkopt -fsanitize=thread
3 构建程序
如出现如下错误:
/opt/rh/devtoolset-8/root/usr/bin/ld.gold: error: cannot find -ltsan
则可参考:https://github.com/google/sanitizers/issues/695
解决方案为:在Centos系统上运行如下命令
sudo yum install devtoolset-8-libtsan-devel
libtsan.so下载地址:libtsan-8.4.1-2.1.el8.x86_64 RPM