@@ -231,10 +231,6 @@ endif
231231# Where to locate arch specific headers
232232hdr-arch := $(SRCARCH )
233233
234- ifeq ($(ARCH ) ,m68knommu)
235- hdr-arch := m68k
236- endif
237-
238234KCONFIG_CONFIG ?= .config
239235export KCONFIG_CONFIG
240236
@@ -341,7 +337,6 @@ AWK = awk
341337GENKSYMS = scripts/genksyms/genksyms
342338INSTALLKERNEL := installkernel
343339DEPMOD = /sbin/depmod
344- KALLSYMS = scripts/kallsyms
345340PERL = perl
346341CHECK = sparse
347342
@@ -739,197 +734,21 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
739734libs-y2 := $(patsubst % /, % /built-in.o, $(libs-y ) )
740735libs-y := $(libs-y1 ) $(libs-y2 )
741736
742- # Build vmlinux
743- # ---------------------------------------------------------------------------
744- # vmlinux is built from the objects selected by $(vmlinux-init) and
745- # $(vmlinux-main). Most are built-in.o files from top-level directories
746- # in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
747- # Ordering when linking is important, and $(vmlinux-init) must be first.
748- #
749- # vmlinux
750- # ^
751- # |
752- # +-< $(vmlinux-init)
753- # | +--< init/version.o + more
754- # |
755- # +--< $(vmlinux-main)
756- # | +--< driver/built-in.o mm/built-in.o + more
757- # |
758- # +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
759- #
760- # vmlinux version (uname -v) cannot be updated during normal
761- # descending-into-subdirs phase since we do not yet know if we need to
762- # update vmlinux.
763- # Therefore this step is delayed until just before final link of vmlinux -
764- # except in the kallsyms case where it is done just before adding the
765- # symbols to the kernel.
766- #
767- # System.map is generated to document addresses of all kernel symbols
768-
769- vmlinux-init := $(head-y ) $(init-y )
770- vmlinux-main := $(core-y ) $(libs-y ) $(drivers-y ) $(net-y )
771- vmlinux-all := $(vmlinux-init ) $(vmlinux-main )
772- vmlinux-lds := arch/$(SRCARCH ) /kernel/vmlinux.lds
773- export KBUILD_VMLINUX_OBJS := $(vmlinux-all )
774-
775- # Rule to link vmlinux - also used during CONFIG_KALLSYMS
776- # May be overridden by arch/$(ARCH)/Makefile
777- quiet_cmd_vmlinux__ ?= LD $@
778- cmd_vmlinux__ ?= $(LD ) $(LDFLAGS ) $(LDFLAGS_vmlinux ) -o $@ \
779- -T $(vmlinux-lds ) $(vmlinux-init ) \
780- --start-group $(vmlinux-main ) --end-group \
781- $(filter-out $(vmlinux-lds ) $(vmlinux-init ) $(vmlinux-main ) vmlinux.o FORCE ,$^ )
782-
783- # Generate new vmlinux version
784- quiet_cmd_vmlinux_version = GEN .version
785- cmd_vmlinux_version = set -e; \
786- if [ ! -r .version ]; then \
787- rm -f .version; \
788- echo 1 >.version; \
789- else \
790- mv .version .old_version; \
791- expr 0$$(cat .old_version ) + 1 >.version; \
792- fi; \
793- $(MAKE ) $(build ) =init
794-
795- # Generate System.map
796- quiet_cmd_sysmap = SYSMAP
797- cmd_sysmap = $(CONFIG_SHELL ) $(srctree ) /scripts/mksysmap
798-
799- # Sort exception table at build time
800- quiet_cmd_sortextable = SORTEX
801- cmd_sortextable = $(objtree ) /scripts/sortextable
802-
803- # Link of vmlinux
804- # If CONFIG_KALLSYMS is set .version is already updated
805- # Generate System.map and verify that the content is consistent
806- # Use + in front of the vmlinux_version rule to silent warning with make -j2
807- # First command is ':' to allow us to use + in front of the rule
808- define rule_vmlinux__
809- :
810- $(if $(CONFIG_KALLSYMS ) ,,+$(call cmd,vmlinux_version) )
811-
812- $(call cmd,vmlinux__)
813- $(Q ) echo 'cmd_$@ := $(cmd_vmlinux__ ) ' > $(@D ) /.$(@F ) .cmd
814-
815- $(if $(CONFIG_BUILDTIME_EXTABLE_SORT ) , \
816- $(Q )$(if $($(quiet ) cmd_sortextable) , \
817- echo ' $($(quiet ) cmd_sortextable) vmlinux' &&) \
818- $(cmd_sortextable ) vmlinux)
819-
820-
821- $(Q )$(if $($(quiet ) cmd_sysmap) , \
822- echo ' $($(quiet ) cmd_sysmap) System.map' &&) \
823- $(cmd_sysmap ) $@ System.map; \
824- if [ $$? -ne 0 ]; then \
825- rm -f $@ ; \
826- /bin/false; \
827- fi;
828- $(verify_kallsyms )
829- endef
830-
831-
832- ifdef CONFIG_KALLSYMS
833- # Generate section listing all symbols and add it into vmlinux $(kallsyms.o)
834- # It's a three stage process:
835- # o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
836- # empty
837- # Running kallsyms on that gives us .tmp_kallsyms1.o with
838- # the right size - vmlinux version (uname -v) is updated during this step
839- # o .tmp_vmlinux2 now has a __kallsyms section of the right size,
840- # but due to the added section, some addresses have shifted.
841- # From here, we generate a correct .tmp_kallsyms2.o
842- # o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
843- # o Verify that the System.map from vmlinux matches the map from
844- # .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
845- # o If 'make KALLSYMS_EXTRA_PASS=1" was used, do an extra pass using
846- # .tmp_vmlinux3 and .tmp_kallsyms3.o. This is only meant as a
847- # temporary bypass to allow the kernel to be built while the
848- # maintainers work out what went wrong with kallsyms.
849-
850- last_kallsyms := 2
851-
852- ifdef KALLSYMS_EXTRA_PASS
853- ifneq ($(KALLSYMS_EXTRA_PASS ) ,0)
854- last_kallsyms := 3
855- endif
856- endif
857-
858- kallsyms.o := .tmp_kallsyms$(last_kallsyms ) .o
859-
860- define verify_kallsyms
861- $(Q )$(if $($(quiet ) cmd_sysmap) , \
862- echo ' $($(quiet ) cmd_sysmap) .tmp_System.map' &&) \
863- $(cmd_sysmap ) .tmp_vmlinux$(last_kallsyms ) .tmp_System.map
864- $(Q ) cmp -s System.map .tmp_System.map || \
865- (echo Inconsistent kallsyms data; \
866- echo This is a bug - please report about it; \
867- echo Try "make KALLSYMS_EXTRA_PASS=1" as a workaround; \
868- rm .tmp_kallsyms* ; /bin/false )
869- endef
870-
871- # Update vmlinux version before link
872- # Use + in front of this rule to silent warning about make -j1
873- # First command is ':' to allow us to use + in front of this rule
874- cmd_ksym_ld = $(cmd_vmlinux__ )
875- define rule_ksym_ld
876- :
877- +$(call cmd,vmlinux_version)
878- $(call cmd,vmlinux__)
879- $(Q ) echo 'cmd_$@ := $(cmd_vmlinux__ ) ' > $(@D ) /.$(@F ) .cmd
880- endef
881-
882- # Generate .S file with all kernel symbols
883- quiet_cmd_kallsyms = KSYM $@
884- cmd_kallsyms = $(NM ) -n $< | $(KALLSYMS ) \
885- $(if $(CONFIG_KALLSYMS_ALL ) ,--all-symbols) > $@
737+ # Externally visible symbols (used by link-vmlinux.sh)
738+ export KBUILD_VMLINUX_INIT := $(head-y ) $(init-y )
739+ export KBUILD_VMLINUX_MAIN := $(core-y ) $(libs-y ) $(drivers-y ) $(net-y )
740+ export KBUILD_LDS := arch/$(SRCARCH ) /kernel/vmlinux.lds
741+ export LDFLAGS_vmlinux
886742
887- .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o : % .o: % .S scripts FORCE
888- $(call if_changed_dep,as_o_S)
743+ vmlinux-deps := $(KBUILD_LDS ) $(KBUILD_VMLINUX_INIT ) $(KBUILD_VMLINUX_MAIN )
889744
890- .tmp_kallsyms% .S : .tmp_vmlinux% $(KALLSYMS )
891- $(call cmd,kallsyms)
745+ # Final link of vmlinux
746+ cmd_link-vmlinux = $(CONFIG_SHELL ) $< $(LD ) $(LDFLAGS ) $(LDFLAGS_vmlinux )
747+ quiet_cmd_link-vmlinux = LINK $@
892748
893- # .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version
894- .tmp_vmlinux1 : $(vmlinux-lds ) $(vmlinux-all ) FORCE
895- $(call if_changed_rule,ksym_ld)
896-
897- .tmp_vmlinux2 : $(vmlinux-lds ) $(vmlinux-all ) .tmp_kallsyms1.o FORCE
898- $(call if_changed,vmlinux__)
899-
900- .tmp_vmlinux3 : $(vmlinux-lds ) $(vmlinux-all ) .tmp_kallsyms2.o FORCE
901- $(call if_changed,vmlinux__)
902-
903- # Needs to visit scripts/ before $(KALLSYMS) can be used.
904- $(KALLSYMS ) : scripts ;
905-
906- # Generate some data for debugging strange kallsyms problems
907- debug_kallsyms : .tmp_map$(last_kallsyms )
908-
909- .tmp_map% : .tmp_vmlinux% FORCE
910- ($( OBJDUMP) -h $< | $( AWK) ' /^ +[0-9]/{print $$4 " 0 " $$2}' ; $( NM) $< ) | sort > $@
911-
912- .tmp_map3 : .tmp_map2
913-
914- .tmp_map2 : .tmp_map1
915-
916- endif # ifdef CONFIG_KALLSYMS
917-
918- # Do modpost on a prelinked vmlinux. The finally linked vmlinux has
919- # relevant sections renamed as per the linker script.
920- quiet_cmd_vmlinux-modpost = LD $@
921- cmd_vmlinux-modpost = $(LD ) $(LDFLAGS ) -r -o $@ \
922- $(vmlinux-init ) --start-group $(vmlinux-main ) --end-group \
923- $(filter-out $(vmlinux-init ) $(vmlinux-main ) FORCE ,$^ )
924- define rule_vmlinux-modpost
925- :
926- +$(call cmd,vmlinux-modpost)
927- $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.modpost $@
928- $(Q ) echo 'cmd_$@ := $(cmd_vmlinux-modpost ) ' > $(dot-target ) .cmd
929- endef
930-
931- # vmlinux image - including updated kernel symbols
932- vmlinux : $(vmlinux-lds ) $(vmlinux-init ) $(vmlinux-main ) vmlinux.o $(kallsyms.o ) FORCE
749+ # Include targets which we want to
750+ # execute if the rest of the kernel build went well.
751+ vmlinux : scripts/link-vmlinux.sh $(vmlinux-deps ) FORCE
933752ifdef CONFIG_HEADERS_CHECK
934753 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
935754endif
@@ -939,22 +758,11 @@ endif
939758ifdef CONFIG_BUILD_DOCSRC
940759 $(Q)$(MAKE) $(build)=Documentation
941760endif
942- $(call vmlinux-modpost)
943- $(call if_changed_rule,vmlinux__)
944- $(Q)rm -f .old_version
945-
946- # build vmlinux.o first to catch section mismatch errors early
947- ifdef CONFIG_KALLSYMS
948- .tmp_vmlinux1 : vmlinux.o
949- endif
950-
951- modpost-init := $(filter-out init/built-in.o, $(vmlinux-init ) )
952- vmlinux.o : $(modpost-init ) $(vmlinux-main ) FORCE
953- $(call if_changed_rule,vmlinux-modpost)
761+ +$(call if_changed,link-vmlinux)
954762
955763# The actual objects are generated when descending,
956764# make sure no implicit rule kicks in
957- $(sort $(vmlinux-init ) $( vmlinux-main ) ) $( vmlinux-lds ) : $(vmlinux-dirs ) ;
765+ $(sort $(vmlinux-deps ) ) : $(vmlinux-dirs ) ;
958766
959767# Handle descending into subdirectories listed in $(vmlinux-dirs)
960768# Preset locale variables to speed up the build process. Limit locale
@@ -1181,8 +989,6 @@ endif # CONFIG_MODULES
1181989
1182990# Directories & files removed with 'make clean'
1183991CLEAN_DIRS += $(MODVERDIR )
1184- CLEAN_FILES += vmlinux System.map \
1185- .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
1186992
1187993# Directories & files removed with 'make mrproper'
1188994MRPROPER_DIRS += include/config usr/include include/generated \
@@ -1428,6 +1234,7 @@ scripts: ;
14281234endif # KBUILD_EXTMOD
14291235
14301236clean : $(clean-dirs )
1237+ $(Q )$(CONFIG_SHELL ) $(srctree ) /scripts/link-vmlinux.sh clean
14311238 $(call cmd,rmdirs)
14321239 $(call cmd,rmfiles)
14331240 @find $(if $(KBUILD_EXTMOD ) , $(KBUILD_EXTMOD ) , .) $(RCS_FIND_IGNORE ) \
@@ -1568,14 +1375,6 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
15681375cmd_crmodverdir = $(Q ) mkdir -p $(MODVERDIR ) \
15691376 $(if $(KBUILD_MODULES ) ,; rm -f $(MODVERDIR ) /* )
15701377
1571- a_flags = -Wp,-MD,$(depfile ) $(KBUILD_AFLAGS ) $(AFLAGS_KERNEL ) \
1572- $(KBUILD_AFLAGS_KERNEL ) \
1573- $(NOSTDINC_FLAGS ) $(LINUXINCLUDE ) $(KBUILD_CPPFLAGS ) \
1574- $(modkern_aflags ) $(EXTRA_AFLAGS ) $(AFLAGS_$(basetarget ) .o )
1575-
1576- quiet_cmd_as_o_S = AS $@
1577- cmd_as_o_S = $(CC ) $(a_flags ) -c -o $@ $<
1578-
15791378# read all saved command lines
15801379
15811380targets := $(wildcard $(sort $(targets ) ) )
0 commit comments