From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147456; b=Cyoq8e9ximKnoPU0dt2g8RRocM3IrpbEit/4moxqTWsqHmNEjaNhnOPz4B6ttNV9TLbY 3zhZQ04q4Vtr8Bzsr4lLHQ0unO8+x9ROq4SA/RXEDbNjFLLEX8YPFTAcKkz+OJhphlyp9 UblCPyb14hxwexip+QlPrY6SbJk7NP+5of/WtMdeRFQXn8A/YTcGmHiIJ2GVLSLE9NcxN 1EtS7Dwqj7fIC1jIeO+ZxOAX1c7GFE+dOohdx+MtyLQGQgLjLD58TskYsAatErpZ55VkB hG5KoSgWfMLtuM+9ztRF4qaOlaIcxoI7EsK2OyCNFvB9BWdFP3mvJkxVmLMNY63bNmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147456; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=8B+fJUzyb7Vo4KiKi68FBCHNJyc68EmslRgVZicdW9o=; b=DuaK1rsbCqe2fk1hebJiyv2XnlbJAYQ6qqG0qFrGM/47Nnr36aORYfDdKGmnOefLlP66 9ATnnkK8CWaQcZTMmCxsgZzOH87y2NyAx/Z9MA9FlY1h1hTd2q8Om77rSjM6kdRh9pkkc A90kmFdOGq0A/etSTQB2O3zpUB+uR/bJTHHRH7YgYD1cjCmIQBb5qWK6LYlHZi7iL/6SV bEHLdijxgtHyPV2echQweDKd/KN1LrfRm8EKGgCBsC37iCIz2lYRs5Apn2g+3vh4LXWU5 3aWC5UoOhRLlmB8z/JSwFw/lUHCoF5qML4ozEwQ1YfnaTW2ePJNm1ZT+VhKcllY3G3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jd5UVYYC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 708FF606A31A; Tue, 1 Dec 2026 17:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jd5UVYYC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D9DF1F00897; Tue, 1 Dec 2026 17:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796147456; bh=8B+fJUzyb7Vo4KiKi68FBCHNJyc68EmslRgVZicdW9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jd5UVYYCFpQNgjQFlzS5qHulyOohEQFMB0CjUgmKbWSIqrmJwf+RREYp8cj1lUbFD tbaddcbJURQP7l88nF8OU3tEgt6Lyj3ATmUjryq01fLxSWpUmiRobuje/5idM0TPIV hD0eSO8fRuZEznwjx+jqAxO3IYqON9hCjCuGUauK82AAWt8iRSF6iIfnvZsrvQv5Eb rd2LPUDwHgahdSNenr4qv7OFLf1wgAwqx8thHMwgeoOdVl1Pb2ia4vU9f3tsznXG4z N+cqmkf/rBMvqMe/sSGrPm2jWKWgK7vVddJwQakSvYWnUUNL8XOs5udUCpu1qSF7kM LeN+AwnqLt+Jw== From: Sasha Levin To: Nathan Chancellor Cc: Sasha Levin , Nicolas Schier , linux-kbuild@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Andrew Morton , Thorsten Leemhuis , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 0/7] kbuild: build the userspace tools in tools/ with the kernel Date: Tue, 1 Dec 2026 12:50:52 -0500 Message-ID: <20261201175052.733351-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201023512.GA2264386@ax162> References: <20261112195427.3411746-1-sashal@kernel.org> <20261116182426.3440056-1-sashal@kernel.org> <20261116193513.GA1037705@ax162> <20261201023512.GA2264386@ax162> X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Mon, Nov 30, 2026 at 07:35:12PM -0700, Nathan Chancellor wrote: >I took this for a spin on next-20261130 on an arm64 test box. Everything >built successfully, although I did have some warnings with clang-23 (I >think you have sent patches for some of them but I didn't check too >closely). Thanks for trying it out! The rseq fixes I sent earlier are in -next already. The warnings you got are new: clang 23's -Wunused-but-set-global in spidev_fdx.c, taskstats_fill_stats_tgid.c and param_test.c, and a function pointer comparison in a proc selftest that went in after rc1. I have fixes for those and will send them to their maintainers. One question while you're here: param_test.c marks loop_cnt_1..6 as "used" and only reads them from inline asm on x86, and clang 23 still says "set but not used". Is that intended? "used" does silence -Wunused-variable. >1. Some of the tests do not respect '-s', resulting in a decent amount > of additional output for allmodconfig (see recording below). That's the selftests' lib.mk, it prints its "CC" lines no matter what. I have a patch for it, and one for the version perf prints on stderr. >2. I see some issues with warnings being garbled, maybe from too much > parallel building? Yes. rseq builds param_test.c six times at once and each clang writes its warnings straight to the terminal. A plain "make -j -C tools/testing/selftests/rseq" does the same. >3. I worry about warnings coming from the tools build not being as easy > to investigate because the warning does not always have the absolute > or srctree relative file name, requiring an additional command to > search the tree for the file in tools before being able to fix it. It > is just unfortunate ergonomics. Agreed. With the change below, each tool's make runs with -Otarget and its stderr goes to a file. Once the tools are built, the files are shown one after the other, each under a line that names the tool's directory: tools_build: tools/spi: spidev_fdx.c:16:12: warning: variable 'verbose' set but not used [-Wunused-but-set-global] 16 | static int verbose; | ^ 1 warning generated. -Otarget is only passed with GNU make 4.4 and later. Older versions lock stdout for it and can hang when that's /dev/null. With that and the patches above, your build (arm64, clang 23.1.6, next-20261130, cross-compiled here) prints nothing with -s. This is what I have on top of v4: diff --git a/Makefile b/Makefile index 2a69f4c73a641..abd8ddb2ded50 100644 --- a/Makefile +++ b/Makefile @@ -1648,7 +1648,8 @@ tools/%: FORCE # The userspace programs selected in tools/Kconfig, built for the target PHONY += tools_build tools_build: headers - $(Q)$(MAKE) -f $(srctree)/tools/Makefile.kbuild + $(Q)$(MAKE) -f $(srctree)/tools/Makefile.kbuild; ret=$$?; \ + $(MAKE) -f $(srctree)/tools/Makefile.kbuild __tools_report && exit $$ret ifdef CONFIG_TOOLS_BUILD all: tools_build diff --git a/tools/Makefile.kbuild b/tools/Makefile.kbuild index 8fcaef8c147fc..a4988bec2e738 100644 --- a/tools/Makefile.kbuild +++ b/tools/Makefile.kbuild @@ -44,28 +44,54 @@ endif squote := ' escsq = $(subst $(squote),'\$(squote)',$1) -# $(call build,,,,[,]) +# $(call build,,,,,[,]) # Builds in an empty directory when the make arguments, LDFLAGS or the # compiler changed, or when one of the files, or a file in one of the # directories, is newer than the last build. A failure fails the build, # unless commands to run instead are given. "make -n" only shows the build. -build-key = $(call escsq,$(2) LDFLAGS=$(USERLDFLAGS) $(CONFIG_CC_VERSION_TEXT)) +# +# The tools name files relative to their own directory, and compilers that +# run in parallel write into each other's messages. What a tool prints on +# stderr goes to a file next to its output directory, below the name of the +# tool's directory, and __tools_report shows these files one after the +# other when the tools are built. A file is kept and added to until it was +# shown, so that an interrupted build does not lose what it holds. +build-key = $(call escsq,-C $(toolsdir)/$(1) $(3) LDFLAGS=$(USERLDFLAGS) $(CONFIG_CC_VERSION_TEXT)) dry-run := $(findstring n,$(firstword -$(MAKEFLAGS))) +# GNU make before 4.4 locks stdout to synchronize its output, and can hang +# when that is /dev/null. +output-sync := $(if $(filter notintermediate,$(.FEATURES)),-Otarget) # Headers the kernel build generates. When the kernel is built in the source # tree, they are written after the tools were built. generated-headers := -path '$(abs_srctree)/include/generated' -o -path '$(abs_srctree)/include/config' \ -o -path '$(abs_srctree)/arch/*/include/generated' define build - +$(Q)$(if $(dry-run),,if [ "$$(cat $(1)/.tools_build 2>/dev/null)" != '$(build-key)' ] $(if $(3),|| \ - [ -n "$$(find $(3) \( $(generated-headers) \) -prune -o -newer $(1)/.tools_build -type f -print -quit 2>/dev/null)" ]); then \ - rm -rf $(1); \ + +$(Q)$(if $(dry-run),,if [ "$$(cat $(2)/.tools_build 2>/dev/null)" != '$(build-key)' ] $(if $(4),|| \ + [ -n "$$(find $(4) \( $(generated-headers) \) -prune -o -newer $(2)/.tools_build -type f -print -quit 2>/dev/null)" ]); then \ + rm -rf $(2); \ fi;) \ - mkdir -p $(1) && $(MAKE) $(2) && \ - $(if $(dry-run),:,printf '%s' '$(build-key)' > $(1)/.tools_build) || \ - { echo >&2 "tools_build: $(patsubst $(outdir)/%,%,$(1)) failed to build; set CONFIG_$(4)=n to skip it"; $(or $(5),false); } + mkdir -p $(2) && \ + $(if $(dry-run),,{ [ -s $(2).tools_build.log ] || echo 'tools_build: tools/$(1):' > $(2).tools_build.log; } && \ + exec 2>> $(2).tools_build.log &&) \ + $(MAKE) $(output-sync) -C $(toolsdir)/$(1) $(3) && \ + $(if $(dry-run),:,printf '%s' '$(build-key)' > $(2)/.tools_build) || \ + { echo >&2 "tools_build: tools/$(1) failed to build; set CONFIG_$(5)=n to skip it"; $(or $(6),false); } endef +# A file with nothing after its first line has nothing to show. A file is +# removed once it was read and shown; failing to do that fails the build. +PHONY += __tools_report +__tools_report: + $(Q)[ -d $(outdir) ] || exit 0; set -f; \ + logs=$$(find $(outdir) -name '*.tools_build.log') && \ + logs=$$(printf '%s\n' $$logs | sort) || exit 1; ret=0; \ + for log in $$logs; do \ + size=$$(wc -c < "$$log") && header=$$(head -n 1 "$$log") || { ret=1; continue; }; \ + [ $$((size)) -le $$(($${#header} + 1)) ] || cat "$$log" >&2 || { ret=1; continue; }; \ + rm -f "$$log" || ret=1; \ + done; exit $$ret + # Programs in tools/, which track their own header dependencies tools-$(CONFIG_TOOLS_BUILD_BOOTCONFIG) += bootconfig tools-$(CONFIG_TOOLS_BUILD_COUNTER) += counter @@ -82,7 +108,7 @@ __tools_build: $(tool-targets) PHONY += $(tool-targets) $(tool-targets): tool-%: FORCE - $(call build,$(outdir)/$*,-C $(toolsdir)/$* O=$(outdir)/$* CC='$(call escsq,$(tools-cc))',,TOOLS_BUILD_$(shell echo $* | tr a-z A-Z)) + $(call build,$*,$(outdir)/$*,O=$(outdir)/$* CC='$(call escsq,$(tools-cc))',,TOOLS_BUILD_$(shell echo $* | tr a-z A-Z)) # perf, without the feature table in the kernel build log perf-flags := CC='$(call escsq,$(tools-cc))' FEATURE_DISPLAY= WERROR=$(if $(CONFIG_WERROR),1,0) @@ -92,7 +118,7 @@ __tools_build: $(if $(CONFIG_TOOLS_BUILD_PERF),perf) PHONY += perf perf: FORCE - $(call build,$(outdir)/perf,-C $(toolsdir)/perf -f Makefile.perf O=$(outdir)/perf $(perf-flags) $(perf-flags-y),,TOOLS_BUILD_PERF) + $(call build,perf,$(outdir)/perf,-f Makefile.perf O=$(outdir)/perf $(perf-flags) $(perf-flags-y),,TOOLS_BUILD_PERF) # Selftests in tools/testing/selftests/ selftests-$(CONFIG_TOOLS_BUILD_SELFTESTS_ACCT) += acct @@ -211,7 +237,7 @@ __tools_build: $(selftest-targets) PHONY += $(selftest-targets) $(selftest-targets): selftest-%: $(selftest-shared) FORCE - $(call build,$(outdir)/selftests/$*,-C $(toolsdir)/testing/selftests/$* OUTPUT=$(outdir)/selftests/$* $(selftest-flags),$(selftest-shared) $(toolsdir)/testing/selftests/$* $(selftest-extra-$*),TOOLS_BUILD_SELFTESTS_$(shell echo $* | tr a-z/- A-Z__),$(call selftest-failed,$*)) + $(call build,testing/selftests/$*,$(outdir)/selftests/$*,OUTPUT=$(outdir)/selftests/$* $(selftest-flags),$(selftest-shared) $(toolsdir)/testing/selftests/$* $(selftest-extra-$*),TOOLS_BUILD_SELFTESTS_$(shell echo $* | tr a-z/- A-Z__),$(call selftest-failed,$*)) PHONY += FORCE FORCE: -- Thanks, Sasha