|
|
Log in / Subscribe / Register

tools build: Append -fzero-init-padding-bits=all option

From:  Leo Yan <leo.yan-AT-arm.com>
To:  Arnaldo Carvalho de Melo <acme-AT-kernel.org>, Ian Rogers <irogers-AT-google.com>, Namhyung Kim <namhyung-AT-kernel.org>, James Clark <james.clark-AT-linaro.org>, Kees Cook <kees-AT-kernel.org>, Quentin Monnet <qmo-AT-kernel.org>, Nathan Chancellor <nathan-AT-kernel.org>, Nicolas Schier <nsc-AT-kernel.org>, Nick Desaulniers <nick.desaulniers+lkml-AT-gmail.com>, Bill Wendling <morbo-AT-google.com>, Justin Stitt <justinstitt-AT-google.com>, Alexei Starovoitov <ast-AT-kernel.org>, Daniel Borkmann <daniel-AT-iogearbox.net>, Andrii Nakryiko <andrii-AT-kernel.org>, Martin KaFai Lau <martin.lau-AT-linux.dev>, Eduard Zingerman <eddyz87-AT-gmail.com>, Song Liu <song-AT-kernel.org>, Yonghong Song <yonghong.song-AT-linux.dev>, John Fastabend <john.fastabend-AT-gmail.com>, KP Singh <kpsingh-AT-kernel.org>, Stanislav Fomichev <sdf-AT-fomichev.me>, Hao Luo <haoluo-AT-google.com>, Jiri Olsa <jolsa-AT-kernel.org>, "Rafael J. Wysocki" <rafael-AT-kernel.org>, Daniel Lezcano <daniel.lezcano-AT-kernel.org>, Zhang Rui <rui.zhang-AT-intel.com>, Lukasz Luba <lukasz.luba-AT-arm.com>, Peter Zijlstra <peterz-AT-infradead.org>, Ingo Molnar <mingo-AT-redhat.com>, Mark Rutland <mark.rutland-AT-arm.com>, Alexander Shishkin <alexander.shishkin-AT-linux.intel.com>, Adrian Hunter <adrian.hunter-AT-intel.com>, Masami Hiramatsu <mhiramat-AT-kernel.org>, William Breathitt Gray <wbg-AT-kernel.org>, Barry Song <baohua-AT-kernel.org>, Qinxin Xia <xiaqinxin-AT-huawei.com>, Bartosz Golaszewski <brgl-AT-kernel.org>, Kent Gibson <warthog618-AT-gmail.com>, "K. Y. Srinivasan" <kys-AT-microsoft.com>, Haiyang Zhang <haiyangz-AT-microsoft.com>, Wei Liu <wei.liu-AT-kernel.org>, Dexuan Cui <decui-AT-microsoft.com>, Long Li <longli-AT-microsoft.com>, Jonathan Cameron <jic23-AT-kernel.org>, David Lechner <dlechner-AT-baylibre.com>, Nuno Sá <nuno.sa-AT-analog.com>, Andy Shevchenko <andy-AT-kernel.org>, Andrew Morton <akpm-AT-linux-foundation.org>, Willy Tarreau <w-AT-1wt.eu>, Thomas Weißschuh <linux-AT-weissschuh.net>, Josh Poimboeuf <jpoimboe-AT-kernel.org>, Robert Moore <robert.moore-AT-intel.com>, Len Brown <lenb-AT-kernel.org>, Srinivas Pandruvada <srinivas.pandruvada-AT-linux.intel.com>, Tejun Heo <tj-AT-kernel.org>, David Vernet <void-AT-manifault.com>, Andrea Righi <arighi-AT-nvidia.com>, Changwoo Min <changwoo-AT-igalia.com>, Mark Brown <broonie-AT-kernel.org>, Steven Rostedt <rostedt-AT-goodmis.org>, Gabriele Monaco <gmonaco-AT-redhat.com>, Shuah Khan <shuah-AT-kernel.org>, Jiri Kosina <jikos-AT-kernel.org>, Benjamin Tissoires <bentiss-AT-kernel.org>
Subject:  [PATCH v7 00/23] tools build: Append -fzero-init-padding-bits=all option
Date:  Tue, 02 Jun 2026 15:40:34 +0100
Message-ID:  <20260602-tools_build_fix_zero_init-v7-0-631baf679fe7@arm.com>
Cc:  linux-kbuild-AT-vger.kernel.org, linux-kernel-AT-vger.kernel.org, linux-perf-users-AT-vger.kernel.org, Leo Yan <leo.yan-AT-arm.com>, Bartosz Golaszewski <bartosz.golaszewski-AT-oss.qualcomm.com>, Jonathan Cameron <jic23-AT-kernel.org>
Archive-link:  Article

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.

