您现在的位置是:首页 >技术教程 >vmlinux编译过程网站首页技术教程
vmlinux编译过程
1、进入linux内核源码目录下,打开Makefile文件,搜索vmlinux
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
+$(call if_changed,link-vmlinux)
vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o init/built-in.a usr/built-in.a arch/arm/built-in.a arch/arm/mach-aspeed/built-in.a arch/arm/mach-milbeaut/built-in.a arch/arm/mach-stm32/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a arch/arm/lib/built-in.a lib/built-in.a arch/arm/lib/lib.a lib/lib.a drivers/built-in.a sound/built-in.a samples/built-in.a net/built-in.a virt/built-in.a
cmd_link-vmlinux =
$(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)";
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
sh scripts/link-vmlinux.sh arm-linux-gnueabihf-ld -EL --no-undefined -X --pic-veneer --build-id=sha1 --orphan-handling=warn
2、scripts/Kbuild.include------->if_changed
if_changed = $(if $(newer-prereqs)$(cmd-check),
$(cmd);
printf '%s ' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
3、分析scripts/link-vmlinux.sh
# vmlinux
# ^
# |
# +--< $(KBUILD_VMLINUX_OBJS)
# | +--< init/built-in.a drivers/built-in.a mm/built-in.a + more
# |
# +--< $(KBUILD_VMLINUX_LIBS)
# | +--< lib/lib.a + more
# |
# +-< ${kallsymso} (see description in KALLSYMS section)
info LD vmlinux.o
modpost_link vmlinux.o
objtool_link vmlinux.o
modpost_link()
{
local objectsobjects="--whole-archive
${KBUILD_VMLINUX_OBJS}
--no-whole-archive
--start-group
${KBUILD_VMLINUX_LIBS}
--end-group"${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${objects}
}
arm-linux-gnueabihf-ld -EL -r -o vmlinux.o --whole-archive arch/arm/kernel/head.o init/built-in.a usr/built-in.a arch/arm/built-in.a arch/arm/mach-aspeed/built-in.a arch/arm/mach-milbeaut/built-in.a arch/arm/mach-stm32/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a arch/arm/lib/built-in.a lib/built-in.a arch/arm/lib/lib.a lib/lib.a drivers/built-in.a sound/built-in.a samples/built-in.a net/built-in.a virt/built-in.a --no-whole-archive --start-group --end-group
4、Makefile------->KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
# Externally visible symbols (used by link-vmlinux.sh)
KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
ifdef CONFIG_MODULES
KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
else
KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
endif
KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
# Objects we will link into vmlinux / subdirs we need to visit
core-y := init/ usr/
drivers-y := drivers/ sound/
drivers-$(CONFIG_SAMPLES) += samples/
drivers-y += net/ virt/
libs-y := lib/