Skip to content

Commit

Permalink
Make clang thread safety analysis configurable. (#26422)
Browse files Browse the repository at this point in the history
* Make clang thread safety analysis configurable.

Depending on CLANG version used, thread safety analysis may not
be available. Found this when OSS-FUZZ tests were failing.

This CL adds a `chip_enable_thread_safety_checks` flag to turn these
checks on/off and defaults them to on when the compiler is clang.

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Jan 9, 2024
1 parent 22b2f13 commit 2599017
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni")
import("//build_overrides/nlassert.gni")
import("//build_overrides/nlfaultinjection.gni")

import("${build_root}/config/compiler/compiler.gni")
import("${chip_root}/build/chip/buildconfig_header.gni")
import("${chip_root}/build/chip/tests.gni")
import("${chip_root}/src/platform/device.gni")
Expand All @@ -32,6 +33,12 @@ declare_args() {

# Extra include dirs for project configs.
chip_project_config_include_dirs = []

# enable clang thread safety analysis in SystemMutex.h,
# specifically attributes such as capability, guarded_by, acquire, ...
#
# see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
chip_enable_thread_safety_checks = is_clang
}

if (chip_project_config_include_dirs == [] &&
Expand Down Expand Up @@ -117,6 +124,9 @@ buildconfig_header("system_buildconfig") {
"SYSTEM_PLATFORM_CONFIG_INCLUDE=${chip_system_platform_config_include}",
]
}
if (chip_enable_thread_safety_checks) {
defines += [ "SYSTEM_ENABLE_CLANG_THREAD_SAFETY_ANALYSIS=1" ]
}

if (chip_system_layer_impl_config_file != "") {
defines += [ "CHIP_SYSTEM_LAYER_IMPL_CONFIG_FILE=${chip_system_layer_impl_config_file}" ]
Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace chip {
namespace System {

// Enable thread safety attributes only with clang.
#if defined(__clang__) && (!defined(SWIG))
#if defined(SYSTEM_ENABLE_CLANG_THREAD_SAFETY_ANALYSIS) && (!defined(SWIG))
#define CHIP_TSA_ATTRIBUTE__(x) __attribute__((x))
#else
#define CHIP_TSA_ATTRIBUTE__(x)
Expand Down

0 comments on commit 2599017

Please sign in to comment.