]>
Commit | Line | Data |
---|---|---|
785df1f9 AM |
1 | |
2 | From: Sam Ravnborg <sam@ravnborg.org> | |
3 | ||
4 | The external module support recently introduced caused a number of problems: | |
5 | - To build an external module the Module.symvers file was needed | |
6 | - To create the Module.symvers file a module was required | |
7 | - If Module.symvers was missing kbuild boiled out with an error | |
8 | - If vmlinux was missing also the stage 2 of module build failed (make -k) | |
9 | - It was not documented what was needed to actually bauild a module | |
10 | ||
11 | The following patch addresses this by adding the following functionality: | |
12 | - Always generate the Module.symvers file | |
13 | - Ignore a missing Module.symvers file | |
14 | - Add a new target modules_prepare, it prepares the kernel for building | |
15 | external modules, and is also usefull with O= | |
16 | - And it adds some more comments to Makefile.modpost, so others may follow | |
17 | it with some luck | |
18 | - .modpost.cmd is no longer generated | |
19 | ||
20 | This should close all reports on issues with respect to building external | |
21 | modules with current kernel - which has been identified as kernel problems. | |
22 | ||
23 | ||
24 | --- | |
25 | ||
26 | 25-akpm/Makefile | 6 ++ | |
27 | 25-akpm/scripts/Makefile.modpost | 86 ++++++++++++++++++++++++++------------- | |
28 | 25-akpm/scripts/modpost.c | 7 +-- | |
29 | 3 files changed, 66 insertions(+), 33 deletions(-) | |
30 | ||
31 | diff -puN Makefile~kbuild-improved-external-module-support Makefile | |
32 | --- 25/Makefile~kbuild-improved-external-module-support Tue Apr 20 14:46:06 2004 | |
33 | +++ 25-akpm/Makefile Tue Apr 20 14:46:06 2004 | |
34 | @@ -716,8 +716,12 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_B | |
35 | @echo ' Building modules, stage 2.'; | |
36 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost | |
37 | ||
38 | -# Install modules | |
39 | ||
40 | +# Target to prepare building external modules | |
41 | +.PHONY: modules_prepare | |
42 | +modules_prepare: prepare-all scripts | |
43 | + | |
44 | +# Target to install modules | |
45 | .PHONY: modules_install | |
46 | modules_install: _modinst_ _modinst_post | |
47 | ||
48 | diff -puN scripts/Makefile.modpost~kbuild-improved-external-module-support scripts/Makefile.modpost | |
49 | --- 25/scripts/Makefile.modpost~kbuild-improved-external-module-support Tue Apr 20 14:46:06 2004 | |
50 | +++ 25-akpm/scripts/Makefile.modpost Tue Apr 20 14:46:06 2004 | |
51 | @@ -1,34 +1,71 @@ | |
52 | # =========================================================================== | |
53 | # Module versions | |
54 | # =========================================================================== | |
55 | +# | |
56 | +# Stage one of module building created the following: | |
57 | +# a) The individual .o files used for the module | |
58 | +# b) A <module>.o file wich is the .o files above linked together | |
59 | +# c) A <module>.mod file in $(MODVERDIR)/, listing the name of the | |
60 | +# the preliminary <module>.o file, plus all .o files | |
61 | + | |
62 | +# Stage 2 is handled by this file and does the following | |
63 | +# 1) Find all modules from the files listed in $(MODVERDIR)/ | |
64 | +# 2) modpost is then used to | |
65 | +# 3) create one <module>.mod.c file pr. module | |
66 | +# 4) create one Module.symvers file with CRC for all exported symbols | |
67 | +# 5) compile all <module>.mod.c files | |
68 | +# 6) final link of the module to a <module.ko> file | |
69 | + | |
70 | +# Step 3 is used to place certain information in the module's ELF | |
71 | +# section, including information such as: | |
72 | +# Version magic (see include/vermagic.h for full details) | |
73 | +# - Kernel release | |
74 | +# - SMP is CONFIG_SMP | |
75 | +# - PREEMPT is CONFIG_PREEMPT | |
76 | +# - GCC Version | |
77 | +# Module info | |
78 | +# - Module version (MODULE_VERSION) | |
79 | +# - Module alias'es (MODULE_ALIAS) | |
80 | +# - Module license (MODULE_LICENSE) | |
81 | +# - See include/linux/module.h for more details | |
82 | + | |
83 | +# Step 4 is solely used to allow module versioning in external modules, | |
84 | +# where the CRC of each module is retreived from the Module.symers file. | |
85 | ||
86 | -.PHONY: __modversions | |
87 | -__modversions: | |
88 | +.PHONY: _modpost | |
89 | +_modpost: __modpost | |
90 | ||
91 | include .config | |
92 | include scripts/Makefile.lib | |
93 | ||
94 | -# | |
95 | +symverfile := $(objtree)/Module.symvers | |
96 | ||
97 | +# Step 1), find all modules listed in $(MODVERDIR)/ | |
98 | __modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod)) | |
99 | -modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o))) | |
100 | +modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o))) | |
101 | ||
102 | -__modversions: $(modules) | |
103 | - @: | |
104 | +_modpost: $(modules) | |
105 | ||
106 | -# The final module link | |
107 | ||
108 | -quiet_cmd_ld_ko_o = LD [M] $@ | |
109 | - cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \ | |
110 | - $(filter-out FORCE,$^) | |
111 | +# Step 2), invoke modpost | |
112 | +# Includes step 3,4 | |
113 | +quiet_cmd_modpost = MODPOST | |
114 | + cmd_modpost = scripts/modpost \ | |
115 | + $(if $(KBUILD_EXTMOD),-i,-o) $(symverfile) \ | |
116 | + $(filter-out FORCE,$^) | |
117 | ||
118 | -$(modules): %.ko :%.o %.mod.o FORCE | |
119 | - $(call if_changed,ld_ko_o) | |
120 | +.PHONY: __modpost | |
121 | +__modpost: $(wildcard vmlinux) $(modules:.ko=.o) FORCE | |
122 | + $(call cmd,modpost) | |
123 | + | |
124 | +# Declare generated files as targets for modpost | |
125 | +$(symverfile): __modpost ; | |
126 | +$(modules:.ko=.mod.c): __modpost ; | |
127 | ||
128 | -targets += $(modules) | |
129 | ||
130 | -# Compile version info for unresolved symbols | |
131 | +# Step 5), compile all *.mod.c files | |
132 | ||
133 | +# modname is set to make c_flags define KBUILD_MODNAME | |
134 | modname = $(*F) | |
135 | ||
136 | quiet_cmd_cc_o_c = CC $@ | |
137 | @@ -40,23 +77,16 @@ $(modules:.ko=.mod.o): %.mod.o: %.mod.c | |
138 | ||
139 | targets += $(modules:.ko=.mod.o) | |
140 | ||
141 | -# All the .mod.c files are generated using the helper "modpost" | |
142 | - | |
143 | -.PHONY: __modpost | |
144 | - | |
145 | -$(modules:.ko=.mod.c): __modpost ; | |
146 | - | |
147 | -# Extract all checksums for all exported symbols | |
148 | +# Step 6), final link of the modules | |
149 | +quiet_cmd_ld_ko_o = LD [M] $@ | |
150 | + cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \ | |
151 | + $(filter-out FORCE,$^) | |
152 | ||
153 | -quiet_cmd_modpost = MODPOST | |
154 | - cmd_modpost = scripts/modpost \ | |
155 | - $(if $(filter vmlinux,$^),-o,-i) $(objtree)/Module.symvers \ | |
156 | - $(filter-out FORCE,$^) | |
157 | +$(modules): %.ko :%.o %.mod.o FORCE | |
158 | + $(call if_changed,ld_ko_o) | |
159 | ||
160 | -__modpost: $(if $(KBUILD_EXTMOD),,$(wildcard vmlinux)) $(modules:.ko=.o) FORCE | |
161 | - $(call if_changed,modpost) | |
162 | +targets += $(modules) | |
163 | ||
164 | -targets += __modpost | |
165 | ||
166 | # Add FORCE to the prequisites of a target to force it to be always rebuilt. | |
167 | # --------------------------------------------------------------------------- | |
168 | diff -puN scripts/modpost.c~kbuild-improved-external-module-support scripts/modpost.c | |
169 | --- 25/scripts/modpost.c~kbuild-improved-external-module-support Tue Apr 20 14:46:06 2004 | |
170 | +++ 25-akpm/scripts/modpost.c Tue Apr 20 14:46:06 2004 | |
171 | @@ -625,10 +625,9 @@ read_dump(const char *fname) | |
172 | void *file = grab_file(fname, &size); | |
173 | char *line; | |
174 | ||
175 | - if (!file) { | |
176 | - perror(fname); | |
177 | - abort(); | |
178 | - } | |
179 | + if (!file) | |
180 | + /* No symbol versions, silently ignore */ | |
181 | + return; | |
182 | ||
183 | while ((line = get_next_line(&pos, file, size))) { | |
184 | char *symname, *modname, *d; | |
185 | ||
186 | _ |