kbuild: reuse $(cmd_objtool) for cmd_cc_lto_link_modules

For CONFIG_LTO_CLANG=y, the objtool processing is not possible at the
compilation, hence postponed by the link time.

Reuse $(cmd_objtool) for CONFIG_LTO_CLANG=y by defining objtool-enabled
properly.

For CONFIG_LTO_CLANG=y:

  objtool-enabled is off for %.o compilation
  objtool-enabled is on  for %.lto link

For CONFIG_LTO_CLANG=n:

  objtool-enabled is on for %.o compilation
      (but, it depends on OBJECT_FILE_NON_STANDARD)

Set part-of-module := y for %.lto.o to avoid repeating --module.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
Masahiro Yamada 2021-08-31 16:39:57 +09:00
Родитель ef62588c2c
Коммит 90a353491e
1 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -236,20 +236,26 @@ objtool_args = \
$(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_X86_SMAP), --uaccess) \
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)
ifndef CONFIG_LTO_CLANG cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
endif # CONFIG_STACK_VALIDATION
ifdef CONFIG_LTO_CLANG
# Skip objtool for LLVM bitcode
$(obj)/%.o: objtool-enabled :=
else
# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
objtool-enabled = $(if $(filter-out y%, \ $(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) endif
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
endif # CONFIG_LTO_CLANG
endif # CONFIG_STACK_VALIDATION
ifdef CONFIG_TRIM_UNUSED_KSYMS ifdef CONFIG_TRIM_UNUSED_KSYMS
cmd_gen_ksymdeps = \ cmd_gen_ksymdeps = \
@ -289,13 +295,13 @@ cmd_cc_lto_link_modules = \
$(LD) $(ld_flags) -r -o $@ \ $(LD) $(ld_flags) -r -o $@ \
$(shell [ -s $(@:.lto.o=.o.symversions) ] && \ $(shell [ -s $(@:.lto.o=.o.symversions) ] && \
echo -T $(@:.lto.o=.o.symversions)) \ echo -T $(@:.lto.o=.o.symversions)) \
--whole-archive $(filter-out FORCE,$^) --whole-archive $(filter-out FORCE,$^) \
$(cmd_objtool)
ifdef CONFIG_STACK_VALIDATION
# objtool was skipped for LLVM bitcode, run it now that we have compiled # objtool was skipped for LLVM bitcode, run it now that we have compiled
# modules into native code # modules into native code
cmd_cc_lto_link_modules += ; $(objtool) $(objtool_args) --module $@ $(obj)/%.lto.o: objtool-enabled = y
endif $(obj)/%.lto.o: part-of-module := y
$(obj)/%.lto.o: $(obj)/%.o FORCE $(obj)/%.lto.o: $(obj)/%.o FORCE
$(call if_changed,cc_lto_link_modules) $(call if_changed,cc_lto_link_modules)