Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fdc7d3

Browse files
committed
kbuild: link vmlinux only 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] adjust_autoksyms.sh updates autoksyms.h and recurses 'make vmlinux' --------(begin sub-make)-------- [4] Second build with new autoksyms.h [5] link-vmlinux.sh is invoked because vmlinux is missing ---------(end sub-make)--------- [6] link-vmlinux.sh 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 built up the dependency graph. Because if_changed is implemented based on $?, this issue can be narrowed down to how Make handles $?. You can test it with the following simple code: [Test Makefile] A: B @echo newer prerequisite: $? cp B A B: C cp C B touch A [Result] $ rm -f A B $ touch C $ make cp C B touch A newer prerequisite: B cp B A Here, 'A' has been touched in the recipe of 'B'. So, the dependency 'A: B' has already been met before the recipe of 'A' is executed. However, Make does not notice the fact that the recipe of 'B' also updates 'A' as a side-effect. The situation is similar in this case; the vmlinux has actually been updated in the vmlinux_prereq target. Make cannot predict this, so judges the vmlinux is old. link-vmlinux.sh is costly, so it is better to not run it when unneeded. Split CONFIG_TRIM_UNUSED_KSYMS recursion to a dedicated target. The reason of commit 2441e78 ("kbuild: better abstract vmlinux sequential prerequisites") was to cater to CONFIG_BUILD_DOCSRC, but it was later removed by commit 1848929 ("samples: move blackfin gptimers-example from Documentation"). Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Nicolas Pitre <[email protected]>
1 parent fbfa9be commit 3fdc7d3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Makefile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -996,17 +996,9 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Doc
996996

997997
vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS)
998998

999-
# Include targets which we want to execute sequentially if the rest of the
1000-
# kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be
1001-
# evaluated more than once.
1002-
PHONY += vmlinux_prereq
1003-
vmlinux_prereq: $(vmlinux-deps) FORCE
1004-
ifdef CONFIG_HEADERS_CHECK
1005-
$(Q)$(MAKE) -f $(srctree)/Makefile headers_check
1006-
endif
1007-
ifdef CONFIG_GDB_SCRIPTS
1008-
$(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1009-
endif
999+
# Recurse until adjust_autoksyms.sh is satisfied
1000+
PHONY += autoksyms_recursive
1001+
autoksyms_recursive: $(vmlinux-deps)
10101002
ifdef CONFIG_TRIM_UNUSED_KSYMS
10111003
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
10121004
"$(MAKE) -f $(srctree)/Makefile vmlinux"
@@ -1032,7 +1024,13 @@ cmd_link-vmlinux = \
10321024
$(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \
10331025
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
10341026

1035-
vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE
1027+
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
1028+
ifdef CONFIG_HEADERS_CHECK
1029+
$(Q)$(MAKE) -f $(srctree)/Makefile headers_check
1030+
endif
1031+
ifdef CONFIG_GDB_SCRIPTS
1032+
$(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1033+
endif
10361034
+$(call if_changed,link-vmlinux)
10371035

10381036
# Build samples along the rest of the kernel

0 commit comments

Comments
 (0)