From 8870cd69edef9d9bc2c2aab6de6d140da241ba54 Mon Sep 17 00:00:00 2001 From: Vadim Mutilin Date: Wed, 6 Mar 2024 16:50:21 +0300 Subject: [PATCH] Enable TSAN Change-Id: I83fe9ba24aa12f56cf04370cc99e48cacbee86a1 Signed-off-by: Vadim Mutilin --- build/config/compiler/BUILD.gn | 5 +++++ build/config/sanitizers/sanitizers.gni | 2 ++ build/templates/cxx/cxx.gni | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 4613b124..e2df3804 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 effba924..4758bed9 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 00e33939..7bb8c885 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 = [] } -- Gitee