Message ID | 20241113234526.402738-3-masahiroy@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o | expand |
Hi Masahiro, On Thu, Nov 14, 2024 at 08:45:22AM +0900, Masahiro Yamada wrote: > Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}. > > This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib > and set objtool-enabled to y there. > > With this change, *.mod.o, .module-common.o, builtin-dtb.o, and > vmlinux.export.o will now be covered by objtool. > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> I am seeing some build failures when LTO is enabled with this change in -next as commit d8d3f6c6690c ("kbuild: enable objtool for *.mod.o and additional kernel objects"). $ printf 'CONFIG_LTO_%s\n' NONE=n CLANG_THIN=y >kernel/configs/thinlto.config $ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper {def,thinlto.}config all ... .vmlinux.export.o: warning: objtool: gelf_getehdr: invalid `Elf' handle make[4]: *** [scripts/Makefile.vmlinux:13: .vmlinux.export.o] Error 1 ... When LTO is enabled, these files are LLVM bitcode, not ELF, so objtool can't process them: $ file .vmlinux.export.o .vmlinux.export.o: LLVM IR bitcode Cheers, Nathan
On Tue, Nov 19, 2024 at 11:27 AM Nathan Chancellor <nathan@kernel.org> wrote: > > Hi Masahiro, > > On Thu, Nov 14, 2024 at 08:45:22AM +0900, Masahiro Yamada wrote: > > Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}. > > > > This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib > > and set objtool-enabled to y there. > > > > With this change, *.mod.o, .module-common.o, builtin-dtb.o, and > > vmlinux.export.o will now be covered by objtool. > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > I am seeing some build failures when LTO is enabled with this change in > -next as commit d8d3f6c6690c ("kbuild: enable objtool for *.mod.o and > additional kernel objects"). > > $ printf 'CONFIG_LTO_%s\n' NONE=n CLANG_THIN=y >kernel/configs/thinlto.config > > $ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper {def,thinlto.}config all > ... > .vmlinux.export.o: warning: objtool: gelf_getehdr: invalid `Elf' handle > make[4]: *** [scripts/Makefile.vmlinux:13: .vmlinux.export.o] Error 1 > ... > > When LTO is enabled, these files are LLVM bitcode, not ELF, so objtool > can't process them: > > $ file .vmlinux.export.o > .vmlinux.export.o: LLVM IR bitcode Good catch! I will squash the attached diff. Thank you. -- Best Regards Masahiro Yamada
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 24e10c821461..18b76947fe96 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -202,23 +202,6 @@ 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))) endif -define rule_cc_o_c - $(call cmd_and_fixdep,cc_o_c) - $(call cmd,checksrc) - $(call cmd,checkdoc) - $(call cmd,gen_objtooldep) - $(call cmd,gen_symversions_c) - $(call cmd,record_mcount) - $(call cmd,warn_shared_object) -endef - -define rule_as_o_S - $(call cmd_and_fixdep,as_o_S) - $(call cmd,gen_objtooldep) - $(call cmd,gen_symversions_S) - $(call cmd,warn_shared_object) -endef - # Built-in and composite module parts $(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE $(call if_changed_rule,cc_o_c) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 73e385946855..17c81c346e36 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -302,14 +302,33 @@ endef # =========================================================================== # These are shared by some Makefile.* files. +objtool-enabled := y + quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ $(cmd_ld_single_m) \ $(cmd_objtool) +define rule_cc_o_c + $(call cmd_and_fixdep,cc_o_c) + $(call cmd,checksrc) + $(call cmd,checkdoc) + $(call cmd,gen_objtooldep) + $(call cmd,gen_symversions_c) + $(call cmd,record_mcount) + $(call cmd,warn_shared_object) +endef + quiet_cmd_as_o_S = AS $(quiet_modtag) $@ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) +define rule_as_o_S + $(call cmd_and_fixdep,as_o_S) + $(call cmd,gen_objtooldep) + $(call cmd,gen_symversions_S) + $(call cmd,warn_shared_object) +endef + # Copy a file # =========================================================================== # 'cp' preserves permissions. If you use it to copy a file in read-only srctree, diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index d0153d033bbb..0547a4b59f13 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -26,10 +26,10 @@ KCSAN_SANITIZE := n ccflags-remove-y := $(CC_FLAGS_CFI) %.mod.o: %.mod.c FORCE - $(call if_changed_dep,cc_o_c) + $(call if_changed_rule,cc_o_c) .module-common.o: $(srctree)/scripts/module-common.c FORCE - $(call if_changed_dep,cc_o_c) + $(call if_changed_rule,cc_o_c) quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 1652561896eb..83fc1a861f41 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -12,10 +12,10 @@ include $(srctree)/scripts/Makefile.lib targets := %.o: %.c FORCE - $(call if_changed_dep,cc_o_c) + $(call if_changed_rule,cc_o_c) %.o: %.S FORCE - $(call if_changed_dep,as_o_S) + $(call if_changed_rule,as_o_S) # Built-in dtb # ---------------------------------------------------------------------------
Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}. This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib and set objtool-enabled to y there. With this change, *.mod.o, .module-common.o, builtin-dtb.o, and vmlinux.export.o will now be covered by objtool. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> --- scripts/Makefile.build | 17 ----------------- scripts/Makefile.lib | 19 +++++++++++++++++++ scripts/Makefile.modfinal | 4 ++-- scripts/Makefile.vmlinux | 4 ++-- 4 files changed, 23 insertions(+), 21 deletions(-)