Skip to contentSkip to conversation

kbuild: only clean objtool on mrproper

PATCH In review Michal Suchanek 3 participants 8 messages Feb 25 – Mar 3 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: only clean objtool on mrproper

For packaging purposes I want to be able to grab the tool binaries without the .o files

Fixes 68b4fe32d737 ("kbuild: Add objtool to top-level clean target")
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index e944c6e71e81..e9b8811a02f5 100644
@@ -1675,7 +1675,7 @@ vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
 	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
-clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
+clean: archclean vmlinuxclean resolve_btfids_clean
 
 # mrproper - Delete all generated files, including .config
 #
@@ -1686,7 +1686,7 @@ PHONY += $(mrproper-dirs) mrproper
 $(mrproper-dirs):
 	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
 
-mrproper: clean $(mrproper-dirs)
+mrproper: clean objtool_clean $(mrproper-dirs)
 	$(call cmd,rmfiles)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.rmeta' \) \
Signature · 1 line
2.51.0
#1 lore raw
Quoted 5 lines · Michal Suchanek

For packaging purposes I want to be able to grab the tool binaries without the .o files

Fixes 68b4fe32d737 ("kbuild: Add objtool to top-level clean target")

Wouldn't resolve_btfids need the same treatment? Why is objtool special here? Also, what's the use case? Running 'make clean' then copying what is left? Josh, thoughts on this change?

Quoted 29 lines
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index e944c6e71e81..e9b8811a02f5 100644
@@ -1675,7 +1675,7 @@ vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
 	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
-clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
+clean: archclean vmlinuxclean resolve_btfids_clean
 
 # mrproper - Delete all generated files, including .config
 #
@@ -1686,7 +1686,7 @@ PHONY += $(mrproper-dirs) mrproper
 $(mrproper-dirs):
 	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
 
-mrproper: clean $(mrproper-dirs)
+mrproper: clean objtool_clean $(mrproper-dirs)
 	$(call cmd,rmfiles)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.rmeta' \) \
Signature · 1 line
2.51.0
#2 lore raw
Quoted 8 lines · Nathan Chancellor
Quoted 5 lines · Michal Suchanek

For packaging purposes I want to be able to grab the tool binaries without the .o files

Fixes 68b4fe32d737 ("kbuild: Add objtool to top-level clean target")

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

Quoted 1 line

Why is objtool special here?

That's what I would like to know as well.

Quoted 2 lines

Also, what's the use case? Running 'make clean' then copying what is left?

Yes, that's what my build script has been doing for at least a decade, possibly mutiple decades when it was somebody else's build script.

Thanks

Michal

Quoted 31 lines

Josh, thoughts on this change?

Quoted 29 lines
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index e944c6e71e81..e9b8811a02f5 100644
@@ -1675,7 +1675,7 @@ vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
 	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
-clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
+clean: archclean vmlinuxclean resolve_btfids_clean
 
 # mrproper - Delete all generated files, including .config
 #
@@ -1686,7 +1686,7 @@ PHONY += $(mrproper-dirs) mrproper
 $(mrproper-dirs):
 	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
 
-mrproper: clean $(mrproper-dirs)
+mrproper: clean objtool_clean $(mrproper-dirs)
 	$(call cmd,rmfiles)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.rmeta' \) \
Signature · 1 line
2.51.0
#3 lore raw
Quoted 15 lines · Michal Suchánek
Quoted 8 lines · Nathan Chancellor
Quoted 5 lines · Michal Suchanek

For packaging purposes I want to be able to grab the tool binaries without the .o files

Fixes 68b4fe32d737 ("kbuild: Add objtool to top-level clean target")

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

Quoted 1 line

Why is objtool special here?

Quoted 7 lines

That's what I would like to know as well.

Quoted 2 lines

Also, what's the use case? Running 'make clean' then copying what is left?

Yes, that's what my build script has been doing for at least a decade, possibly mutiple decades when it was somebody else's build script.

Why is the build script doing that?

Signature · 1 line
Josh
#4 lore raw
Quoted 18 lines · Josh Poimboeuf
Quoted 17 lines · Michal Suchánek
Quoted 8 lines · Nathan Chancellor
Quoted 5 lines · Michal Suchanek

For packaging purposes I want to be able to grab the tool binaries without the .o files

Fixes 68b4fe32d737 ("kbuild: Add objtool to top-level clean target")

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

Quoted 1 line

Why is objtool special here?

That's what I would like to know as well.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Also, what's the use case? Running 'make clean' then copying what is left?

Yes, that's what my build script has been doing for at least a decade, possibly mutiple decades when it was somebody else's build script.

Why is the build script doing that?

To clollect the generated files, primarily for building modules.

Thanks

Michal

#5 lore raw
In reply to Michal Suchánek
Quoted 5 lines · Michal Suchánek
Quoted 1 line · Nathan Chancellor

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

