@nickdesaulniers reports that x86_64 defconfig + CONFIG_LTO_CLANG_THIN + CONFIG_TRIM_UNUSED_KSYMS currently fails to build with the following modpost error:
MODPOST modules-only.symvers
ERROR: modpost: "ex_handler_rdmsr_unsafe" [drivers/thermal/intel/x86_pkg_temp_thermal.ko] undefined!
ERROR: modpost: "ex_handler_wrmsr_unsafe" [drivers/thermal/intel/x86_pkg_temp_thermal.ko] undefined!
make[2]: *** [../scripts/Makefile.modpost:150: modules-only.symvers] Error 1
This happens because the list of undefined symbols in x86_pkg_temp_thermal.ko is actually determined from the LLVM bitcode in x86_pg_temp_thermal.o. While the bitcode does contain references to these symbols, they are in inline assembly, which llvm-nm ignores.
An obvious solution would be to generate the list of undefined symbols only after we have compiled the bitcode into .lto.o, but that's complicated by the fact that the undefined_syms command is run before the module is linked into .lto.o. Here's the relevant part from scripts/Makefile.build:
ifdef CONFIG_TRIM_UNUSED_KSYMS
...
# List module undefined symbols
undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
endif
...
cmd_mod = { \
echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
$(undefined_syms) echo; \
} > $@
$(obj)/%.mod: $(obj)/%.o FORCE
$(call if_changed,mod)
In order to fix this, I think we would have to either postpone undefined_syms until after .lto.o has been compiled, or compile .lto.o earlier.
@nickdesaulniers reports that x86_64 defconfig +
CONFIG_LTO_CLANG_THIN+CONFIG_TRIM_UNUSED_KSYMScurrently fails to build with the following modpost error:This happens because the list of undefined symbols in
x86_pkg_temp_thermal.kois actually determined from the LLVM bitcode inx86_pg_temp_thermal.o. While the bitcode does contain references to these symbols, they are in inline assembly, whichllvm-nmignores.An obvious solution would be to generate the list of undefined symbols only after we have compiled the bitcode into
.lto.o, but that's complicated by the fact that theundefined_symscommand is run before the module is linked into.lto.o. Here's the relevant part fromscripts/Makefile.build:In order to fix this, I think we would have to either postpone
undefined_symsuntil after.lto.ohas been compiled, or compile.lto.oearlier.