From nobody Mon Mar 23 21:28:57 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF40F3B27C5; Mon, 23 Mar 2026 15:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278867; cv=none; b=YPhrVuYv61teJ+ynXV8pSuPKVkFa7/fc738gbE6PRlfPrE68CLDQgN3pOxCkHZyXFdlqP2qOm8HOc0M84apxqLBgW2QhRaElw4AtRcGMscIG2kY7EpFFBbe+bThKor7GZtXV4Md1Vk/msAohFtNfgN+3B9u9xjOCukFi+bd/JuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278867; c=relaxed/simple; bh=NWqH78wsmi6y4jjQ8qhIYxcnenhctkfjAsE0nlrnoMY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OdRwWkewNDvVvdWdsoZHNlfIWF6jSe1YTDz2vC+lVOok32W3PTVAFdK0l1EhIdYfupp+0qHyLuqrfhRCjTuHXe3+slfUJWZEToOyczWjWTyqibr9JLdvZuyy4XkkhDdsf4Py77zXpkVYu+pnq7YOSoI/5l4yaO3gsUWM+XXr5Hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5C68F16A3; Mon, 23 Mar 2026 08:14:19 -0700 (PDT) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1F1C53F694; Mon, 23 Mar 2026 08:14:18 -0700 (PDT) From: Leo Yan Date: Mon, 23 Mar 2026 15:13:26 +0000 Subject: [PATCH v6 05/24] tools build: Append -fzero-init-padding-bits=all to extra cflags 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-Transfer-Encoding: quoted-printable Message-Id: <20260323-tools_build_fix_zero_init-v6-5-235858c51af9@arm.com> References: <20260323-tools_build_fix_zero_init-v6-0-235858c51af9@arm.com> In-Reply-To: <20260323-tools_build_fix_zero_init-v6-0-235858c51af9@arm.com> To: Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , 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 , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_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 Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1774278819; l=2805; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=NWqH78wsmi6y4jjQ8qhIYxcnenhctkfjAsE0nlrnoMY=; b=uAbiJgiU8GdnWOe3pCWxM2eI48EQZuBvYeSWhzkjrJrxGT7kwPkzj0zjYyqT4cP8FqgLsv7H3 vPfgQHnTjJ7BxICZctPzWv7lzq1Mn1aKU9B49p4oqZ/pcYFxl6ZEkT/ X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= 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=3Dunions 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=3Dall"), the kernel has enabled -fzero-init-padding-bits=3Dall 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 Acked-by: Namhyung Kim Signed-off-by: Leo Yan --- tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..a2397ceae512c1bc54adb15cb1a= 111ff34e28e43 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -137,6 +137,36 @@ else EXTRA_WARNINGS +=3D -Wshadow endif =20 +# output directory for tests below +TMPOUT =3D .tmp_$$$$ + +# try-run +# Usage: option =3D $(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 =3D $(shell set -e; \ + TMP=3D$(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 +=3D $(call cc-option,-march=3Dwinchip-c6,-march=3Di586) +cc-option =3D $(call try-run, \ + $(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + +host-cc-option =3D $(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 :=3D $(call cc-option,-fzero-init-padding-bits=3Dall) +override EXTRA_CFLAGS +=3D $(FLAG_ZERO_INIT) +HOST_FLAG_ZERO_INIT :=3D $(call host-cc-option,-fzero-init-padding-bits=3D= all) +override HOST_EXTRACFLAGS +=3D $(HOST_FLAG_ZERO_INIT) + ifneq ($(findstring $(MAKEFLAGS), w),w) PRINT_DIR =3D --no-print-directory else --=20 2.34.1