[PATCH v3 00/30] tools build: Append -fzero-init-padding-bits=all option
From: Leo Yan
Date: Sun Mar 08 2026 - 12:46:57 EST
GCC-15 doesn't guarantee that a {0} initializer clears the whole union [1].
This may cause bugs if data is not intialized properly.
The kernel enabld the -fzero-init-padding-bits=all option to tackle the
issue, which was merged in commit dce4aab8441d ("kbuild: Use
-fzero-init-padding-bits=all").
This series propagates the same flag to the tools build. It uses
tools/scripts/Makefile.include as the central place to add the
option to EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC
compilers. Each project under tools/ appends the variables as needed.
The variable name HOST_EXTRACFLAGS comes from kbuild conventions (see
Documentation/kbuild/makefiles.rst).
This series is divided into three parts:
Patches 01 – 04: Preparation before adding the new compiler option.
These patches adjust Makefiles to ensure the newly
introduced option does not cause regressions.
Patch 05: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGS and HOST_EXTRACFLAGS for the
CC and HOSTCC compilers, respectively.
Patches 06 – 30: Apply EXTRA_CFLAGS and HOST_EXTRACFLAGS in
project Makefiles.
The change has been verified:
Test 1: cross compiling perf with aarch64 GCC-15.2 [2]:
ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- \
make LDFLAGS="-static" -C tools/perf VF=1 NO_JEVENTS=1 \
DEBUG=1 V=1 NO_LIBELF=1 NO_LIBTRACEEVENT=1
Test 2: native selftest build on Arm64 machine:
make -C tools/testing/selftests TARGETS=hid SKIP_TARGETS="" V=1
[1] https://gcc.gnu.org/gcc-15/changes.html
[2] https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
Changes in v3:
- Extended to support cross compilation (Quentin).
- Link to v2: https://lore.kernel.org/r/20260224-tools_build_fix_zero_init-v2-1-b1acc817a01e@xxxxxxx
---
Leo Yan (30):
bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
libbpf: Initialize CFLAGS before including Makefile.include
tools: lib: thermal: Initialize CFLAGS before including Makefile.include
tools/thermal: Initialize CFLAGS before including Makefile.include
tools build: Append -fzero-init-padding-bits=all to extra cflags
bpftool: Append extra host flags
perf build: Append extra host flags
tools/bpf: build: Append extra cflags
tools build: Append extra host cflags
tools build: Append extra cflags for feature
tools: bootconfig: Append extra cflags
tools: counter: Append extra cflags
tools: dma: Append extra cflags
tools: gpio: Append extra cflags
tools: hv: Append extra cflags
tools: iio: Append extra cflags
tools: mm: Append extra cflags
tools: nolibc: Append extra cflags
tools: objtool: Append extra host cflags
tools: power: acpi: Append extra cflags
tools: power: x86/intel-speed-select: Append extra cflags
tools: sched_ext: Append extra cflags
tools: spi: Append extra cflags
tools: tracing: Append extra cflags
tools: usb: Append extra cflags
tools: verification: Append extra cflags
selftests/bpf: Append extra cflags
selftests/hid: Append extra cflags
selftests/nolibc: Append extra cflags
selftests/sched_ext: Append extra cflags
tools/bootconfig/Makefile | 1 +
tools/bpf/Makefile | 1 +
tools/bpf/bpftool/Makefile | 9 +++++++--
tools/build/Makefile | 6 ++++--
tools/build/feature/Makefile | 2 ++
tools/counter/Makefile | 1 +
tools/dma/Makefile | 1 +
tools/gpio/Makefile | 1 +
tools/hv/Makefile | 1 +
tools/iio/Makefile | 1 +
tools/include/nolibc/Makefile | 2 +-
tools/lib/bpf/Makefile | 16 ++++++++-------
tools/lib/thermal/Makefile | 16 ++++++++-------
tools/mm/Makefile | 1 +
tools/objtool/Makefile | 2 ++
tools/perf/Makefile.config | 2 +-
tools/power/acpi/Makefile.config | 1 +
tools/power/x86/intel-speed-select/Makefile | 1 +
tools/sched_ext/Makefile | 1 +
tools/scripts/Makefile.include | 28 ++++++++++++++++++++++++++
tools/spi/Makefile | 1 +
tools/testing/selftests/bpf/Makefile | 1 +
tools/testing/selftests/hid/Makefile | 1 +
tools/testing/selftests/nolibc/Makefile.nolibc | 3 +++
tools/testing/selftests/sched_ext/Makefile | 1 +
tools/thermal/lib/Makefile | 16 ++++++++-------
tools/tracing/latency/Makefile | 1 +
tools/usb/Makefile | 1 +
tools/verification/rv/Makefile | 1 +
29 files changed, 93 insertions(+), 27 deletions(-)
---
base-commit: 4ae12d8bd9a830799db335ee661d6cbc6597f838
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b
Best regards,
--
Leo Yan <leo.yan@xxxxxxx>