From: Kees Cook <kees@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Leo Yan <leo.yan@arm.com>, Nicolas Schier <nsc@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
Namhyung Kim <namhyung@kernel.org>,
James Clark <james.clark@linaro.org>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH RESEND v2] tools build: Use -fzero-init-padding-bits=all
Date: Tue, 24 Feb 2026 13:11:19 -0800 [thread overview]
Message-ID: <202602241310.C3641B97@keescook> (raw)
In-Reply-To: <20260224171956.GA639152@ax162>
On Tue, Feb 24, 2026 at 10:19:56AM -0700, Nathan Chancellor wrote:
> Hi Leo,
>
> On Tue, Feb 24, 2026 at 12:16:40PM +0000, Leo Yan wrote:
> > GCC-15 release claims [1]:
> >
> > {0} initializer in C or C++ for unions no longer guarantees clearing
> > of the whole union (except for static storage duration initialization),
> > it just initializes the first union member to zero. If initialization
> > of the whole union including padding bits is desirable, use {} (valid
> > in C23 or C++) or use -fzero-init-padding-bits=unions option to
> > restore old GCC behavior.
> >
> > As a result, this new behaviour might cause unexpected data when we
> > initialize a union with using the '{ 0 }' initializer.
> >
> > Since commit dce4aab8441d ("kbuild: Use -fzero-init-padding-bits=all"),
> > the kernel has enabled -fzero-init-padding-bits=all to zero padding bits
> > in unions and structures. This commit applies the same option for tools
> > building.
> >
> > The option is not supported neither by any version older than GCC 15 and
> > is also not supported by LLVM, this patch adds the cc-option function to
> > dynamically detect the compiler option.
> >
> > [1] https://gcc.gnu.org/gcc-15/changes.html
> >
> > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > ---
> > Resent to linux-kbuild mailing list.
>
> Kbuild does not maintain/touch tools/. This should go via another tree
> like perf or something. It does not look like
> tools/scripts/Makefile.include has a clear owner, perf and bpf tend to
> be the ones who touch it the most.
You could claim it! ;)
Regardless, I like to see cc-option available here, as I doubt this will
be the last conditional option for tool builds. (Actually, are there
other conditional options that could use this today in the tools
Makefiles?)
-Kees
>
> > ---
> > tools/scripts/Makefile.include | 24 ++++++++++++++++++++++++
> > 1 file changed, 24 insertions(+)
> >
> > diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> > index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..73f6aef4f3fda0cda7ee8f4b9a3b7ff7d956070d 100644
> > --- a/tools/scripts/Makefile.include
> > +++ b/tools/scripts/Makefile.include
> > @@ -40,6 +40,30 @@ EXTRA_WARNINGS += -Wwrite-strings
> > EXTRA_WARNINGS += -Wformat
> > EXTRA_WARNINGS += -Wno-type-limits
> >
> > +# output directory for tests below
> > +TMPOUT = .tmp_$$$$
> > +
> > +# try-run
> > +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
> > +# Exit code chooses option. "$$TMP" serves as a temporary file and is
> > +# automatically cleaned up.
> > +try-run = $(shell set -e; \
> > + TMP=$(TMPOUT)/tmp; \
> > + trap "rm -rf $(TMPOUT)" EXIT; \
> > + mkdir -p $(TMPOUT); \
> > + if ($(1)) >/dev/null 2>&1; \
> > + then echo "$(2)"; \
> > + else echo "$(3)"; \
> > + fi)
> > +
> > +# cc-option
> > +# Usage: CFLAGS += $(call cc-option,-march=winchip-c6,-march=i586)
> > +cc-option = $(call try-run, \
> > + $(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> > +
> > +# Explicitly clear padding bits with the initializer '{ 0 }'
> > +CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
> > +
> > # Makefiles suck: This macro sets a default value of $(2) for the
> > # variable named by $(1), unless the variable has been set by
> > # environment or command line. This is necessary for CC and AR
> >
> > ---
> > base-commit: 7dff99b354601dd01829e1511711846e04340a69
> > change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b
> >
> > Best regards,
> > --
> > Leo Yan <leo.yan@arm.com>
> >
--
Kees Cook
next prev parent reply other threads:[~2026-02-24 21:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 12:16 [PATCH RESEND v2] tools build: Use -fzero-init-padding-bits=all Leo Yan
2026-02-24 17:19 ` Nathan Chancellor
2026-02-24 21:11 ` Kees Cook [this message]
2026-02-25 9:22 ` Leo Yan
2026-02-25 19:25 ` Nathan Chancellor
2026-02-26 18:33 ` Namhyung Kim
2026-02-26 18:38 ` Namhyung Kim
2026-02-26 22:52 ` Quentin Monnet
2026-02-27 10:36 ` Leo Yan
2026-02-27 11:52 ` Quentin Monnet
2026-03-04 1:14 ` Namhyung Kim
2026-03-04 1:28 ` Quentin Monnet
2026-03-04 1:35 ` Namhyung Kim
2026-03-04 9:23 ` Leo Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202602241310.C3641B97@keescook \
--to=kees@kernel.org \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=justinstitt@google.com \
--cc=leo.yan@arm.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nsc@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox