From nobody Thu Apr 9 19:54:29 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7845B396B61; Tue, 24 Feb 2026 12:16:57 +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=1771935421; cv=none; b=Tv8QAucwSkVPR3eDs5kdTgFc2byfRjI3WAsazqaWBpDXNDcRjnEvJDBEYea2DMw3rbOmNRgac7QTBm5RFVphq3vHrkHqjaFNLYEDbE19WZpiObgNeDNzLbEn9+MPW6ZJ6lGse8lHy0RYDAwfBTLxz4K0dJWvp2yo0KktKSe4rKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771935421; c=relaxed/simple; bh=caccyDgZzv1w4El8pn0YhoNYBUIx3pO4j7z5UQOikIg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=tiHoEigatLK9Q+hLlPc864BN1LJ3HAH+SCkOP/gq07gE4o2jgri5y786QlzWODb7MvEeKIZupHze2rgFL27awKxEkJ3PIWx4xXRXJ6UVYsOHrJXqCyxCvt6vqQ5Pj3CsS8AE1RuiQlfXmM3c93T8Cf6sPDfnQeCEH9FnZ6tsD4A= 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 27CC9339; Tue, 24 Feb 2026 04:16:50 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4324F3F62B; Tue, 24 Feb 2026 04:16:54 -0800 (PST) From: Leo Yan Date: Tue, 24 Feb 2026 12:16:40 +0000 Subject: [PATCH RESEND v2] tools build: Use -fzero-init-padding-bits=all 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: <20260224-tools_build_fix_zero_init-v2-1-b1acc817a01e@arm.com> X-B4-Tracking: v=1; b=H4sIAKeWnWkC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyjHQUlJIzE vPSU3UzU4B8JSMDIzMDIyMT3ZL8/Jzi+KTSzJyU+LTMiviq1KL8+My8zBLdlGRTIzPDpBSLJIs kJaD+gqJUoAKw2dFKQa7Brn4uSrG1tQDpqYLKcwAAAA== X-Change-ID: 20260224-tools_build_fix_zero_init-dc5261bd8b8b To: Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , James Clark , Kees Cook Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771935414; l=2715; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=caccyDgZzv1w4El8pn0YhoNYBUIx3pO4j7z5UQOikIg=; b=4fYDTyk7PtjjCIr6sZ/vkVs7JduCYgsk+telUWd/TylDbDG2HnFgYMbWW5dXSi2xIgGsuDADJ sCznsvv4f0ZB3QD9h8d1H7/+CKrf9QrIivXRbzzuGHgNE1DO62hZGhP 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 neither by any version older than GCC 15 and is also not supported by LLVM, this patch adds the cc-option function to dynamically detect the compiler option. [1] https://gcc.gnu.org/gcc-15/changes.html Signed-off-by: Leo Yan --- Resent to linux-kbuild mailing list. --- tools/scripts/Makefile.include | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..73f6aef4f3fda0cda7ee8f4b9a3= b7ff7d956070d 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -40,6 +40,30 @@ EXTRA_WARNINGS +=3D -Wwrite-strings EXTRA_WARNINGS +=3D -Wformat EXTRA_WARNINGS +=3D -Wno-type-limits =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)) + +# Explicitly clear padding bits with the initializer '{ 0 }' +CFLAGS +=3D $(call cc-option,-fzero-init-padding-bits=3Dall) + # Makefiles suck: This macro sets a default value of $(2) for the # variable named by $(1), unless the variable has been set by # environment or command line. This is necessary for CC and AR --- base-commit: 7dff99b354601dd01829e1511711846e04340a69 change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b Best regards, --=20 Leo Yan