| @@ -337,7 +337,6 @@ AWK = awk · 336 unmodified lines |
| 337 | 337 | GENKSYMS = scripts/genksyms/genksyms |
| 338 | 338 | INSTALLKERNEL := installkernel |
| 339 | 339 | DEPMOD = /sbin/depmod |
| 340 | | −KALLSYMS = scripts/kallsyms |
| 341 | 340 | PERL = perl |
| 342 | 341 | CHECK = sparse |
| 343 | 342 | |
| @@ -723,191 +722,21 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) · 379 unmodified lines |
| 723 | 722 | libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) |
| 724 | 723 | libs-y := $(libs-y1) $(libs-y2) |
| 725 | 724 | |
| 726 | | −# externally visible symbols |
| 725 | +# Externally visible symbols (used by link-vmlinux.sh) |
| 727 | 726 | export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) |
| 728 | 727 | export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y) |
| 729 | 728 | export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds |
| 729 | +export LDFLAGS_vmlinux |
| 730 | 730 | |
| 731 | | −# Build vmlinux |
| 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 | | − |
| 758 | | −vmlinux-init := $(head-y) $(init-y) |
| 759 | | −vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y) |
| 760 | | −vmlinux-all := $(vmlinux-init) $(vmlinux-main) |
| 761 | | −vmlinux-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 |
| 765 | | −quiet_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 |
| 772 | | −quiet_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 |
| 784 | | −quiet_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 |
| 792 | | −define 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) |
| 807 | | −endef |
| 808 | | − |
| 809 | | − |
| 810 | | −ifdef 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 | | − |
| 828 | | −last_kallsyms := 2 |
| 829 | | − |
| 830 | | −ifdef KALLSYMS_EXTRA_PASS |
| 831 | | −ifneq ($(KALLSYMS_EXTRA_PASS),0) |
| 832 | | −last_kallsyms := 3 |
| 833 | | −endif |
| 834 | | −endif |
| 835 | | − |
| 836 | | −kallsyms.o := .tmp_kallsyms$(last_kallsyms).o |
| 837 | | − |
| 838 | | −define 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 ) |
| 847 | | −endef |
| 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 |
| 852 | | −cmd_ksym_ld = $(cmd_vmlinux__) |
| 853 | | −define rule_ksym_ld |
| 854 | | − : |
| 855 | | − +$(call cmd,vmlinux_version) |
| 856 | | − $(call cmd,vmlinux__) |
| 857 | | − $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd |
| 858 | | −endef |
| 859 | | − |
| 860 | | −# Generate .S file with all kernel symbols |
| 861 | | −quiet_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) |
| 731 | +vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) |
| 867 | 732 | |
| 868 | | −.tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS) |
| 869 | | − $(call cmd,kallsyms) |
| 733 | +# Final link of vmlinux |
| 734 | + cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) |
| 735 | +quiet_cmd_link-vmlinux = LINK $@ |
| 870 | 736 | |
| 871 | | −# .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version |
| 872 | | −.tmp_vmlinux1: $(vmlinux-lds) $(vmlinux-all) FORCE |
| 873 | | − $(call if_changed_rule,ksym_ld) |
| 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 |
| 885 | | −debug_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 | | − |
| 894 | | −endif # 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. |
| 898 | | −quiet_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 ,$^) |
| 902 | | −define 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 |
| 907 | | −endef |
| 908 | | − |
| 909 | | −# vmlinux image - including updated kernel symbols |
| 910 | | −vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE |
| 737 | +# Include targets which we want to |
| 738 | +# execute if the rest of the kernel build went well. |
| 739 | +vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE |
| 911 | 740 | ifdef CONFIG_HEADERS_CHECK |
| 912 | 741 | $(Q)$(MAKE) -f $(srctree)/Makefile headers_check |
| 913 | 742 | endif |
| @@ -917,22 +746,11 @@ endif · 3 unmodified lines |
| 917 | 746 | ifdef CONFIG_BUILD_DOCSRC |
| 918 | 747 | $(Q)$(MAKE) $(build)=Documentation |
| 919 | 748 | endif |
| 920 | | − $(call vmlinux-modpost) |
| 921 | | − $(call if_changed_rule,vmlinux__) |
| 922 | | − $(Q)rm -f .old_version |
| 923 | | − |
| 924 | | −# build vmlinux.o first to catch section mismatch errors early |
| 925 | | −ifdef CONFIG_KALLSYMS |
| 926 | | −.tmp_vmlinux1: vmlinux.o |
| 927 | | −endif |
| 928 | | − |
| 929 | | −modpost-init := $(filter-out init/built-in.o, $(vmlinux-init)) |
| 930 | | −vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE |
| 931 | | − $(call if_changed_rule,vmlinux-modpost) |
| 749 | + +$(call if_changed,link-vmlinux) |
| 932 | 750 | |
| 933 | 751 | # The actual objects are generated when descending, |
| 934 | 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 | 755 | # Handle descending into subdirectories listed in $(vmlinux-dirs) |
| 938 | 756 | # Preset locale variables to speed up the build process. Limit locale |
| @@ -1156,8 +974,6 @@ endif # CONFIG_MODULES · 217 unmodified lines |
| 1156 | 974 | |
| 1157 | 975 | # Directories & files removed with 'make clean' |
| 1158 | 976 | CLEAN_DIRS += $(MODVERDIR) |
| 1159 | | −CLEAN_FILES += vmlinux System.map \ |
| 1160 | | − .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map |
| 1161 | 977 | |
| 1162 | 978 | # Directories & files removed with 'make mrproper' |
| 1163 | 979 | MRPROPER_DIRS += include/config usr/include include/generated \ |
| @@ -1403,6 +1219,7 @@ scripts: ; · 239 unmodified lines |
| 1403 | 1219 | endif # KBUILD_EXTMOD |
| 1404 | 1220 | |
| 1405 | 1221 | clean: $(clean-dirs) |
| 1222 | + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean |
| 1406 | 1223 | $(call cmd,rmdirs) |
| 1407 | 1224 | $(call cmd,rmfiles) |
| 1408 | 1225 | @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ |
| @@ -1536,14 +1353,6 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) · 127 unmodified lines |
| 1536 | 1353 | cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \ |
| 1537 | 1354 | $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) |
| 1538 | 1355 | |
| 1539 | | −a_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 | | − |
| 1544 | | −quiet_cmd_as_o_S = AS $@ |
| 1545 | | −cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< |
| 1546 | | − |
| 1547 | 1356 | # read all saved command lines |
| 1548 | 1357 | |
| 1549 | 1358 | targets := $(wildcard $(sort $(targets))) |