public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	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>,
	James Clark <james.clark@linaro.org>, Kees Cook <kees@kernel.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH RESEND v2] tools build: Use -fzero-init-padding-bits=all
Date: Fri, 27 Feb 2026 11:52:38 +0000	[thread overview]
Message-ID: <c886c8c9-d336-4ec3-94c0-c4869dee7e7f@kernel.org> (raw)
In-Reply-To: <20260227103611.GA1098637@e132581.arm.com>

2026-02-27 10:36 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> On Thu, Feb 26, 2026 at 10:52:01PM +0000, Quentin Monnet wrote:
>> 2026-02-26 10:38 UTC-0800 ~ Namhyung Kim <namhyung@kernel.org>
>>> Adding bpftool maintainer.
>>>
>>> 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>
>>
>>
>> Thank you Namhyung for the Cc.
>>
>> I built bpftool with the patch, with gcc 13 (which didn't get the flag,
>> as expected) and gcc 15, and it's fine with both. As far as I can tell,
>> bpftool does not initialise any union with "{0}" anyway.
> 
> Thanks a lot for testing!
> 
>> One potential concern (I didn't try) could be for cross-compilation:
>> bpftool's Makefile sets HOST_CFLAGS based on $(CFLAGS), but $(HOSTCC)
>> and $(CC) could be different versions of gcc, for example.
> 
> To avoid confusion, we can use EXTRA_CFLAGS and HOST_EXTRACFLAGS instead
> in Makefile.include:
> 
> -----
> 
> # 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))
> 
> host-cc-option = $(call try-run, \
>        $(HOSTCC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> 
> # Explicitly clear padding bits with the initializer '{ 0 }'
> EXTRA_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
> HOST_EXTRACFLAGS += $(call host-cc-option,-fzero-init-padding-bits=all)
> 
> -----
> 
> Then, in a project, its Makefile can append EXTRA_CFLAGS and
> HOST_EXTRACFLAGS to CFLAGS and HOSTCFLAGS respectively.


This sounds like it should work for bpftool as long as we += and don't
overwrite the EXTRA_CFLAGS passed from command line. In bpftool's
Makefile we'd have to move HOST_CFLAGS's CFLAGS-based defintion higher
up, before we add the EXTRA_CFLAGS to CFLAGS; and if anything needs to
be passed to the host binary, users will have to specify
HOST_EXTRACFLAGS (or HOST_EXTRA_CFLAGS?) independently, which is acceptable.

Out of curiosity I looked at other tools, and of course everyone does it
differently:

- Some of them, like bpftool, reuse the CFLAGS inherited from
tools/scripts/Makefile.include, adding EXTRA_CFLAGS to it, so setting
aside cross-compiling, both approaches (using CFLAGS or EXTRA_CFLAGS)
are fine.

- Some of them, such as tools/lib/bpf/Makefile for example, reset CFLAGS
before/by adding EXTRA_CFLAGS, so your v2 relying on CFLAGS would
probably have no effect for them.

- Some of them, such as tools/tracing/latency/Makefile or
tools/mm/Makefile, do not use EXTRA_CFLAGS - maybe it's worth adding it
if your objective is to pass the flag to all/most tools.

- (Also many smaller Makefiles such as most of the ones in selftests do
not pull tools/scripts/Makefile.include at all, but I suppose this is
out of scope.)


> If this is fine for us, I will repin patches
> 
>> The same concern could apply to perf with HOSTCFLAGS, by the way?
> 
> I don't see perf's HOSTCFLAGS to reuse CFLAGS.


Woops I can't see the HOSTCFLAGS using the CFLAGS either for perf, sorry
about that.

Thanks,
Quentin

  reply	other threads:[~2026-02-27 11:52 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
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 [this message]
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=c886c8c9-d336-4ec3-94c0-c4869dee7e7f@kernel.org \
    --to=qmo@kernel.org \
    --cc=acme@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --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