Re: [PATCH RESEND v2] tools build: Use -fzero-init-padding-bits=all
From: Leo Yan
Date: Wed Feb 25 2026 - 04:25:46 EST
On Tue, Feb 24, 2026 at 01:11:19PM -0800, Kees Cook wrote:
> 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@xxxxxxx>
> > > ---
> > > 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.
This is a circular deadlock. Namhyung (the perf maintainer) advised me
to send patch to the linux-kbuild [1], for fixing an union init issue
found recently.
> 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?)
Some subprojects in tools have their own conditional options.
This patch is ambitious that it changes the global Makefile.include file
so it can propagate the '-fzero-init-padding-bits=all' option to
projects that include it. Why do we need to do this globally? This is
because Perf needs to build several subprojects (libperf and bpftool).
Thanks,
Leo
[1] https://lore.kernel.org/linux-perf-users/20260224122054.GB4184494@xxxxxxxxxxxxxxx/T/#ma07fc114e84254d0173490409955e9d3bea147be