That does not reproduce for me personally:

  $ cat kernel/configs/btf.config
  CONFIG_BPF_SYSCALL=y
  # CONFIG_DEBUG_INFO_NONE is not set
  CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
  CONFIG_DEBUG_INFO_BTF=y
  $ make -skj"$(nproc)" ARCH=x86_64 O=build mrproper defconfig btf.config prepare
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  -rwxr-xr-x 1 nathan nathan 2224456 Feb 25 13:33 build/tools/bpf/resolve_btfids/resolve_btfids
  -rwxr-xr-x 1 nathan nathan 4046296 Feb 25 13:33 build/tools/objtool/objtool
  $ make -skj"$(nproc)" ARCH=x86_64 O=build clean
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  "build/tools/bpf/resolve_btfids/resolve_btfids": No such file or directory (os error 2)
  "build/tools/objtool/objtool": No such file or directory (os error 2)

I guess resolve_btfids is not strictly required for external module builds because vmlinux may not be present and cmd_btf_ko handles that gracefully.

Quoted 5 lines
Quoted 2 lines

Also, what's the use case? Running 'make clean' then copying what is left?

Yes, that's what my build script has been doing for at least a decade, possibly mutiple decades when it was somebody else's build script.

I guess that is one way to ensure 'make clean' upholds its promise of leaving just enough to build external modules. I had missed that in review of this change.

Another option would be splitting tools/objtool's clean target into clean and mrproper like the main kernel and mirroring what that does so that objtool the binary can remain around while all its objects get cleaned up.

Cheers,
Nathan

#6 lore raw
Quoted 23 lines · Nathan Chancellor
Quoted 5 lines · Michal Suchánek
Quoted 1 line · Nathan Chancellor

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

That does not reproduce for me personally:

  $ cat kernel/configs/btf.config
  CONFIG_BPF_SYSCALL=y
  # CONFIG_DEBUG_INFO_NONE is not set
  CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
  CONFIG_DEBUG_INFO_BTF=y
  $ make -skj"$(nproc)" ARCH=x86_64 O=build mrproper defconfig btf.config prepare
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  -rwxr-xr-x 1 nathan nathan 2224456 Feb 25 13:33 build/tools/bpf/resolve_btfids/resolve_btfids
  -rwxr-xr-x 1 nathan nathan 4046296 Feb 25 13:33 build/tools/objtool/objtool
  $ make -skj"$(nproc)" ARCH=x86_64 O=build clean
Quoted 7 lines
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  "build/tools/bpf/resolve_btfids/resolve_btfids": No such file or directory (os error 2)
  "build/tools/objtool/objtool": No such file or directory (os error 2)

I guess resolve_btfids is not strictly required for external module builds because vmlinux may not be present and cmd_btf_ko handles that gracefully.

To close the loop here, 'make clean' removes vmlinux and resolve_btfids at the same time and the check in cmd_btf_ko prevents that from becoming a hard error. So technically no problem but a little fragile.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Also, what's the use case? Running 'make clean' then copying what is left?

Yes, that's what my build script has been doing for at least a decade, possibly mutiple decades when it was somebody else's build script.

Quoted 8 lines

I guess that is one way to ensure 'make clean' upholds its promise of leaving just enough to build external modules. I had missed that in review of this change.

Another option would be splitting tools/objtool's clean target into clean and mrproper like the main kernel and mirroring what that does so that objtool the binary can remain around while all its objects get cleaned up.

FWIW, I sent this as an alternative since I think it adheres a little more to Kbuild's contract that 'make clean' leaves enough around for external module builds while removing all unneeded generated files:

https://lore.kernel.org/20260227-avoid-objtool-binary-removal-clean-v1-1-122f3e55eae9@kernel.org/

Cheers,
Nathan

#7 lore raw
In reply to Nathan Chancellor
Quoted 23 lines · Nathan Chancellor
Quoted 5 lines · Michal Suchánek
Quoted 1 line · Nathan Chancellor

Wouldn't resolve_btfids need the same treatment?

No, make clean runs the clean target for resolve_btfids but the tool remains.

That does not reproduce for me personally:

  $ cat kernel/configs/btf.config
  CONFIG_BPF_SYSCALL=y
  # CONFIG_DEBUG_INFO_NONE is not set
  CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
  CONFIG_DEBUG_INFO_BTF=y
  $ make -skj"$(nproc)" ARCH=x86_64 O=build mrproper defconfig btf.config prepare
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  -rwxr-xr-x 1 nathan nathan 2224456 Feb 25 13:33 build/tools/bpf/resolve_btfids/resolve_btfids
  -rwxr-xr-x 1 nathan nathan 4046296 Feb 25 13:33 build/tools/objtool/objtool
  $ make -skj"$(nproc)" ARCH=x86_64 O=build clean
Quoted 7 lines
  $ ls -al build/tools/{bpf/resolve_btfids/resolve_btfids,objtool/objtool}
  "build/tools/bpf/resolve_btfids/resolve_btfids": No such file or directory (os error 2)
  "build/tools/objtool/objtool": No such file or directory (os error 2)

I guess resolve_btfids is not strictly required for external module builds because vmlinux may not be present and cmd_btf_ko handles that gracefully.

Yes, you are right. The reason why this was not a problem with resolve_btfids is that missing resolve_btfids is not an error. Or possibly it's not an error when vmlinux is not in a location where the build can find it.

resolve_btfids should probably also be preserved but it was not reported as a bug so far because the case when it would be a problem is fairly unlikely.

Thanks

Michal