diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 4613b124033505670bea4e2ac0a0b0479efb0358..e2df380438608442b7451f98abe91b8c392656ad 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -315,6 +315,11 @@ config("compiler") { if (is_linux) { cflags += [ "-pthread" ] + if (is_tsan) { + cflags += [ "-fsanitize=thread" ] + ldflags += [ "-fsanitize=thread" ] + } + # Do not use the -pthread ldflag here since it becomes a no-op # when using -nodefaultlibs, which would cause an unused argument # error. "-lpthread" is added in $build_root/config:default_libs. diff --git a/build/config/sanitizers/sanitizers.gni b/build/config/sanitizers/sanitizers.gni index effba924bb58361d2692125246431d8470e0e749..4758bed967645b7cfd8628fdcd143229dbf731e5 100644 --- a/build/config/sanitizers/sanitizers.gni +++ b/build/config/sanitizers/sanitizers.gni @@ -14,6 +14,8 @@ declare_args() { is_asan = false + is_tsan = false + is_ubsan_vptr = false is_safestack = false diff --git a/build/templates/cxx/cxx.gni b/build/templates/cxx/cxx.gni index 00e3393901968a975822879fd5635cca26127230..7bb8c8859ece76b79f095757d26e29b289ae6867 100755 --- a/build/templates/cxx/cxx.gni +++ b/build/templates/cxx/cxx.gni @@ -72,6 +72,11 @@ template("ohos_executable") { if (!defined(ldflags)) { ldflags = [] } + + if (defined(is_tsan) && is_tsan) { + ldflags += [ "-fsanitize=thread" ] + } + if (!defined(inputs)) { inputs = [] } @@ -161,6 +166,12 @@ template("ohos_static_library") { ldflags = [] } + if (!defined(ldflags)) { + ldflags = [] + } + if (defined(is_tsan) && is_tsan) { + ldflags += [ "-fsanitize=thread" ] + } if (defined(invoker.use_rtti) && invoker.use_rtti) { configs += [ "//arkcompiler/toolchain/build/config/compiler:rtti" ] } @@ -240,6 +251,9 @@ template("ohos_shared_library") { if (!defined(ldflags)) { ldflags = [] } + if (defined(is_tsan) && is_tsan) { + ldflags += [ "-fsanitize=thread" ] + } if (!defined(inputs)) { inputs = [] }