Skip to content

RFC kbuild: build the userspace tools in tools/ with the kernel

Sasha Levin linux-kbuild linux-kselftest linux-perf-users lkml sashiko-reviews 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest7 patches 11 repliesIn review
  2. v1 RFC6 patches 13 repliesSuperseded

Changes in v2 from the cover letter

- 1/7: Add Thomas's Reviewed-by.
- 2/7: Put each "depends on" condition on its own line. Allow UML: the tools are built for the architecture UML runs on (HEADER_ARCH), as their build systems do not know ARCH=um. Drop the PYTHONDONTWRITEBYTECODE export, as 5479e1a13b75 ("perf tools: Put Python bytecode in output directory") in perf-tools-next keeps perf's bytecode in its output directory.
- 3/7: New. Add MINIMAL=1 to perf, which turns off every optional feature, as Ian suggested.
- 4/7: Build perf with MINIMAL=1 instead of a list of NO_* variables.
- 5/7: As with "make kselftest-all", a selftest that fails to build no longer fails the build unless FORCE_TARGETS is set, and kselftest_deps.sh lists the libraries it needs that the compiler cannot link with. Also rebuild the selftests when headers under tools/arch change, the vDSO test when kernel headers change, and the x86 tests when the x86 headers they include change.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7kbuild: factor the userspace ABI flags out into KBUILD_USERABIMakefile+7 -51 reply
2/7kbuild: add "make tools_build" to build userspace tools from tools/.gitignore Makefile lib/Kconfig.debug +2 more+172 -11 reply
3/7perf build: Add MINIMAL=1 to build without optional featurestools/perf/Makefile.config tools/perf/Makefile.perf tools/perf/tests/make+45 -113 replies
4/7tools: build perf in tools_buildtools/Kconfig tools/Makefile.kbuild+26 -01 reply
5/7tools: build kernel selftests in tools_buildtools/Kconfig tools/Makefile.kbuild+355 -42 replies
6/7kbuild: build the tools selected in tools/Kconfig as part of "make all"Makefile+4 -00 replies
7/7Documentation: describe building tools with the kernelDocumentation/dev-tools/kselftest.rst Documentation/kbuild/kbuild.rst Documentation/process/submit-checklist.rst+12 -10 replies

Reviews trailers per patch

4 of 7 patches have a Reviewed-by or Acked-by.

PatchThomas WeißschuhShuah KhanNamhyung Kim
1/7R-b
2/7
3/7A-b
4/7A-b
5/7R-b
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [RFC PATCH v2 0/7] kbuild: build the userspace tools in tools/ with the kernel

The userspace programs under tools/ are disconnected from the rest of the kernel's build system. Each has its own makefiles and build framework, and "make" never builds them: apart from the few host tools the build itself needs, such as objtool and resolve_btfids, nothing under tools/ is compiled as part of a kernel build.

That makes them easy to break. Most people, and most of the build bots, check a change with "make allmodconfig && make", which doesn't cover tools/ at all. A change that breaks a tool passes every build check and is only noticed when someone happens to build that tool by hand, often much later.

We keep seeing this in tools/testing/: selftests that stop building after a change elsewhere in the tree, or after a backport to a stable tree, and stay broken until someone tries to build them. Others brought up the same concern at LPC.

This series lets the kernel build also build the tools it is configured for:

- tools/Kconfig adds a "Build userspace tools from tools/" menu (CONFIG_TOOLS_BUILD) with one entry per tool and per selftests directory, so .config records what gets built, and a tool that breaks can be turned off on its own.

- "make tools_build" builds the selected tools for the target, each with its own build system as it is built standalone, into tools-build/ in the object tree.

- With CONFIG_TOOLS_BUILD=y, "make all" builds them too. allmodconfig and allyesconfig enable every entry that applies to the target when the compiler can link glibc programs for it (currently x86_64 and arm64), so the usual build test catches tools breakage. Other toolchains are unaffected, as are "make vmlinux", "make modules" and external module builds.

This is useful beyond build testing: the tools are built for the same target, from the same tree, as the kernel they go with.

