1. Make compilation of Linux kernel source code
This article summarizes what the top-level Makefile does when making the Linux kernel source code. That is to summarize the make process of the Linux kernel source code.
This article is a continuation of the previous article at the following address:
2. Summary of Linux make process
1. vmlinux
When executing the "make" command to compile the Linux kernel source code, the top-level Makefile will compile target _all . After the analysis of the previous article, target _all ultimately depends on vmlinux , and vmlinux in the top-level Makefile depends on the following:
vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE
...
+$(call if_changed,link-vmlinux)
The focus here is to analyze "scripts/link-vmlinux.sh $(vmlinux-deps) FORCE".
Among them, link-vmlinux.sh is just a script file, and the rest is to analyze the dependency vmlinux-deps.
The dependency vmlinux-deps depends on $(head-y) , $(init-y) , $(core-y) , $(libs-y) , $(drivers-y) and $(net-y). six variables.
These six variables have been analyzed in the previous article.
These variables are all built-in.o or .a files. This is the same as oubot. They compile the source code files in the corresponding directories and then generate built-in.o files in the respective directories. Some of them generate . a library file. Finally, these built-in.o and .a files are linked to form an executable file in ELF format, which is vmlinux !
2. Commands that vmlinux depends on
+$(call if_changed,link-vmlinux)
Indicates that the result of $(call if_changed,link-vmlinux) will be used as the final command to generate vmlinux . The " + " in front indicates that the result of the command cannot be ignored. $(call if_changed,link-vmlinux) is to call the function if_changed , link-vmlinux is the parameter of the function if_changed .
The function if_changed is defined in the file scripts/Kbuild.include as follows:
247 if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
248 @set -e; \
249 $(echo-cmd) $(cmd_$(1)); \
250 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
914 # Final link of vmlinux
915 cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS)
$(LDFLAGS_vmlinux)
916 quiet_cmd_link-vmlinux = LINK $@
cmd_link-vmlinux = /bin/bash scripts/link-vmlinux.sh arm-linux-gnueabihf-ld -EL -p --noundefined -X --pic-veneer --build-id
3. vmliux_link function
51 vmlinux_link()
52 {
53 local lds="${objtree}/${KBUILD_LDS}"
54
55 if [ "${SRCARCH}" != "um" ]; then
56 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
57 -T ${lds} ${KBUILD_VMLINUX_INIT} \
58 --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1}
59 else
60 ${CC} ${CFLAGS_vmlinux} -o ${2} \
61 -Wl,-T,${lds} ${KBUILD_VMLINUX_INIT} \
62 -Wl,--start-group \
63 ${KBUILD_VMLINUX_MAIN} \
64 -Wl,--end-group \
65 -lutil ${1}
66 rm -f linux
67 fi
68 }
......
216 info LD vmlinux
217 vmlinux_link "${kallsymso}" vmlinux