Re: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags

Leo Yan
2026-03-23T14:23:09Z

Hi Ian,

On Wed, Mar 18, 2026 at 09:38:43AM -0700, Ian Rogers wrote:

[...]

> > tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
> > diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> > index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..a2397ceae512c1bc54adb15cb1a111ff34e28e43 100644
> > --- a/tools/scripts/Makefile.include
> > +++ b/tools/scripts/Makefile.include
> > @@ -137,6 +137,36 @@ else
> > EXTRA_WARNINGS += -Wshadow
> > endif
> >
> > +# 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))
> > +
> > +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 }'
> > +FLAG_ZERO_INIT := $(call cc-option,-fzero-init-padding-bits=all)
> > +override EXTRA_CFLAGS += $(FLAG_ZERO_INIT)
>
> Sashiko [1] noted a possibly unintended consequence of this change for libbpf:
>
> Does this override unintentionally drop the default compiler flags for libbpf?
>
> Looking at tools/lib/bpf/Makefile, the default compiler flags like -g and -O2
> are only applied if EXTRA_CFLAGS is undefined:
>
> tools/lib/bpf/Makefile:
> ifndef EXTRA_CFLAGS
> EXTRA_CFLAGS := -g -O2
> endif
>
> Since tools/scripts/Makefile.include unconditionally appends to EXTRA_CFLAGS
> here, the variable will be defined before tools/lib/bpf/Makefile evaluates it.
>
> This causes libbpf to silently drop the default -g and -O2 flags.
>
> While later commits in this series fix this exact issue for
> tools/lib/thermal/Makefile, it appears tools/lib/bpf/Makefile was missed.

This is expected. As Alexei suggested, BPF patches should go via the bpf
tree and be sent separately [2]. As a result, the AI review has no full
context and misses the BPF pieces.

I will send a new series and a BPF/bpftool series separately. If AI still
complains this, I'd suggest we simply ignore this false positive.

Thanks,
Leo

[2] https://lore.kernel.org/linux-perf-users/CAADnVQLN6bYHnusnC5QnDoGGUO-A=qnM6fP9bhEVXEHD6_y9EQ@mail.gmail.com/#t