Changes in v2:
- 1/7: Add Thomas's Reviewed-by.
- 2/7: Put each "depends on" condition on its own line. Allow UML: the tools are built for the architecture UML runs on (HEADER_ARCH), as their build systems do not know ARCH=um. Drop the PYTHONDONTWRITEBYTECODE export, as 5479e1a13b75 ("perf tools: Put Python bytecode in output directory") in perf-tools-next keeps perf's bytecode in its output directory.
- 3/7: New. Add MINIMAL=1 to perf, which turns off every optional feature, as Ian suggested.
- 4/7: Build perf with MINIMAL=1 instead of a list of NO_* variables.
- 5/7: As with "make kselftest-all", a selftest that fails to build no longer fails the build unless FORCE_TARGETS is set, and kselftest_deps.sh lists the libraries it needs that the compiler cannot link with. Also rebuild the selftests when headers under tools/arch change, the vDSO test when kernel headers change, and the x86 tests when the x86 headers they include change.

3/7 is against mainline. perf-tools-next renamed NO_LIBPYTHON to NO_PYTHON_MODULE and runs mypy and pylint by default, so there it also needs NO_PYTHON_MODULE, NO_MYPY and NO_PYLINT.

v1: https://lore.kernel.org/r/[email protected]

Sasha Levin (7):
kbuild: factor the userspace ABI flags out into KBUILD_USERABI
kbuild: add "make tools_build" to build userspace tools from tools/ perf build: Add MINIMAL=1 to build without optional features
tools: build perf in tools_build
tools: build kernel selftests in tools_build
kbuild: build the tools selected in tools/Kconfig as part of "make
all"
Documentation: describe building tools with the kernel

 .gitignore                                 |   5 +
 Documentation/dev-tools/kselftest.rst      |   4 +
 Documentation/kbuild/kbuild.rst            |   4 +-
 Documentation/process/submit-checklist.rst |   5 +
 Makefile                                   |  24 +-
 lib/Kconfig.debug                          |   2 +
 tools/Kconfig                              | 330 +++++++++++++++++++++
 tools/Makefile.kbuild                      | 205 +++++++++++++
 tools/perf/Makefile.config                 |   8 +-
 tools/perf/Makefile.perf                   |  40 ++-
 tools/perf/tests/make                      |   8 +-
 11 files changed, 617 insertions(+), 18 deletions(-)
 create mode 100644 tools/Kconfig
 create mode 100644 tools/Makefile.kbuild

base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
prerequisite-patch-id: 68eb8785244b88ec7e696e716420e2d9b1367dbc
prerequisite-patch-id: 37c57cf4c2a9700788cd1755912753f363cbb3f9
prerequisite-patch-id: 7772557d5d842a42f1bbb3ee18d41f337db9783a
prerequisite-patch-id: 75abf8d47ec8093740c215e9eebe7bbb5846ddd6
prerequisite-patch-id: de33c5273a0f7619a54dc6d1fd9c47383b7dd60e
prerequisite-patch-id: 5243b7b03f2c12a6e66c353b0c083f7f21fd7ba2
prerequisite-patch-id: 7153a847ba7b05e49a670caba5d5b8fa2508eff1
prerequisite-patch-id: 67a995618952454c30eb77960a5bf6f897d22547
prerequisite-patch-id: f0580be789bfbd90c903bfef8cf6099609e63347
prerequisite-patch-id: 975b27a83085ae7532771fbd7bb17b779ea2c254
prerequisite-patch-id: 1eee5ec66bc4c1ff3ba9f57e005484ed514c77a1
prerequisite-patch-id: 333bf51a132f726bf970b5963017bdc607c0e315
prerequisite-patch-id: 7853ec5197ec9b9322a102a6b02dd62bba4df102
prerequisite-patch-id: bc69d99570e4326ce7736b244838e1e97cc13358
prerequisite-patch-id: 7a28872d234cdfa7bd5ec851e9dde01a65e91130
prerequisite-patch-id: f75a478f103e8707f7ce1ebb136e3a605f026cae
prerequisite-patch-id: c6aacf3772c239df0224afb7e4bb661fb9b81c63
prerequisite-patch-id: a71f47de3fd339d680c9f18e80f5bcde7eae0abf

Signature · 1 line
2.53.0