Linux Perf Users
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: "Sasha Levin" <sashal@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org, "Shuah Khan" <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"James Clark" <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Thorsten Leemhuis" <linux@leemhuis.info>,
	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	[thread overview]
Message-ID: <20261201175052.733351-1-sashal@kernel.org> (raw)
In-Reply-To: <20261201023512.GA2264386@ax162>

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,<output directory>,<make arguments>,<files to check>,<CONFIG_ symbol>[,<on failure>])
+# $(call build,<directory in tools/>,<output directory>,<make arguments>,<files to check>,<CONFIG_ symbol>[,<on failure>])
 # 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/<name>, 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/<name>
 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

      reply	other threads:[~2026-12-01 17:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 19:54 [PATCH v4 0/7] kbuild: build the userspace tools in tools/ with the kernel Sasha Levin
2026-11-12 19:54 ` [PATCH v4 1/7] kbuild: factor the userspace ABI flags out into KBUILD_USERABI Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 2/7] kbuild: add "make tools_build" to build userspace tools from tools/ Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 3/7] perf build: Add MINIMAL=1 to build without optional features Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 4/7] tools: build perf in tools_build Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 5/7] tools: build kernel selftests " Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 6/7] kbuild: build the tools selected in tools/Kconfig as part of "make all" Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 19:54 ` [PATCH v4 7/7] Documentation: describe building tools with the kernel Sasha Levin
2026-11-13 19:55   ` sashiko-bot
2026-11-12 20:23 ` [PATCH v4 0/7] kbuild: build the userspace tools in tools/ " Andrew Morton
2026-11-13  1:52   ` Sasha Levin
2026-11-20 20:53   ` Nicolas Schier
2026-11-23 18:19     ` Sasha Levin
2026-11-16 18:24 ` Sasha Levin
2026-11-16 19:35   ` Nathan Chancellor
2026-12-01  2:35     ` Nathan Chancellor
2026-12-01 17:50       ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201175052.733351-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux@leemhuis.info \
    --cc=linux@weissschuh.net \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox