From: Leo Yan <leo.yan@arm.com>
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>,
"Ian Rogers" <irogers@google.com>,
"Namhyung Kim" <namhyung@kernel.org>,
"James Clark" <james.clark@linaro.org>,
"Kees Cook" <kees@kernel.org>, "Quentin Monnet" <qmo@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>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Daniel Lezcano" <daniel.lezcano@kernel.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Lukasz Luba" <lukasz.luba@arm.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"William Breathitt Gray" <wbg@kernel.org>,
"Barry Song" <baohua@kernel.org>,
"Qinxin Xia" <xiaqinxin@huawei.com>,
"Bartosz Golaszewski" <brgl@kernel.org>,
"Kent Gibson" <warthog618@gmail.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
"Haiyang Zhang" <haiyangz@microsoft.com>,
"Wei Liu" <wei.liu@kernel.org>,
"Dexuan Cui" <decui@microsoft.com>,
"Long Li" <longli@microsoft.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Willy Tarreau" <w@1wt.eu>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Robert Moore" <robert.moore@intel.com>,
"Len Brown" <lenb@kernel.org>,
"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Tejun Heo" <tj@kernel.org>, "David Vernet" <void@manifault.com>,
"Andrea Righi" <arighi@nvidia.com>,
"Changwoo Min" <changwoo@igalia.com>,
"Mark Brown" <broonie@kernel.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Gabriele Monaco" <gmonaco@redhat.com>,
"Shuah Khan" <shuah@kernel.org>, "Jiri Kosina" <jikos@kernel.org>,
"Benjamin Tissoires" <bentiss@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, bpf@vger.kernel.org,
linux-perf-users@vger.kernel.org, Leo Yan <leo.yan@arm.com>
Subject: [PATCH v3 05/30] tools build: Append -fzero-init-padding-bits=all to extra cflags
Date: Sun, 08 Mar 2026 16:46:10 +0000 [thread overview]
Message-ID: <20260308-tools_build_fix_zero_init-v3-5-6477808123b7@arm.com> (raw)
In-Reply-To: <20260308-tools_build_fix_zero_init-v3-0-6477808123b7@arm.com>
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@arm.com>
---
tools/scripts/Makefile.include | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..bab3174565f0d1e40ec574a360a0fddcee641f7e 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -137,6 +137,34 @@ 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 }'
+override EXTRA_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
+override HOST_EXTRACFLAGS += $(call host-cc-option,-fzero-init-padding-bits=all)
+
ifneq ($(findstring $(MAKEFLAGS), w),w)
PRINT_DIR = --no-print-directory
else
--
2.34.1
next prev parent reply other threads:[~2026-03-08 16:47 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 16:46 [PATCH v3 00/30] tools build: Append -fzero-init-padding-bits=all option Leo Yan
2026-03-08 16:46 ` [PATCH v3 01/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS Leo Yan
2026-03-09 10:17 ` Quentin Monnet
2026-03-09 17:40 ` Ian Rogers
2026-03-09 17:51 ` Quentin Monnet
2026-03-08 16:46 ` [PATCH v3 02/30] libbpf: Initialize CFLAGS before including Makefile.include Leo Yan
2026-03-09 17:03 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 03/30] tools: lib: thermal: " Leo Yan
2026-03-09 15:10 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 04/30] tools/thermal: " Leo Yan
2026-03-09 8:41 ` Daniel Lezcano
2026-03-09 10:07 ` Leo Yan
2026-03-10 12:00 ` Daniel Lezcano
2026-03-08 16:46 ` Leo Yan [this message]
2026-03-09 10:17 ` [PATCH v3 05/30] tools build: Append -fzero-init-padding-bits=all to extra cflags Quentin Monnet
2026-03-09 17:17 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 06/30] bpftool: Append extra host flags Leo Yan
2026-03-09 10:17 ` Quentin Monnet
2026-03-08 16:46 ` [PATCH v3 07/30] perf build: " Leo Yan
2026-03-08 16:46 ` [PATCH v3 08/30] tools/bpf: build: Append extra cflags Leo Yan
2026-03-09 17:42 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 09/30] tools build: Append extra host cflags Leo Yan
2026-03-08 16:46 ` [PATCH v3 10/30] tools build: Append extra cflags for feature Leo Yan
2026-03-09 17:51 ` Ian Rogers
2026-03-10 14:25 ` Leo Yan
2026-03-08 16:46 ` [PATCH v3 11/30] tools: bootconfig: Append extra cflags Leo Yan
2026-03-09 12:22 ` Masami Hiramatsu
2026-03-09 17:53 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 12/30] tools: counter: " Leo Yan
2026-03-09 17:55 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 13/30] tools: dma: " Leo Yan
2026-03-09 12:08 ` Qinxin Xia
2026-03-09 17:56 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 14/30] tools: gpio: " Leo Yan
2026-03-09 8:54 ` Bartosz Golaszewski
2026-03-09 17:57 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 15/30] tools: hv: " Leo Yan
2026-03-08 20:28 ` [EXTERNAL] " Haiyang Zhang
2026-03-09 17:58 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 16/30] tools: iio: " Leo Yan
2026-03-09 17:58 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 17/30] tools: mm: " Leo Yan
2026-03-09 17:59 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 18/30] tools: nolibc: " Leo Yan
2026-03-09 22:20 ` Thomas Weißschuh
2026-03-08 16:46 ` [PATCH v3 19/30] tools: objtool: Append extra host cflags Leo Yan
2026-03-09 20:19 ` Josh Poimboeuf
2026-03-08 16:46 ` [PATCH v3 20/30] tools: power: acpi: Append extra cflags Leo Yan
2026-03-09 18:01 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 21/30] tools: power: x86/intel-speed-select: " Leo Yan
2026-03-09 15:59 ` srinivas pandruvada
2026-03-09 18:02 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 22/30] tools: sched_ext: " Leo Yan
2026-03-09 18:07 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 23/30] tools: spi: " Leo Yan
2026-03-08 23:21 ` Mark Brown
2026-03-09 18:03 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 24/30] tools: tracing: " Leo Yan
2026-03-09 15:44 ` Steven Rostedt
2026-03-09 16:37 ` Ian Rogers
2026-03-10 11:48 ` Leo Yan
2026-03-08 16:46 ` [PATCH v3 25/30] tools: usb: " Leo Yan
2026-03-09 18:04 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 26/30] tools: verification: " Leo Yan
2026-03-09 6:26 ` Gabriele Monaco
2026-03-10 15:58 ` Leo Yan
2026-03-08 16:46 ` [PATCH v3 27/30] selftests/bpf: " Leo Yan
2026-03-09 18:05 ` Ian Rogers
2026-03-10 17:50 ` Leo Yan
2026-03-08 16:46 ` [PATCH v3 28/30] selftests/hid: " Leo Yan
2026-03-09 18:06 ` Ian Rogers
2026-03-08 16:46 ` [PATCH v3 29/30] selftests/nolibc: " Leo Yan
2026-03-09 22:24 ` Thomas Weißschuh
2026-03-10 16:06 ` Leo Yan
2026-03-08 16:46 ` [PATCH v3 30/30] selftests/sched_ext: " Leo Yan
2026-03-09 12:45 ` Andrea Righi
2026-03-09 18:02 ` Ian Rogers
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=20260308-tools_build_fix_zero_init-v3-5-6477808123b7@arm.com \
--to=leo.yan@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=andy@kernel.org \
--cc=arighi@nvidia.com \
--cc=ast@kernel.org \
--cc=baohua@kernel.org \
--cc=bentiss@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brgl@kernel.org \
--cc=broonie@kernel.org \
--cc=changwoo@igalia.com \
--cc=daniel.lezcano@kernel.org \
--cc=daniel@iogearbox.net \
--cc=decui@microsoft.com \
--cc=dlechner@baylibre.com \
--cc=eddyz87@gmail.com \
--cc=gmonaco@redhat.com \
--cc=haiyangz@microsoft.com \
--cc=haoluo@google.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kys@microsoft.com \
--cc=lenb@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=llvm@lists.linux.dev \
--cc=longli@microsoft.com \
--cc=lukasz.luba@arm.com \
--cc=mark.rutland@arm.com \
--cc=martin.lau@linux.dev \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nsc@kernel.org \
--cc=nuno.sa@analog.com \
--cc=peterz@infradead.org \
--cc=qmo@kernel.org \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=rostedt@goodmis.org \
--cc=rui.zhang@intel.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=tj@kernel.org \
--cc=void@manifault.com \
--cc=w@1wt.eu \
--cc=warthog618@gmail.com \
--cc=wbg@kernel.org \
--cc=wei.liu@kernel.org \
--cc=xiaqinxin@huawei.com \
--cc=yonghong.song@linux.dev \
/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