.. | .. |
---|
6 | 6 | # Stage one of module building created the following: |
---|
7 | 7 | # a) The individual .o files used for the module |
---|
8 | 8 | # b) A <module>.o file which is the .o files above linked together |
---|
9 | | -# c) A <module>.mod file in $(MODVERDIR)/, listing the name of the |
---|
10 | | -# the preliminary <module>.o file, plus all .o files |
---|
| 9 | +# c) A <module>.mod file, listing the name of the preliminary <module>.o file, |
---|
| 10 | +# plus all .o files |
---|
| 11 | +# d) modules.order, which lists all the modules |
---|
11 | 12 | |
---|
12 | 13 | # Stage 2 is handled by this file and does the following |
---|
13 | | -# 1) Find all modules from the files listed in $(MODVERDIR)/ |
---|
| 14 | +# 1) Find all modules listed in modules.order |
---|
14 | 15 | # 2) modpost is then used to |
---|
15 | 16 | # 3) create one <module>.mod.c file pr. module |
---|
16 | 17 | # 4) create one Module.symvers file with CRC for all exported symbols |
---|
17 | | -# 5) compile all <module>.mod.c files |
---|
18 | | -# 6) final link of the module to a <module.ko> file |
---|
19 | 18 | |
---|
20 | 19 | # Step 3 is used to place certain information in the module's ELF |
---|
21 | 20 | # section, including information such as: |
---|
22 | 21 | # Version magic (see include/linux/vermagic.h for full details) |
---|
23 | 22 | # - Kernel release |
---|
24 | 23 | # - SMP is CONFIG_SMP |
---|
25 | | -# - PREEMPT is CONFIG_PREEMPT |
---|
| 24 | +# - PREEMPT is CONFIG_PREEMPT[_RT] |
---|
26 | 25 | # - GCC Version |
---|
27 | 26 | # Module info |
---|
28 | 27 | # - Module version (MODULE_VERSION) |
---|
.. | .. |
---|
37 | 36 | # symbols in the final module linking stage |
---|
38 | 37 | # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. |
---|
39 | 38 | # This is solely useful to speed up test compiles |
---|
40 | | -PHONY := _modpost |
---|
41 | | -_modpost: __modpost |
---|
| 39 | + |
---|
| 40 | +PHONY := __modpost |
---|
| 41 | +__modpost: |
---|
42 | 42 | |
---|
43 | 43 | include include/config/auto.conf |
---|
44 | 44 | include scripts/Kbuild.include |
---|
45 | 45 | |
---|
46 | | -# When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info |
---|
47 | | -ifneq ($(KBUILD_EXTMOD),) |
---|
| 46 | +# for ld_flags |
---|
| 47 | +include scripts/Makefile.lib |
---|
48 | 48 | |
---|
49 | | -# set src + obj - they may be used when building the .mod.c file |
---|
| 49 | +mixed-build-prefix = $(if $(KBUILD_MIXED_TREE),$(KBUILD_MIXED_TREE)/) |
---|
| 50 | + |
---|
| 51 | +MODPOST = scripts/mod/modpost \ |
---|
| 52 | + $(if $(CONFIG_MODVERSIONS),-m) \ |
---|
| 53 | + $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ |
---|
| 54 | + $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ |
---|
| 55 | + $(if $(KBUILD_MODPOST_WARN),-w) \ |
---|
| 56 | + -o $@ |
---|
| 57 | + |
---|
| 58 | +ifdef MODPOST_VMLINUX |
---|
| 59 | + |
---|
| 60 | +quiet_cmd_modpost = MODPOST $@ |
---|
| 61 | + cmd_modpost = $(MODPOST) $< |
---|
| 62 | + |
---|
| 63 | +vmlinux.symvers: vmlinux.o |
---|
| 64 | + $(call cmd,modpost) |
---|
| 65 | + |
---|
| 66 | +__modpost: vmlinux.symvers |
---|
| 67 | + |
---|
| 68 | +else |
---|
| 69 | + |
---|
| 70 | +ifeq ($(KBUILD_EXTMOD),) |
---|
| 71 | + |
---|
| 72 | +input-symdump := $(mixed-build-prefix)vmlinux.symvers |
---|
| 73 | +output-symdump := modules-only.symvers |
---|
| 74 | +module_srcpath := $(srctree) |
---|
| 75 | + |
---|
| 76 | +quiet_cmd_cat = GEN $@ |
---|
| 77 | + cmd_cat = cat $(real-prereqs) > $@ |
---|
| 78 | + |
---|
| 79 | +ifneq ($(wildcard $(mixed-build-prefix)vmlinux.symvers),) |
---|
| 80 | + |
---|
| 81 | +__modpost: Module.symvers |
---|
| 82 | +Module.symvers: $(mixed-build-prefix)vmlinux.symvers modules-only.symvers FORCE |
---|
| 83 | + $(call if_changed,cat) |
---|
| 84 | + |
---|
| 85 | +targets += Module.symvers |
---|
| 86 | + |
---|
| 87 | +endif |
---|
| 88 | + |
---|
| 89 | +else |
---|
| 90 | + |
---|
| 91 | +# set src + obj - they may be used in the modules's Makefile |
---|
50 | 92 | obj := $(KBUILD_EXTMOD) |
---|
51 | 93 | src := $(obj) |
---|
52 | 94 | |
---|
53 | 95 | # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS |
---|
54 | | -include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ |
---|
55 | | - $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) |
---|
| 96 | +include $(if $(wildcard $(src)/Kbuild), $(src)/Kbuild, $(src)/Makefile) |
---|
| 97 | + |
---|
| 98 | +# modpost option for external modules |
---|
| 99 | +MODPOST += -e |
---|
| 100 | + |
---|
| 101 | +input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS) |
---|
| 102 | +output-symdump := $(KBUILD_EXTMOD)/Module.symvers |
---|
| 103 | + |
---|
| 104 | +# Get the external module's source path. KBUILD_EXTMOD could either be an |
---|
| 105 | +# absolute path or relative path from $(srctree). This makes sure that we |
---|
| 106 | +# aren't using a relative path from a separate working directory (O= or |
---|
| 107 | +# KBUILD_OUTPUT) since that may not be the actual module's SCM project path. So |
---|
| 108 | +# check the path relative to $(srctree) first. |
---|
| 109 | +ifneq ($(realpath $(srctree)/$(KBUILD_EXTMOD) 2>/dev/null),) |
---|
| 110 | + module_srcpath := $(srctree)/$(KBUILD_EXTMOD) |
---|
| 111 | +else |
---|
| 112 | + module_srcpath := $(KBUILD_EXTMOD) |
---|
56 | 113 | endif |
---|
57 | 114 | |
---|
58 | | -include scripts/Makefile.lib |
---|
| 115 | +endif |
---|
59 | 116 | |
---|
60 | | -kernelsymfile := $(objtree)/Module.symvers |
---|
61 | | -modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers |
---|
| 117 | +ifeq ($(CONFIG_MODULE_SCMVERSION),y) |
---|
| 118 | +# Get the SCM version of the module. `sed` verifies setlocalversion returns |
---|
| 119 | +# a proper revision based on the SCM type, e.g. git, mercurial, or svn. |
---|
| 120 | +module_scmversion := $(shell $(srctree)/scripts/setlocalversion $(module_srcpath) | \ |
---|
| 121 | + sed -n 's/.*-\(\(g\|hg\)[a-fA-F0-9]\+\(-dirty\)\?\|svn[0-9]\+\).*/\1/p') |
---|
| 122 | +ifneq ($(module_scmversion),) |
---|
| 123 | +MODPOST += -v $(module_scmversion) |
---|
| 124 | +endif |
---|
| 125 | +endif |
---|
62 | 126 | |
---|
63 | | -# Step 1), find all modules listed in $(MODVERDIR)/ |
---|
64 | | -MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort -u |
---|
65 | | -__modules := $(shell $(MODLISTCMD)) |
---|
66 | | -modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o))) |
---|
| 127 | +# modpost options for modules (both in-kernel and external) |
---|
| 128 | +MODPOST += \ |
---|
| 129 | + $(addprefix -i ,$(wildcard $(input-symdump))) \ |
---|
| 130 | + $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ |
---|
| 131 | + $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) |
---|
67 | 132 | |
---|
68 | | -# Stop after building .o files if NOFINAL is set. Makes compile tests quicker |
---|
69 | | -_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules)) |
---|
| 133 | +# 'make -i -k' ignores compile errors, and builds as many modules as possible. |
---|
| 134 | +ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) |
---|
| 135 | +MODPOST += -n |
---|
| 136 | +endif |
---|
70 | 137 | |
---|
71 | | -# Step 2), invoke modpost |
---|
72 | | -# Includes step 3,4 |
---|
73 | | -modpost = scripts/mod/modpost \ |
---|
74 | | - $(if $(CONFIG_MODVERSIONS),-m) \ |
---|
75 | | - $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \ |
---|
76 | | - $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ |
---|
77 | | - $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ |
---|
78 | | - $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \ |
---|
79 | | - $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ |
---|
80 | | - $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ |
---|
81 | | - $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ |
---|
82 | | - $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) |
---|
83 | | - |
---|
84 | | -MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS))) |
---|
85 | | - |
---|
86 | | -# If CONFIG_LTO_CLANG is enabled, .o files are either LLVM IR, or empty, so we |
---|
87 | | -# need to link them into actual objects before passing them to modpost |
---|
88 | | -modpost-ext = $(if $(CONFIG_LTO_CLANG),.lto,) |
---|
| 138 | +# Clear VPATH to not search for *.symvers in $(srctree). Check only $(objtree). |
---|
| 139 | +VPATH := |
---|
| 140 | +$(input-symdump): |
---|
| 141 | + @echo >&2 'WARNING: Symbol version dump "$@" is missing.' |
---|
| 142 | + @echo >&2 ' Modules may not have dependencies or modversions.' |
---|
89 | 143 | |
---|
90 | 144 | ifdef CONFIG_LTO_CLANG |
---|
91 | | -quiet_cmd_cc_lto_link_modules = LD [M] $@ |
---|
92 | | -cmd_cc_lto_link_modules = \ |
---|
93 | | - $(LD) $(ld_flags) -r -o $(@) \ |
---|
94 | | - $(shell [ -s $(@:$(modpost-ext).o=.o.symversions) ] && \ |
---|
95 | | - echo -T $(@:$(modpost-ext).o=.o.symversions)) \ |
---|
96 | | - --whole-archive $(filter-out FORCE,$^) |
---|
| 145 | +# With CONFIG_LTO_CLANG, .o files might be LLVM bitcode, so we need to run |
---|
| 146 | +# LTO to compile them into native code before running modpost |
---|
| 147 | +prelink-ext := .lto |
---|
97 | 148 | |
---|
98 | | -$(modules:.ko=$(modpost-ext).o): %$(modpost-ext).o: %.o FORCE |
---|
| 149 | +quiet_cmd_cc_lto_link_modules = LTO [M] $@ |
---|
| 150 | +cmd_cc_lto_link_modules = \ |
---|
| 151 | + $(LD) $(ld_flags) -r -o $@ \ |
---|
| 152 | + $(shell [ -s $(@:.lto.o=.o.symversions) ] && \ |
---|
| 153 | + echo -T $(@:.lto.o=.o.symversions)) \ |
---|
| 154 | + --whole-archive $^ |
---|
| 155 | + |
---|
| 156 | +%.lto.o: %.o |
---|
99 | 157 | $(call if_changed,cc_lto_link_modules) |
---|
100 | 158 | endif |
---|
101 | 159 | |
---|
102 | | -# We can go over command line length here, so be careful. |
---|
103 | | -quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules |
---|
104 | | - cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/$(modpost-ext)\.o/' | $(modpost) $(MODPOST_OPT) -s -T - |
---|
| 160 | +modules := $(sort $(shell cat $(MODORDER))) |
---|
105 | 161 | |
---|
106 | | -PHONY += __modpost |
---|
107 | | -__modpost: $(modules:.ko=$(modpost-ext).o) FORCE |
---|
108 | | - $(call cmd,modpost) $(wildcard vmlinux) |
---|
| 162 | +# Read out modules.order to pass in modpost. |
---|
| 163 | +# Otherwise, allmodconfig would fail with "Argument list too long". |
---|
| 164 | +quiet_cmd_modpost = MODPOST $@ |
---|
| 165 | + cmd_modpost = sed 's/\.ko$$/$(prelink-ext)\.o/' $< | $(MODPOST) -T - |
---|
109 | 166 | |
---|
110 | | -quiet_cmd_kernel-mod = MODPOST $@ |
---|
111 | | - cmd_kernel-mod = $(modpost) $@ |
---|
| 167 | +$(output-symdump): $(MODORDER) $(input-symdump) $(modules:.ko=$(prelink-ext).o) FORCE |
---|
| 168 | + $(call if_changed,modpost) |
---|
112 | 169 | |
---|
113 | | -vmlinux.o: FORCE |
---|
114 | | - $(call cmd,kernel-mod) |
---|
| 170 | +targets += $(output-symdump) |
---|
115 | 171 | |
---|
116 | | -# Declare generated files as targets for modpost |
---|
117 | | -$(modules:.ko=.mod.c): __modpost ; |
---|
118 | | - |
---|
119 | | -# Step 5), compile all *.mod.c files |
---|
120 | | - |
---|
121 | | -# modname is set to make c_flags define KBUILD_MODNAME |
---|
122 | | -modname = $(notdir $(@:.mod.o=)) |
---|
123 | | - |
---|
124 | | -quiet_cmd_cc_o_c = CC $@ |
---|
125 | | - cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ |
---|
126 | | - -c -o $@ $< |
---|
127 | | - |
---|
128 | | -$(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE |
---|
129 | | - $(call if_changed_dep,cc_o_c) |
---|
130 | | - |
---|
131 | | -targets += $(modules:.ko=.mod.o) |
---|
132 | | - |
---|
133 | | -ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) |
---|
134 | | - |
---|
135 | | -# Step 6), final link of the modules with optional arch pass after final link |
---|
136 | | -quiet_cmd_ld_ko_o = LD [M] $@ |
---|
137 | | - |
---|
138 | | -ifdef CONFIG_LTO_CLANG |
---|
139 | | - cmd_ld_ko_o = \ |
---|
140 | | - $(LD) -r $(LDFLAGS) \ |
---|
141 | | - $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ |
---|
142 | | - $(shell [ -s $(@:.ko=.o.symversions) ] && \ |
---|
143 | | - echo -T $(@:.ko=.o.symversions)) \ |
---|
144 | | - -o $@ --whole-archive \ |
---|
145 | | - $(filter-out FORCE,$(^:$(modpost-ext).o=.o)) |
---|
146 | | - |
---|
147 | | - ifdef CONFIG_FTRACE_MCOUNT_RECORD |
---|
148 | | - cmd_ld_ko_o += ; $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) $@ |
---|
149 | | - endif |
---|
150 | | -else |
---|
151 | | - cmd_ld_ko_o = \ |
---|
152 | | - $(LD) -r $(KBUILD_LDFLAGS) \ |
---|
153 | | - $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ |
---|
154 | | - -o $@ $(filter-out FORCE,$^) ; \ |
---|
155 | | - $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) |
---|
| 172 | +__modpost: $(output-symdump) |
---|
| 173 | +ifneq ($(KBUILD_MODPOST_NOFINAL),1) |
---|
| 174 | + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal |
---|
156 | 175 | endif |
---|
157 | 176 | |
---|
158 | | -$(modules): %.ko: %$(modpost-ext).o %.mod.o FORCE |
---|
159 | | - +$(call if_changed,ld_ko_o) |
---|
160 | | - |
---|
161 | | -targets += $(modules) |
---|
162 | | - |
---|
163 | | - |
---|
164 | | -# Add FORCE to the prequisites of a target to force it to be always rebuilt. |
---|
165 | | -# --------------------------------------------------------------------------- |
---|
166 | | - |
---|
167 | 177 | PHONY += FORCE |
---|
168 | | - |
---|
169 | 178 | FORCE: |
---|
170 | 179 | |
---|
171 | | -# Read all saved command lines and dependencies for the $(targets) we |
---|
172 | | -# may be building above, using $(if_changed{,_dep}). As an |
---|
173 | | -# optimization, we don't need to read them if the target does not |
---|
174 | | -# exist, we will rebuild anyway in that case. |
---|
| 180 | +existing-targets := $(wildcard $(sort $(targets))) |
---|
175 | 181 | |
---|
176 | | -cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) |
---|
| 182 | +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
---|
177 | 183 | |
---|
178 | | -ifneq ($(cmd_files),) |
---|
179 | | - include $(cmd_files) |
---|
180 | 184 | endif |
---|
181 | 185 | |
---|
182 | 186 | .PHONY: $(PHONY) |
---|