Skip to contentSkip to conversation

Makefile: add comment to discourage tools/* addition for kernel builds

PATCH In review Masahiro Yamada 3 participants 4 messages Jul 17, 2024 – Jul 20, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Makefile: add comment to discourage tools/* addition for kernel builds

Kbuild provides scripts/Makefile.host to build host programs used for building the kernel. Unfortunately, there are two exceptions that opt out of Kbuild. The build system under tools/ is a cheesy replica, and cause issues. I was recently poked about a problem in the tools build system, which I do not maintain (and nobody maintains). [1]

Without a comment, people might believe this is the right location because that is where objtool lives, even if a more robust Kbuild syntax satisfies their needs. [2]

[1]: https://lore.kernel.org/linux-kbuild/[email protected]/T/#m8ece130dd0e23c6f2395ed89070161948dee8457
[2]: https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- rephase the comment for clarification

 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 768d3dc107f8..943899656977 100644
@@ -1328,6 +1328,12 @@ prepare: tools/bpf/resolve_btfids
 endif
 endif
 
+# The tools build system is not a part of Kbuild and tends to introduce
+# its own unique issues. If you need to integrate a new tool into Kbuild,
+# please consider locating that tool outside the tools/ tree and using the
+# standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry
+# here. See Documentation/kbuild/makefiles.rst for details.
+
 PHONY += resolve_btfids_clean
 
 resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw

Hi Masahiro,

Quoted 32 lines · Masahiro Yamada

Kbuild provides scripts/Makefile.host to build host programs used for building the kernel. Unfortunately, there are two exceptions that opt out of Kbuild. The build system under tools/ is a cheesy replica, and cause issues. I was recently poked about a problem in the tools build system, which I do not maintain (and nobody maintains). [1]

Without a comment, people might believe this is the right location because that is where objtool lives, even if a more robust Kbuild syntax satisfies their needs. [2]

[1]: https://lore.kernel.org/linux-kbuild/[email protected]/T/#m8ece130dd0e23c6f2395ed89070161948dee8457
[2]: https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- rephase the comment for clarification

 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +0 -0
index 768d3dc107f8..943899656977 100644
@@ -1328,6 +1328,12 @@ prepare: tools/bpf/resolve_btfids
 endif
 endif

Makefile prepare: tools/bpf/resolve_btfids · line 1339

Quoted 10 lines
Makefile +6 -0
 
+# The tools build system is not a part of Kbuild and tends to introduce
+# its own unique issues. If you need to integrate a new tool into Kbuild,
+# please consider locating that tool outside the tools/ tree and using the
+# standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry
+# here. See Documentation/kbuild/makefiles.rst for details.
+
 PHONY += resolve_btfids_clean
 
 resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids

Looks good to me, thanks for adding the clarification!

Sami

#2 lore raw
In reply to Masahiro Yamada
Quoted 9 lines · Masahiro Yamada

Kbuild provides scripts/Makefile.host to build host programs used for building the kernel. Unfortunately, there are two exceptions that opt out of Kbuild. The build system under tools/ is a cheesy replica, and cause issues. I was recently poked about a problem in the tools build system, which I do not maintain (and nobody maintains). [1]

Without a comment, people might believe this is the right location because that is where objtool lives, even if a more robust Kbuild syntax satisfies their needs. [2]

I think the original idea (from Ingo?) was to make objtool portable so it could be easily copied and built separately without getting too intertwined with the kernel source.

I think that's still a useful goal. To my knowledge it's been used in at least one other code base and could be used elsewhere going forward as much of its functionality might be transferable to other code bases.

Also being in tools helps it shares library code (libsubcmd) and synced headers with perf (and others).

If there's some other way to make it portable and allow it to share code with other tools that then I wouldn't object to moving it to scripts.

Or, if the main problem is that there are two custom build systems (one of them being a cheap knockoff), could kbuild be made portable enough to be used in tools?

Signature · 1 line
Josh
#3 lore raw
Quoted 23 lines · Josh Poimboeuf
Quoted 9 lines · Masahiro Yamada

Kbuild provides scripts/Makefile.host to build host programs used for building the kernel. Unfortunately, there are two exceptions that opt out of Kbuild. The build system under tools/ is a cheesy replica, and cause issues. I was recently poked about a problem in the tools build system, which I do not maintain (and nobody maintains). [1]

Without a comment, people might believe this is the right location because that is where objtool lives, even if a more robust Kbuild syntax satisfies their needs. [2]

I think the original idea (from Ingo?) was to make objtool portable so it could be easily copied and built separately without getting too intertwined with the kernel source.

I think that's still a useful goal. To my knowledge it's been used in at least one other code base and could be used elsewhere going forward as much of its functionality might be transferable to other code bases.

Also being in tools helps it shares library code (libsubcmd) and synced headers with perf (and others).

Quoted 6 lines

If there's some other way to make it portable and allow it to share code with other tools that then I wouldn't object to moving it to scripts.

Or, if the main problem is that there are two custom build systems (one of them being a cheap knockoff), could kbuild be made portable enough to be used in tools?

I checked Debian and Fedora, but I did not find such a package that provides objtool as a standalone tool.

In reality, objtool is tightly bound to the kernel source. If people had thought it useful outside the kernel tree, such a disto package would have been widely available.

I do not think there is a good reason to complicate Kbuild based on the hypothetical statement.

Signature · 2 lines
Best Regards
Masahiro Yamada