* [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n
@ 2025-01-31 14:04 Masahiro Yamada
2025-01-31 16:58 ` Yonghong Song
2025-01-31 21:41 ` Song Liu
0 siblings, 2 replies; 3+ messages in thread
From: Masahiro Yamada @ 2025-01-31 14:04 UTC (permalink / raw)
To: linux-kbuild
Cc: linux-kernel, Masahiro Yamada, Yonghong Song, Bill Wendling,
Justin Stitt, Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
llvm
Since commit bede169618c6 ("kbuild: enable objtool for *.mod.o and
additional kernel objects"), Clang LTO builds do not perform any
optimizations when CONFIG_OBJTOOL is disable (e.g., for ARCH=arm64).
This is because every LLVM bitcode file is immediately converted to
ELF format before the object files are linked together.
This commit fixes the breakage.
Fixes: bede169618c6 ("kbuild: enable objtool for *.mod.o and additional kernel objects")
Reported-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.build | 2 ++
scripts/Makefile.lib | 10 ++++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 81d9dacad03c..993708d11874 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -194,7 +194,9 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object))
+ifdef CONFIG_OBJTOOL
$(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
+endif
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7395200538da..2e280a02e9e6 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -287,6 +287,8 @@ delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
+objtool-enabled := y
+
endif # CONFIG_OBJTOOL
# Useful for describing the dependency of composite objects
@@ -302,11 +304,11 @@ endef
# ===========================================================================
# These are shared by some Makefile.* files.
-objtool-enabled := y
-
ifdef CONFIG_LTO_CLANG
-# objtool cannot process LLVM IR. Make $(LD) covert LLVM IR to ELF here.
-cmd_ld_single = $(if $(objtool-enabled), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
+# Run $(LD) here to covert LLVM IR to ELF in the following cases:
+# - when this object needs objtool processing, as objtool cannot process LLVM IR
+# - when this is a single-object module, as modpost cannot process LLVM IR
+cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
endif
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n
2025-01-31 14:04 [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n Masahiro Yamada
@ 2025-01-31 16:58 ` Yonghong Song
2025-01-31 21:41 ` Song Liu
1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2025-01-31 16:58 UTC (permalink / raw)
To: Masahiro Yamada, linux-kbuild
Cc: linux-kernel, Bill Wendling, Justin Stitt, Nathan Chancellor,
Nick Desaulniers, Nicolas Schier, llvm
On 1/31/25 6:04 AM, Masahiro Yamada wrote:
> Since commit bede169618c6 ("kbuild: enable objtool for *.mod.o and
> additional kernel objects"), Clang LTO builds do not perform any
> optimizations when CONFIG_OBJTOOL is disable (e.g., for ARCH=arm64).
> This is because every LLVM bitcode file is immediately converted to
> ELF format before the object files are linked together.
>
> This commit fixes the breakage.
>
> Fixes: bede169618c6 ("kbuild: enable objtool for *.mod.o and additional kernel objects")
> Reported-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Thanks for the fix!
I tested x86_64 and arm64 for with and without lto, everything works fine. So
Tested-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n
2025-01-31 14:04 [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n Masahiro Yamada
2025-01-31 16:58 ` Yonghong Song
@ 2025-01-31 21:41 ` Song Liu
1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2025-01-31 21:41 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, linux-kernel, Yonghong Song, Bill Wendling,
Justin Stitt, Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
llvm
On Fri, Jan 31, 2025 at 6:04 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Since commit bede169618c6 ("kbuild: enable objtool for *.mod.o and
> additional kernel objects"), Clang LTO builds do not perform any
> optimizations when CONFIG_OBJTOOL is disable (e.g., for ARCH=arm64).
> This is because every LLVM bitcode file is immediately converted to
> ELF format before the object files are linked together.
>
> This commit fixes the breakage.
>
> Fixes: bede169618c6 ("kbuild: enable objtool for *.mod.o and additional kernel objects")
> Reported-by: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Song Liu <song@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-31 21:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-31 14:04 [PATCH] kbuild: fix Clang LTO with CONFIG_OBJTOOL=n Masahiro Yamada
2025-01-31 16:58 ` Yonghong Song
2025-01-31 21:41 ` Song Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox