Makefile: enable Thread Safety Analysis

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@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260909162322.29778-16-carlos.lopezr4096@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Carlos López
2026-09-16 09:48:30 +05:30
committed by Anup Patel
parent 92b24d6acb
commit 9476b78361
+7
View File
@@ -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)