public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE
@ 2026-03-27 21:59 Justin Stitt
  2026-03-27 22:18 ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: Justin Stitt @ 2026-03-27 21:59 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
	Bill Wendling
  Cc: Kees Cook, linux-kbuild, linux-kernel, llvm, Justin Stitt

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@google.com>
---
 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@google.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE
  2026-03-27 21:59 [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE Justin Stitt
@ 2026-03-27 22:18 ` Nathan Chancellor
  2026-03-27 22:29   ` Justin Stitt
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2026-03-27 22:18 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Kees Cook,
	linux-kbuild, linux-kernel, llvm

On Fri, Mar 27, 2026 at 02:59:20PM -0700, Justin Stitt wrote:
> 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@google.com>
> ---
>  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

While this is indeed particularly useful for CONFIG_FORTIFY_SOURCE, this
impacts the warning and error attributes, which can be used anywhere
(see __bad_copy_from() for example). Is this being wrapped due to the
potential compile time impact? Can we use something like hyperfine to
quantify it and see if the impact is worth the trade off of always
having it enabled for friendlier diagnostics? If not, maybe worth
adding a Kconfig option that is force selected by FORTIFY_SOURCE with
clang or can be optionally enabled by a user?

> +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@google.com>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE
  2026-03-27 22:18 ` Nathan Chancellor
@ 2026-03-27 22:29   ` Justin Stitt
  2026-03-30  3:59     ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Justin Stitt @ 2026-03-27 22:29 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Kees Cook,
	linux-kbuild, linux-kernel, llvm

Hi,

On Fri, Mar 27, 2026 at 3:18 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Fri, Mar 27, 2026 at 02:59:20PM -0700, Justin Stitt wrote:
> > 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@google.com>
> > ---
> >  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
>
> While this is indeed particularly useful for CONFIG_FORTIFY_SOURCE, this
> impacts the warning and error attributes, which can be used anywhere
> (see __bad_copy_from() for example). Is this being wrapped due to the
> potential compile time impact? Can we use something like hyperfine to
> quantify it and see if the impact is worth the trade off of always
> having it enabled for friendlier diagnostics?

The compile time impact is not measurable (within expected noise). The
peak memory usage may increase by somewhere in the 0.5% to 1.5% range
depending on build configuration.

I bundled this under fortify to limit initial impact as its had
virtually no real-world testing and may produce unhelpful diagnostic
notes under its heuristic mode. I don't expect folks to use `-g1` in
the kernel (which would enable full-proof diagnostic notes).

> If not, maybe worth adding a Kconfig option that is force selected by FORTIFY_SOURCE with
> clang or can be optionally enabled by a user?

I'll defer to you on this one. We could add
CONFIG_SHOW_INLINING_CHAIN_NOTES or something similar?

>
> > +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@google.com>
> >

Justin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE
  2026-03-27 22:29   ` Justin Stitt
@ 2026-03-30  3:59     ` Kees Cook
  2026-03-30  5:36       ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2026-03-30  3:59 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
	Bill Wendling, linux-kbuild, linux-kernel, llvm

On Fri, Mar 27, 2026 at 03:29:18PM -0700, Justin Stitt wrote:
> On Fri, Mar 27, 2026 at 3:18 PM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > On Fri, Mar 27, 2026 at 02:59:20PM -0700, Justin Stitt wrote:
> > > 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@google.com>
> > > ---
> > >  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
> >
> > While this is indeed particularly useful for CONFIG_FORTIFY_SOURCE, this
> > impacts the warning and error attributes, which can be used anywhere
> > (see __bad_copy_from() for example). Is this being wrapped due to the
> > potential compile time impact? Can we use something like hyperfine to
> > quantify it and see if the impact is worth the trade off of always
> > having it enabled for friendlier diagnostics?
> 
> The compile time impact is not measurable (within expected noise). The
> peak memory usage may increase by somewhere in the 0.5% to 1.5% range
> depending on build configuration.
> 
> I bundled this under fortify to limit initial impact as its had
> virtually no real-world testing and may produce unhelpful diagnostic
> notes under its heuristic mode. I don't expect folks to use `-g1` in
> the kernel (which would enable full-proof diagnostic notes).
> 
> > If not, maybe worth adding a Kconfig option that is force selected by FORTIFY_SOURCE with
> > clang or can be optionally enabled by a user?
> 
> I'll defer to you on this one. We could add
> CONFIG_SHOW_INLINING_CHAIN_NOTES or something similar?

I would prefer to just unconditionally enable this when it is supported.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE
  2026-03-30  3:59     ` Kees Cook
@ 2026-03-30  5:36       ` Nathan Chancellor
  0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2026-03-30  5:36 UTC (permalink / raw)
  To: Kees Cook
  Cc: Justin Stitt, Nicolas Schier, Nick Desaulniers, Bill Wendling,
	linux-kbuild, linux-kernel, llvm

On Sun, Mar 29, 2026 at 08:59:51PM -0700, Kees Cook wrote:
> On Fri, Mar 27, 2026 at 03:29:18PM -0700, Justin Stitt wrote:
> > On Fri, Mar 27, 2026 at 3:18 PM Nathan Chancellor <nathan@kernel.org> wrote:
> > The compile time impact is not measurable (within expected noise). The
> > peak memory usage may increase by somewhere in the 0.5% to 1.5% range
> > depending on build configuration.
> > 
> > I bundled this under fortify to limit initial impact as its had
> > virtually no real-world testing and may produce unhelpful diagnostic
> > notes under its heuristic mode. I don't expect folks to use `-g1` in
> > the kernel (which would enable full-proof diagnostic notes).
> > 
> > > If not, maybe worth adding a Kconfig option that is force selected by FORTIFY_SOURCE with
> > > clang or can be optionally enabled by a user?
> > 
> > I'll defer to you on this one. We could add
> > CONFIG_SHOW_INLINING_CHAIN_NOTES or something similar?
> 
> I would prefer to just unconditionally enable this when it is supported.

Agreed. It cannot possibly be worse than the status quo, right? :) This
feels very similar to -fdiagnostics-show-context=2, so maybe add it near
there?

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-30  5:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 21:59 [PATCH] kbuild: add -fdiagnostics-show-inlining-chain for FORTIFY_SOURCE Justin Stitt
2026-03-27 22:18 ` Nathan Chancellor
2026-03-27 22:29   ` Justin Stitt
2026-03-30  3:59     ` Kees Cook
2026-03-30  5:36       ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox