From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A3811C8634; Thu, 12 Mar 2026 18:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773340287; cv=none; b=fooFC96nnUHNhL0XTwpHMUylRueq6StLX0CkSaCEaS98PIBwscbjMoJQbD2kwUa3I9UygCFrTvHUVvTgiMC6aHiRr446ayDb3K335lPto3b2R0YXqz6NzN3kqbmUsZZ409bE+DCE9A+RI9Hd1qiLIhI4Ph7y3hDUdQyhjz6Vll8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773340287; c=relaxed/simple; bh=rp0qyt4sp3t2v5R7dsT9nLl4D8IeqGrfKOSwHQf9yp4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J9ceaLTbNrGPlKK1pFqSCmk1nuL1tLZz/FzMK1RCaIxLAWFPpJuqoN3TAdfAvB2TTAqEj2tDJp/HLKJSkmhDUAv8d6AxCopww/TN6VjpCjd1XhnaFKGQx+fhOMaZRZDOiXtLEXZ9h5FmGKUjfYuBwPxyxg4IEyrYijJv3ksNgCE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HWm2pqMA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HWm2pqMA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 636D2C4CEF7; Thu, 12 Mar 2026 18:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773340287; bh=rp0qyt4sp3t2v5R7dsT9nLl4D8IeqGrfKOSwHQf9yp4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HWm2pqMA6QFDPUAPLPuhXTuoMJkcpiVXPREifz653Sb2MAVWJTWb1pbXn1Wox8sPK sAGR539NtwuI8NDB2uMWwRL/iGS7BOAeMmobKojiMh/1srwYZpRG82sLHr1PrClCT8 suBk92+HLFgrSt4XiZ3trdm9iYUJjfd1GUaAKOD/QmvbJ5BO44cNhklCfSyVKRuCmX AeezgN++jcT0glq4BBWVB106k26B6FshUghtFq2SCxMZE5pZ0cbyvsGtkAut+YPIL8 EWueQrAIcP0hZwUPAIP4YE26W+nj3G/nlHJ8rrZYqYCzC6HeFRCdzZfjxmOrUCbZN1 LNd4iQccyEHnQ== Date: Thu, 12 Mar 2026 11:31:22 -0700 From: Namhyung Kim To: Leo Yan Cc: Arnaldo Carvalho de Melo , Ian Rogers , James Clark , Kees Cook , Quentin Monnet , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Adrian Hunter , Masami Hiramatsu , William Breathitt Gray , Barry Song , Qinxin Xia , Bartosz Golaszewski , Kent Gibson , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Jonathan Cameron , David Lechner , Nuno =?utf-8?B?U8Oh?= , Andy Shevchenko , Andrew Morton , Willy Tarreau , Thomas =?utf-8?Q?Wei=C3=9Fschuh?= , Josh Poimboeuf , Robert Moore , Len Brown , Srinivas Pandruvada , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Mark Brown , Steven Rostedt , Gabriele Monaco , Shuah Khan , Jiri Kosina , Benjamin Tissoires , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v4 08/30] tools build: Append -fzero-init-padding-bits=all to extra cflags Message-ID: References: <20260311-tools_build_fix_zero_init-v4-0-9e35bdb99cb3@arm.com> <20260311-tools_build_fix_zero_init-v4-8-9e35bdb99cb3@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20260311-tools_build_fix_zero_init-v4-8-9e35bdb99cb3@arm.com> On Wed, Mar 11, 2026 at 08:29:33AM +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 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 > > Acked-by: Quentin Monnet > Signed-off-by: Leo Yan Acked-by: Namhyung Kim Thanks, Namhyung > --- > 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) > +HOST_FLAG_ZERO_INIT := $(call host-cc-option,-fzero-init-padding-bits=all) > +override HOST_EXTRACFLAGS += $(HOST_FLAG_ZERO_INIT) > + > ifneq ($(findstring $(MAKEFLAGS), w),w) > PRINT_DIR = --no-print-directory > else > > -- > 2.34.1 >