From 9476b7836114b9c873ceda1452e7b486afd6d5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Wed, 9 Sep 2026 18:23:23 +0200 Subject: [PATCH] Makefile: enable Thread Safety Analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260909162322.29778-16-carlos.lopezr4096@gmail.com Signed-off-by: Anup Patel --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index aebaa98c..1b3333f3 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)