Re: [PATCH v3 05/30] tools build: Append -fzero-init-padding-bits=all to extra cflags
From: Quentin Monnet
Date: Mon Mar 09 2026 - 06:18:19 EST
2026-03-08 16:46 UTC+0000 ~ Leo Yan <leo.yan@xxxxxxx>
> 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 by any version older than GCC 15, nor is it
> supported by LLVM. This patch adds the cc-option and host-cc-option
> functions to dynamically detect compiler option and append it to the
> EXTRA_CFLAGS and HOST_EXTRACFLAGS respectively.
>
> [1] https://gcc.gnu.org/gcc-15/changes.html
>
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
I can't speak for the maintainers of the other tools of course, but as
far as bpftool is concerned, this looks OK to me. Thanks for this work!
Acked-by: Quentin Monnet <qmo@xxxxxxxxxx>