Skip to content

Commit

Permalink
kbuild: fix building bzImage with CONFIG_TRIM_UNUSED_KSYMS enabled
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Nicolas Pitre authored and torvalds committed Dec 2, 2016
1 parent 8dc0f26 commit 8655639
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ else
include/config/auto.conf: ;
endif # $(dot-config)

# For the kernel to actually contain only the needed exported symbols,
# we have to build modules as well to determine what those symbols are.
# (this can be evaluated only once include/config/auto.conf has been included)
ifdef CONFIG_TRIM_UNUSED_KSYMS
KBUILD_MODULES := 1
endif

# The all: target is the default when no target is given on the
# command line.
# This allow a user to issue only 'make' to build a kernel including modules
Expand Down Expand Up @@ -944,7 +951,7 @@ ifdef CONFIG_GDB_SCRIPTS
endif
ifdef CONFIG_TRIM_UNUSED_KSYMS
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
"$(MAKE) KBUILD_MODULES=1 -f $(srctree)/Makefile vmlinux_prereq"
"$(MAKE) -f $(srctree)/Makefile vmlinux"
endif

# standalone target for easier testing
Expand Down

0 comments on commit 8655639

Please sign in to comment.