aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Ravnborg2012-05-05 03:18:41 -0500
committerMichal Marek2012-05-05 14:19:33 -0500
commit1f2bfbd00e466ff3489b2ca5cc75b1cccd14c123 (patch)
tree6c630d3ee90a34d17f85d5c07dde67d4c27883a8 /Makefile
parent95698570510b7be9ab1542a4a908242c05a9b0ed (diff)
downloadkernel-common-1f2bfbd00e466ff3489b2ca5cc75b1cccd14c123.tar.gz
kernel-common-1f2bfbd00e466ff3489b2ca5cc75b1cccd14c123.tar.xz
kernel-common-1f2bfbd00e466ff3489b2ca5cc75b1cccd14c123.zip
kbuild: link of vmlinux moved to a script
Move the final link of vmlinux to a script to improve readability and maintainability of the code. The Makefile fragments used to link vmlinux has over the years seen far too many changes and the logic had become hard to follow. As the process by nature is serialized there was nothing gained including this in the Makefile. "um" has special link requirments - and the only way to handle this was to hard-code the linking of "um" in the script. This was better than trying to modularize it only for the benefit of "um" anyway. The shell script has been improved after input from: Arnaud Lacombe <lacombar@gmail.com> Nick Bowler <nbowler@elliptictech.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Cc: Arnaud Lacombe <lacombar@gmail.com> Cc: Nick Bowler <nbowler@elliptictech.com> Cc: Richard Weinberger <richard@nod.at> Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile215
1 files changed, 12 insertions, 203 deletions
diff --git a/Makefile b/Makefile
index 7ea0c07779b..a7cf6a11c4d 100644
--- a/Makefile
+++ b/Makefile
@@ -337,7 +337,6 @@ AWK = awk
337GENKSYMS = scripts/genksyms/genksyms 337GENKSYMS = scripts/genksyms/genksyms
338INSTALLKERNEL := installkernel 338INSTALLKERNEL := installkernel
339DEPMOD = /sbin/depmod 339DEPMOD = /sbin/depmod
340KALLSYMS = scripts/kallsyms
341PERL = perl 340PERL = perl
342CHECK = sparse 341CHECK = sparse
343 342
@@ -723,191 +722,21 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
723libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) 722libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
724libs-y := $(libs-y1) $(libs-y2) 723libs-y := $(libs-y1) $(libs-y2)
725 724
726# externally visible symbols 725# Externally visible symbols (used by link-vmlinux.sh)
727export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) 726export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
728export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y) 727export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y)
729export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 728export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
729export LDFLAGS_vmlinux
730 730
731# Build vmlinux 731vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)
732# ---------------------------------------------------------------------------
733# vmlinux is built from the objects selected by $(vmlinux-init) and
734# $(vmlinux-main). Most are built-in.o files from top-level directories
735# in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
736# Ordering when linking is important, and $(vmlinux-init) must be first.
737#
738# vmlinux
739# ^
740# |
741# +-< $(vmlinux-init)
742# | +--< init/version.o + more
743# |
744# +--< $(vmlinux-main)
745# | +--< driver/built-in.o mm/built-in.o + more
746# |
747# +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
748#
749# vmlinux version (uname -v) cannot be updated during normal
750# descending-into-subdirs phase since we do not yet know if we need to
751# update vmlinux.
752# Therefore this step is delayed until just before final link of vmlinux -
753# except in the kallsyms case where it is done just before adding the
754# symbols to the kernel.
755#
756# System.map is generated to document addresses of all kernel symbols
757
758vmlinux-init := $(head-y) $(init-y)
759vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
760vmlinux-all := $(vmlinux-init) $(vmlinux-main)
761vmlinux-lds := arch/$(SRCARCH)/kernel/vmlinux.lds
762
763# Rule to link vmlinux - also used during CONFIG_KALLSYMS
764# May be overridden by arch/$(ARCH)/Makefile
765quiet_cmd_vmlinux__ ?= LD $@
766 cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
767 -T $(vmlinux-lds) $(vmlinux-init) \
768 --start-group $(vmlinux-main) --end-group \
769 $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o FORCE ,$^)
770
771# Generate new vmlinux version
772quiet_cmd_vmlinux_version = GEN .version
773 cmd_vmlinux_version = set -e; \
774 if [ ! -r .version ]; then \
775 rm -f .version; \
776 echo 1 >.version; \
777 else \
778 mv .version .old_version; \
779 expr 0$$(cat .old_version) + 1 >.version; \
780 fi; \
781 $(MAKE) $(build)=init
782
783# Generate System.map
784quiet_cmd_sysmap = SYSMAP
785 cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
786
787# Link of vmlinux
788# If CONFIG_KALLSYMS is set .version is already updated
789# Generate System.map and verify that the content is consistent
790# Use + in front of the vmlinux_version rule to silent warning with make -j2
791# First command is ':' to allow us to use + in front of the rule
792define rule_vmlinux__
793 :
794 $(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version))
795
796 $(call cmd,vmlinux__)
797 $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
798
799 $(Q)$(if $($(quiet)cmd_sysmap), \
800 echo ' $($(quiet)cmd_sysmap) System.map' &&) \
801 $(cmd_sysmap) $@ System.map; \
802 if [ $$? -ne 0 ]; then \
803 rm -f $@; \
804 /bin/false; \
805 fi;
806 $(verify_kallsyms)
807endef
808
809
810ifdef CONFIG_KALLSYMS
811# Generate section listing all symbols and add it into vmlinux $(kallsyms.o)
812# It's a three stage process:
813# o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
814# empty
815# Running kallsyms on that gives us .tmp_kallsyms1.o with
816# the right size - vmlinux version (uname -v) is updated during this step
817# o .tmp_vmlinux2 now has a __kallsyms section of the right size,
818# but due to the added section, some addresses have shifted.
819# From here, we generate a correct .tmp_kallsyms2.o
820# o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
821# o Verify that the System.map from vmlinux matches the map from
822# .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
823# o If 'make KALLSYMS_EXTRA_PASS=1" was used, do an extra pass using
824# .tmp_vmlinux3 and .tmp_kallsyms3.o. This is only meant as a
825# temporary bypass to allow the kernel to be built while the
826# maintainers work out what went wrong with kallsyms.
827
828last_kallsyms := 2
829
830ifdef KALLSYMS_EXTRA_PASS
831ifneq ($(KALLSYMS_EXTRA_PASS),0)
832last_kallsyms := 3
833endif
834endif
835
836kallsyms.o := .tmp_kallsyms$(last_kallsyms).o
837
838define verify_kallsyms
839 $(Q)$(if $($(quiet)cmd_sysmap), \
840 echo ' $($(quiet)cmd_sysmap) .tmp_System.map' &&) \
841 $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
842 $(Q)cmp -s System.map .tmp_System.map || \
843 (echo Inconsistent kallsyms data; \
844 echo This is a bug - please report about it; \
845 echo Try "make KALLSYMS_EXTRA_PASS=1" as a workaround; \
846 rm .tmp_kallsyms* ; /bin/false )
847endef
848
849# Update vmlinux version before link
850# Use + in front of this rule to silent warning about make -j1
851# First command is ':' to allow us to use + in front of this rule
852cmd_ksym_ld = $(cmd_vmlinux__)
853define rule_ksym_ld
854 :
855 +$(call cmd,vmlinux_version)
856 $(call cmd,vmlinux__)
857 $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
858endef
859
860# Generate .S file with all kernel symbols
861quiet_cmd_kallsyms = KSYM $@
862 cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) \
863 $(if $(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
864
865.tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o: %.o: %.S scripts FORCE
866 $(call if_changed_dep,as_o_S)
867 732
868.tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS) 733# Final link of vmlinux
869 $(call cmd,kallsyms) 734 cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)
735quiet_cmd_link-vmlinux = LINK $@
870 736
871# .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version 737# Include targets which we want to
872.tmp_vmlinux1: $(vmlinux-lds) $(vmlinux-all) FORCE 738# execute if the rest of the kernel build went well.
873 $(call if_changed_rule,ksym_ld) 739vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE
874
875.tmp_vmlinux2: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms1.o FORCE
876 $(call if_changed,vmlinux__)
877
878.tmp_vmlinux3: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms2.o FORCE
879 $(call if_changed,vmlinux__)
880
881# Needs to visit scripts/ before $(KALLSYMS) can be used.
882$(KALLSYMS): scripts ;
883
884# Generate some data for debugging strange kallsyms problems
885debug_kallsyms: .tmp_map$(last_kallsyms)
886
887.tmp_map%: .tmp_vmlinux% FORCE
888 ($(OBJDUMP) -h $< | $(AWK) '/^ +[0-9]/{print $$4 " 0 " $$2}'; $(NM) $<) | sort > $@
889
890.tmp_map3: .tmp_map2
891
892.tmp_map2: .tmp_map1
893
894endif # ifdef CONFIG_KALLSYMS
895
896# Do modpost on a prelinked vmlinux. The finally linked vmlinux has
897# relevant sections renamed as per the linker script.
898quiet_cmd_vmlinux-modpost = LD $@
899 cmd_vmlinux-modpost = $(LD) $(LDFLAGS) -r -o $@ \
900 $(vmlinux-init) --start-group $(vmlinux-main) --end-group \
901 $(filter-out $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
902define rule_vmlinux-modpost
903 :
904 +$(call cmd,vmlinux-modpost)
905 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@
906 $(Q)echo 'cmd_$@ := $(cmd_vmlinux-modpost)' > $(dot-target).cmd
907endef
908
909# vmlinux image - including updated kernel symbols
910vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
911ifdef CONFIG_HEADERS_CHECK 740ifdef CONFIG_HEADERS_CHECK
912 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check 741 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
913endif 742endif
@@ -917,22 +746,11 @@ endif
917ifdef CONFIG_BUILD_DOCSRC 746ifdef CONFIG_BUILD_DOCSRC
918 $(Q)$(MAKE) $(build)=Documentation 747 $(Q)$(MAKE) $(build)=Documentation
919endif 748endif
920 $(call vmlinux-modpost) 749 +$(call if_changed,link-vmlinux)
921 $(call if_changed_rule,vmlinux__)
922 $(Q)rm -f .old_version
923
924# build vmlinux.o first to catch section mismatch errors early
925ifdef CONFIG_KALLSYMS
926.tmp_vmlinux1: vmlinux.o
927endif
928
929modpost-init := $(filter-out init/built-in.o, $(vmlinux-init))
930vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
931 $(call if_changed_rule,vmlinux-modpost)
932 750
933# The actual objects are generated when descending, 751# The actual objects are generated when descending,
934# make sure no implicit rule kicks in 752# make sure no implicit rule kicks in
935$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ; 753$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
936 754
937# Handle descending into subdirectories listed in $(vmlinux-dirs) 755# Handle descending into subdirectories listed in $(vmlinux-dirs)
938# Preset locale variables to speed up the build process. Limit locale 756# Preset locale variables to speed up the build process. Limit locale
@@ -1156,8 +974,6 @@ endif # CONFIG_MODULES
1156 974
1157# Directories & files removed with 'make clean' 975# Directories & files removed with 'make clean'
1158CLEAN_DIRS += $(MODVERDIR) 976CLEAN_DIRS += $(MODVERDIR)
1159CLEAN_FILES += vmlinux System.map \
1160 .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
1161 977
1162# Directories & files removed with 'make mrproper' 978# Directories & files removed with 'make mrproper'
1163MRPROPER_DIRS += include/config usr/include include/generated \ 979MRPROPER_DIRS += include/config usr/include include/generated \
@@ -1403,6 +1219,7 @@ scripts: ;
1403endif # KBUILD_EXTMOD 1219endif # KBUILD_EXTMOD
1404 1220
1405clean: $(clean-dirs) 1221clean: $(clean-dirs)
1222 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1406 $(call cmd,rmdirs) 1223 $(call cmd,rmdirs)
1407 $(call cmd,rmfiles) 1224 $(call cmd,rmfiles)
1408 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 1225 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
@@ -1536,14 +1353,6 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
1536cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \ 1353cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
1537 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) 1354 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
1538 1355
1539a_flags = -Wp,-MD,$(depfile) $(KBUILD_AFLAGS) $(AFLAGS_KERNEL) \
1540 $(KBUILD_AFLAGS_KERNEL) \
1541 $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CPPFLAGS) \
1542 $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
1543
1544quiet_cmd_as_o_S = AS $@
1545cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
1546
1547# read all saved command lines 1356# read all saved command lines
1548 1357
1549targets := $(wildcard $(sort $(targets))) 1358targets := $(wildcard $(sort $(targets)))