From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3CC83D8916; Tue, 2 Jun 2026 14:41:48 +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=1780411310; cv=none; b=iq8/QuLWLvZ915NUDBOBRKv/L5xpmjTj0QHhG/5Cn+9vVD5v51YWW1va3rXzNph6SGURI4h9GGDHv9rfFGPTcEJULaxjhLJ4pkHk5EOeCvIAG/2GLfuXGJRpgybUJXS6t+8l30Uv9+djc7EDP43INr1GNIL2G4JJ/eI3aURWlC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780411310; c=relaxed/simple; bh=Zfjmx54wmhTOTfKHgSUz3oiIARFJkpv7bwoefkoudgY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m9rfPl9GvbVaBF4ax0KZg8WSIE0x0o0vcdAh7REtIY7eHSx1TRsZYUXI4K2QO79Eo0TJcQmJEct+zcrFJgv9ZdU8sWxT+R99jaX4UCHvYaDEdwok7UD7qjvR/If0r1Lt4nYxIytv1pxfoGzTjx70bZTuf8etqmZlVmMBTmPTMw0= 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; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=ECaascSU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="ECaascSU" 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 2A0F63572; Tue, 2 Jun 2026 07:41:43 -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 2FAA93F632; Tue, 2 Jun 2026 07:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1780411308; bh=Zfjmx54wmhTOTfKHgSUz3oiIARFJkpv7bwoefkoudgY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ECaascSUTini9Uvtuu9RP9YsoABhc96n69zxXjfsNAyHEoeEn72dZ4Zme3sWq+uHH 25lZyKZsiiO3uevYUver77T69sYbNgxKBj42N0E1PRHPZWdL3k6C8NbCHjdFvLDqJT 3LMsAH4zKeuhdK3J//nYXu5hBI8mHECXbt/tl3Ic= From: Leo Yan Date: Tue, 02 Jun 2026 15:40:40 +0100 Subject: [PATCH v7 06/23] 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: 7bit Message-Id: <20260602-tools_build_fix_zero_init-v7-6-631baf679fe7@arm.com> References: <20260602-tools_build_fix_zero_init-v7-0-631baf679fe7@arm.com> In-Reply-To: <20260602-tools_build_fix_zero_init-v7-0-631baf679fe7@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=1780411243; l=2805; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=Zfjmx54wmhTOTfKHgSUz3oiIARFJkpv7bwoefkoudgY=; b=mIIWHhIvYgqIFU/Qm0rMvVHra6to4RUl7AgB1uOmIhhVFFBhaLOR1nnsnk/BEYOtQdzp0jpI0 FrsNtQDKg4YB2DhLLGonT0hs9Hj05gGpw+wlvHkIu6Zj3dTTYACL49O 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=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 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 41971a68972dda218714d6b95b1d9d92349285c3..17d24cf84051ae99eb5b4c4bdfda43cd187891f6 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -139,6 +139,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