Skip to content

Commit 8655639

Browse files
Nicolas Pitretorvalds
authored andcommitted
kbuild: fix building bzImage with CONFIG_TRIM_UNUSED_KSYMS enabled
When building a specific target such as bzImage, modules aren't normally built. However if CONFIG_TRIM_UNUSED_KSYMS is enabled, no built modules means none of the exported symbols are used and therefore they will all be trimmed away from the final kernel. A subsequent "make modules" will fail because modpost cannot find the needed symbols for those modules in the kernel binary. Let's make sure modules are also built whenever CONFIG_TRIM_UNUSED_KSYMS is enabled and that the kernel binary is properly rebuilt accordingly. Signed-off-by: Nicolas Pitre <[email protected]> Tested-by: Jarod Wilson <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8dc0f26 commit 8655639

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ else
607607
include/config/auto.conf: ;
608608
endif # $(dot-config)
609609

610+
# For the kernel to actually contain only the needed exported symbols,
611+
# we have to build modules as well to determine what those symbols are.
612+
# (this can be evaluated only once include/config/auto.conf has been included)
613+
ifdef CONFIG_TRIM_UNUSED_KSYMS
614+
KBUILD_MODULES := 1
615+
endif
616+
610617
# The all: target is the default when no target is given on the
611618
# command line.
612619
# This allow a user to issue only 'make' to build a kernel including modules
@@ -944,7 +951,7 @@ ifdef CONFIG_GDB_SCRIPTS
944951
endif
945952
ifdef CONFIG_TRIM_UNUSED_KSYMS
946953
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
947-
"$(MAKE) KBUILD_MODULES=1 -f $(srctree)/Makefile vmlinux_prereq"
954+
"$(MAKE) -f $(srctree)/Makefile vmlinux"
948955
endif
949956

950957
# standalone target for easier testing

0 commit comments

Comments
 (0)