Skip to content

Commit 695ed93

Browse files
committed
kbuild: fix Clang LTO with CONFIG_OBJTOOL=n
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 <yonghong.song@linux.dev> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Yonghong Song <yonghong.song@linux.dev>
1 parent 71d815b commit 695ed93

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

scripts/Makefile.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
194194

195195
is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object))
196196

197+
ifdef CONFIG_OBJTOOL
197198
$(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
199+
endif
198200

199201
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
200202
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))

scripts/Makefile.lib

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
287287
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
288288
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
289289

290+
objtool-enabled := y
291+
290292
endif # CONFIG_OBJTOOL
291293

292294
# Useful for describing the dependency of composite objects
@@ -302,11 +304,11 @@ endef
302304
# ===========================================================================
303305
# These are shared by some Makefile.* files.
304306

305-
objtool-enabled := y
306-
307307
ifdef CONFIG_LTO_CLANG
308-
# objtool cannot process LLVM IR. Make $(LD) covert LLVM IR to ELF here.
309-
cmd_ld_single = $(if $(objtool-enabled), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
308+
# Run $(LD) here to covert LLVM IR to ELF in the following cases:
309+
# - when this object needs objtool processing, as objtool cannot process LLVM IR
310+
# - when this is a single-object module, as modpost cannot process LLVM IR
311+
cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
310312
endif
311313

312314
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@

0 commit comments

Comments
 (0)