[PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE

From: Justin Stitt

Date: Fri Mar 27 2026 - 17:59:32 EST


Clang recently added -fdiagnostics-show-inlining-chain [1] to improve
the visibility of inlining chains in diagnostics. This is particularly
useful for CONFIG_FORTIFY_SOURCE where detections can happen deep in
inlined functions.

Add this flag to KBUILD_CFLAGS when CONFIG_FORTIFY_SOURCE is enabled
and the compiler supports it.

Link: https://github.com/llvm/llvm-project/pull/174892 [1]
Link: https://github.com/ClangBuiltLinux/linux/issues/1571
Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
---
Makefile | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/Makefile b/Makefile
index e1279c4d5b24..978726aeb1ef 100644
--- a/Makefile
+++ b/Makefile
@@ -973,6 +973,12 @@ KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
# Get details on warnings generated due to GCC value tracking.
KBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-context=2)

+# Show inlining chain notes for FORTIFY_SOURCE-related diagnostics.
+# GCC does this by default while Clang 23+ supports a flag.
+ifdef CONFIG_FORTIFY_SOURCE
+KBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-inlining-chain)
+endif
+
# Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
ifdef CONFIG_ZERO_CALL_USED_REGS
KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr

---
base-commit: 7df48e36313029e4c0907b2023905dd7213fd678
change-id: 20260327-kbuild-show-inlining-557d31d2293a

Best regards,
--
Justin Stitt <justinstitt@xxxxxxxxxx>