[PATCH 14/14] Makefile: enable Thread Safety Analysis
Carlos López
carlos.lopezr4096 at gmail.com
Wed Jul 29 09:35:41 PDT 2026
Now that all locking code has been properly annotated, enable clang's
Thread Safety Analysis.
Two flags are available, -Wthread-safety, and the more recent
-Wthread-safety-pointer. The former was introduced before clang gained
RISC-V support, so it is guaranteed to be available. The latter was
introduced in clang 21, so check if the provided compiler supports it
before enabling it.
Signed-off-by: Carlos López <carlos.lopezr4096 at gmail.com>
---
Makefile | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Makefile b/Makefile
index 37793aaf4fd6..51a4c7aec1bb 100644
--- a/Makefile
+++ b/Makefile
@@ -209,6 +209,9 @@ CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdl
# Check whether the assembler and the compiler support the Vector extension
CC_SUPPORT_VECTOR := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q riscv.*vector && echo y || echo n)
+# Check whether the compiler supports -Wthread-safety-pointer (clang >= 22)
+CC_SUPPORT_WTHREAD_SAFETY_POINTER := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -Wthread-safety-pointer -x c /dev/null -o /dev/null 2>&1 | grep -q "unknown warning" && echo n || echo y)
+
ifneq ($(OPENSBI_LD_PIE),y)
$(error Your linker does not support creating PIEs, opensbi requires this.)
endif
@@ -359,6 +362,10 @@ endif
ifeq ($(CC_IS_CLANG),y)
GENFLAGS += $(CLANG_TARGET)
GENFLAGS += -Wno-unused-command-line-argument
+GENFLAGS += -Wthread-safety
+ifeq ($(CC_SUPPORT_WTHREAD_SAFETY_POINTER),y)
+GENFLAGS += -Wthread-safety-pointer
+endif
endif
GENFLAGS += -I$(platform_src_dir)/include
GENFLAGS += -I$(include_dir)
--
2.51.0
More information about the opensbi
mailing list