[lkml]   [2018]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 7/7] kbuild: link vmlinux just once for CONFIG_TRIM_UNUSED_KSYMS
If CONFIG_TRIM_UNUSED_KSYMS is enabled and the kernel is built from
a pristine state, the vmlinux is linked twice.

[1] A user runs "make"

[2] First build with empty autoksyms.h

[3] updates autoksyms.h and recurses "make vmlinux"

--------(begin sub-make)--------
[4] Second build with new autoksyms.h

[5] is invoked because "vmlinux" is missing
---------(end sub-make)---------

[6] is invoked again despite "vmlinux" is up-to-date.

The reason of [6] is probably because Make already decided to update
"vmlinux" at the time of [2] because "vmlinux" was missing when Make
generated the dependency list. is costly, so it is better to not run it when unneeded.
Split CONFIG_TRIM_UNUSED_KSYMS handling to a dedicated target.

The reason of commit 2441e78b1919 ("kbuild: better abstract vmlinux
sequential prerequisites") was to cater to CONFIG_BUILD_DOCSRC, but
it was later removed by commit 184892925118 ("samples: move blackfin
gptimers-example from Documentation").

I also changed to simply exit with 1 or 0 to make
it look straightforward.

Signed-off-by: Masahiro Yamada <>

Makefile | 28 ++++++++++++----------------
scripts/ | 3 +--
2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index 1dab647..0a7bab6 100644
--- a/Makefile
+++ b/Makefile
@@ -987,21 +987,11 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Doc


-# Include targets which we want to execute sequentially if the rest of the
-# kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be
-# evaluated more than once.
-PHONY += vmlinux_prereq
-vmlinux_prereq: $(vmlinux-deps) FORCE
- $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
- $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/
- $(Q)$(CONFIG_SHELL) $(srctree)/scripts/ \
- "$(MAKE) -f $(srctree)/Makefile vmlinux"
+# Recurse until is satisfied
+PHONY += autoksyms_recursive
+autoksyms_recursive: $(vmlinux-deps)
+ $(Q)$(CONFIG_SHELL) $(srctree)/scripts/ || \
+ $(MAKE) -f $(srctree)/Makefile autoksyms_recursive

# For the kernel to actually contain only the needed exported symbols,
# we have to build modules as well to determine what those symbols are.
@@ -1023,7 +1013,13 @@ cmd_link-vmlinux = \
$(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)

-vmlinux: scripts/ vmlinux_prereq $(vmlinux-deps) FORCE
+vmlinux: scripts/ autoksyms_recursive $(vmlinux-deps) FORCE
+ $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
+ $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/
+$(call if_changed,link-vmlinux)

# Build samples along the rest of the kernel
diff --git a/scripts/ b/scripts/
index 7bb3618..1377cf8 100755
--- a/scripts/
+++ b/scripts/
@@ -95,8 +95,7 @@ if [ $changed -gt 0 ]; then
info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
info "UPD" "$cur_ksyms_file"
mv -f "$new_ksyms_file" "$cur_ksyms_file"
- # Then trigger a rebuild of affected source files
- exec $@
+ exit 1
rm -f "$new_ksyms_file"
 \ /
  Last update: 2018-03-14 17:46    [W:0.137 / U:3.708 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site