kbuild: Fix TRIM_UNUSED_KSYMS with LTO_CLANG
With CONFIG_LTO_CLANG, we currently link modules into native code just before modpost, which means with TRIM_UNUSED_KSYMS enabled, we still look at the LLVM bitcode in the .o files when generating the list of used symbols. As the bitcode doesn't yet have calls to compiler intrinsics and llvm-nm doesn't see function references that only exist in function-level inline assembly, we currently need a whitelist for TRIM_UNUSED_KSYMS to work with LTO. This change moves module LTO linking to happen earlier, and thus avoids the issue with LLVM bitcode and TRIM_UNUSED_KSYMS entirely, allowing us to also drop the whitelist from gen_autoksyms.sh. Link: https://github.com/ClangBuiltLinux/linux/issues/1369 Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Alexander Lobakin <alobakin@pm.me> Tested-by: Alexander Lobakin <alobakin@pm.me> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
committed by
Masahiro Yamada
parent
7d73c3e9c5
commit
850ded46c6
@@ -9,7 +9,7 @@ __modfinal:
|
||||
include include/config/auto.conf
|
||||
include $(srctree)/scripts/Kbuild.include
|
||||
|
||||
# for c_flags and objtool_args
|
||||
# for c_flags and mod-prelink-ext
|
||||
include $(srctree)/scripts/Makefile.lib
|
||||
|
||||
# find all modules listed in modules.order
|
||||
@@ -30,23 +30,6 @@ quiet_cmd_cc_o_c = CC [M] $@
|
||||
|
||||
ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
|
||||
|
||||
ifdef CONFIG_LTO_CLANG
|
||||
# With CONFIG_LTO_CLANG, reuse the object file we compiled for modpost to
|
||||
# avoid a second slow LTO link
|
||||
prelink-ext := .lto
|
||||
|
||||
# ELF processing was skipped earlier because we didn't have native code,
|
||||
# so let's now process the prelinked binary before we link the module.
|
||||
|
||||
ifdef CONFIG_STACK_VALIDATION
|
||||
cmd_ld_ko_o += \
|
||||
$(objtree)/tools/objtool/objtool $(objtool_args) \
|
||||
$(@:.ko=$(prelink-ext).o);
|
||||
|
||||
endif # CONFIG_STACK_VALIDATION
|
||||
|
||||
endif # CONFIG_LTO_CLANG
|
||||
|
||||
quiet_cmd_ld_ko_o = LD [M] $@
|
||||
cmd_ld_ko_o += \
|
||||
$(LD) -r $(KBUILD_LDFLAGS) \
|
||||
@@ -72,7 +55,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
|
||||
|
||||
|
||||
# Re-generate module BTFs if either module's .ko or vmlinux changed
|
||||
$(modules): %.ko: %$(prelink-ext).o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE
|
||||
$(modules): %.ko: %$(mod-prelink-ext).o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE
|
||||
+$(call if_changed_except,ld_ko_o,vmlinux)
|
||||
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
|
||||
+$(if $(newer-prereqs),$(call cmd,btf_ko))
|
||||
|
||||
Reference in New Issue
Block a user