All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org
Cc: "Shuah Khan" <shuah@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>
Subject: Re: [PATCH v3 2/7] kbuild: add "make tools_build" to build userspace tools from tools/
Date: Tue, 03 Nov 2026 02:13:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-194450@kernel.org> (raw)
In-Reply-To: <20261102021253.2545235-3-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] kbuild: USERLDFLAGS in LDFLAGS is ignored when building tools/dma
- [Low] kbuild: missing $(m64-flag) in CONFIG_TOOLS_BUILD_GLIBC preprocessor probe
--

commit 73fb4c9163d06e31dd88981052867f3114563466
Author: Sasha Levin <sashal@kernel.org>

kbuild: add "make tools_build" to build userspace tools from tools/

This commit introduces a CONFIG_TOOLS_BUILD menu in tools/Kconfig and a
tools_build make target backed by tools/Makefile.kbuild to build selected
userspace tools for the target architecture into tools-build/.

> diff --git a/tools/Kconfig b/tools/Kconfig
> new file mode 100644
> index 0000000000000..2d05c8e593e21
> --- /dev/null
> +++ b/tools/Kconfig
> @@ -0,0 +1,73 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config TOOLS_BUILD_ABI
> +	def_bool X86_64 || ARM64
> +
> +config TOOLS_BUILD_GLIBC
> +	def_bool $(success,echo '#include <features.h>' | $(CC) $(CLANG_FLAGS) $(USERCFLAGS) -E -dM -x c - | grep -q __GLIBC__)

[Severity: Low]
Should this preprocessor probe also pass $(m64-flag)?

In scripts/Kconfig.toolchain, CC_CAN_LINK passes $(m64-flag) to
cc_can_link_user when 64BIT is enabled, and tools/Makefile.kbuild passes
$(KBUILD_USERABI) (which includes -m64 on x86_64) in tools-cc.

When configuring an x86_64 kernel with a biarch GCC toolchain that defaults
to 32-bit mode and only has 64-bit glibc development headers
(gnu/stubs-64.h) installed without 32-bit headers (gnu/stubs-32.h), running
$(CC) $(CLANG_FLAGS) $(USERCFLAGS) -E -dM -x c - without $(m64-flag)
preprocesses <features.h> in 32-bit mode. That fails with a fatal error on
the missing <gnu/stubs-32.h> before -dM outputs macro definitions, causing
TOOLS_BUILD_GLIBC to evaluate to n even though the compiler can build 64-bit
glibc programs for the target.

[ ... ]

> diff --git a/tools/Makefile.kbuild b/tools/Makefile.kbuild
> new file mode 100644
> index 0000000000000..8cfa7f80039cd
> --- /dev/null
> +++ b/tools/Makefile.kbuild
> @@ -0,0 +1,85 @@
[ ... ]
> +# The compiler CONFIG_CC_CAN_LINK was tested with. The tools take linker
> +# flags from LDFLAGS.
> +tools-cc := $(CC) $(USERCFLAGS) $(KBUILD_USERABI)
> +ifneq ($(USERLDFLAGS),)
> +override LDFLAGS := $(USERLDFLAGS)
> +export LDFLAGS
> +endif

[Severity: Low]
Will USERLDFLAGS reach tools/dma when building with CONFIG_TOOLS_BUILD_DMA=y?

Here USERLDFLAGS is only passed through the exported LDFLAGS variable and is
not included in tools-cc. However, tools/dma/Makefile compiles and links
dma_map_benchmark in a single rule without referencing $(LDFLAGS):

tools/dma/Makefile:
$(OUTPUT)$(DMA_MAP_BENCHMARK): prepare FORCE
	$(CC) $(CFLAGS) $(DMA_MAP_BENCHMARK).c -o $@

When a user specifies linker flags in USERLDFLAGS (such as --sysroot, -L,
-fuse-ld, or -static) that scripts/cc-can-link.sh validated for
CONFIG_CC_CAN_LINK, building tools/dma via make tools_build will drop those
flags and can fail to link or produce an improperly linked binary.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102021253.2545235-1-sashal@kernel.org?part=2

  reply	other threads:[~2026-11-03  2:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  2:12 [PATCH v3 0/7] kbuild: build the userspace tools in tools/ with the kernel Sasha Levin
2026-11-02  2:12 ` [PATCH v3 1/7] kbuild: factor the userspace ABI flags out into KBUILD_USERABI Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 2/7] kbuild: add "make tools_build" to build userspace tools from tools/ Sasha Levin
2026-11-03  2:13   ` sashiko-bot [this message]
2026-11-02  2:12 ` [PATCH v3 3/7] perf build: Add MINIMAL=1 to build without optional features Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 4/7] tools: build perf in tools_build Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 5/7] tools: build kernel selftests " Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 6/7] kbuild: build the tools selected in tools/Kconfig as part of "make all" Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 7/7] Documentation: describe building tools with the kernel Sasha Levin
2026-11-03  2:13   ` sashiko-bot

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=sashiko-outbox-194450@kernel.org \
    --to=sashiko-bot@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-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=sashal@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.