Skip to content

Commit

Permalink
kbuild: fix Clang LTO with CONFIG_OBJTOOL=n
Browse files Browse the repository at this point in the history
Since commit bede169 ("kbuild: enable objtool for *.mod.o and
additional kernel objects"), Clang LTO builds do not perform any
optimizations when CONFIG_OBJTOOL is disabled (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: bede169 ("kbuild: enable objtool for *.mod.o and additional kernel objects")
Reported-by: Yonghong Song <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
Tested-by: Yonghong Song <[email protected]>
  • Loading branch information
masahir0y committed Jan 31, 2025
1 parent 71d815b commit 695ed93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
10 changes: 6 additions & 4 deletions scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) $@
Expand Down

0 comments on commit 695ed93

Please sign in to comment.