BPF/bpftool related patches will be sent separately, as maintainers
prefer them to go via the BPF tree.

The changes are organized into three parts:

  Patches 01 – 04: Fixes for thermal build.
  Patch 05:        Rename to cross-cc-option so the function name
                   cc-option can be reserved for using globally.
  Patch 06:        Propagate -fzero-init-padding-bits=all to
                   EXTRA_CFLAGS and HOST_EXTRACFLAGS for the
                   CC and HOSTCC compilers, respectively.
  Patches 07 – 23: Apply EXTRA_CFLAGS and HOST_EXTRACFLAGS in
                   project Makefiles.

The change has been verified:

Test 1: Cross compiling perf (rebased on perf-tools-next)
	host: gcc 15.2.0 (x86_64), target: aarch64-linux-gnu-gcc

  make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LDFLAGS="-static" \
	    -C tools/perf VF=1 CORESIGHT=1 NO_JEVENTS=1 DEBUG=1

Test 2: Cross compiling selftest bpf and sched_ext
	host: gcc 15.2.0 (x86_64), target: aarch64-linux-gnu-gcc

  export ARCH=arm64
  export CROSS_COMPILE=aarch64-linux-gnu-
  make -C tools/testing/selftests/ TARGETS="bpf sched_ext" SKIP_TARGETS=""

Test 3: BPF CI test (BPF patches will be sent separately)

  https://github.com/kernel-patches/bpf/actions/runs/268151...

[1] https://gcc.gnu.org/gcc-15/changes.html

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v7:
- Appended $(EXTRA_CFLAGS) in tracing/rtla/Makefile.
- Refactored testing/selftests/lib.mk to include Makefile.include, as
  the $(EXTRA_CFLAGS) can be applied globally for selftest, dropped the
  patches for selftests/hid, selftests/nolibc and selftests/sched_ext.
- Link to v6: https://lore.kernel.org/r/20260323-tools_build_fix_zero_i...

Changes in v6:
- Gathered Acked tags (thanks Jonathan!)
- Left out bpftool patches and will send together with other BPF patches (Quentin)
- Added back complete info in cover (Peter.Z)
- Link to v5: https://lore.kernel.org/r/20260318-tools_build_fix_zero_i...

Changes in v5:
- Gathered Acked tags (thanks Daniel, Namhyung, Benjamin!)
- Appended HOST_EXTRACFLAGS after KBUILD_HOSTCFLAGS (Ian)
- Appended CFLAGS for libc-test (Thomas)
- Left out BPF patches and will send out separately (Alexei)
- Rebase on v7.0.0-rc4
- Link to v4: https://lore.kernel.org/r/20260311-tools_build_fix_zero_i...

---
Leo Yan (23):
      tools: lib: thermal: Fix typo
      tools/thermal: Fix typo
      tools: lib: thermal: Initialize CFLAGS before including Makefile.include
      tools/thermal: Initialize CFLAGS before including Makefile.include
      selftests/nolibc: Use a dedicated cross cc-option helper
      tools build: Append -fzero-init-padding-bits=all to extra cflags
      perf build: Append extra host flags
      tools build: Append extra host CFLAGS for fixdep
      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: 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
      selftests: Include tools Makefile.include

 tools/bootconfig/Makefile                      |  1 +
 tools/build/Makefile                           |  8 ++++---
 tools/counter/Makefile                         |  1 +
 tools/dma/Makefile                             |  1 +
 tools/gpio/Makefile                            |  1 +
 tools/hv/Makefile                              |  1 +
 tools/iio/Makefile                             |  1 +
 tools/lib/thermal/Makefile                     | 20 +++++++++--------
 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                 | 30 ++++++++++++++++++++++++++
 tools/spi/Makefile                             |  1 +
 tools/testing/selftests/lib.mk                 | 30 +++++++++++++-------------
 tools/testing/selftests/nolibc/Makefile.nolibc | 12 +++++------
 tools/thermal/lib/Makefile                     | 20 +++++++++--------
 tools/tracing/latency/Makefile                 |  1 +
 tools/tracing/rtla/Makefile                    |  1 +
 tools/usb/Makefile                             |  1 +
 22 files changed, 95 insertions(+), 43 deletions(-)
---
base-commit: 6f3ed7fec72fc8979b2a8c7219c0a9fcfc8d07b5
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b

Best regards,
-- 
Leo Yan <leo.yan@arm.com>




Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds