1 This patch updates the SLES 9 module build system to properly support
2 dependencies between external modules, similarly to the way they are
3 supported in newer kernels.
5 Index: linux-2.6.5-7.286/scripts/Makefile.modpost
6 ===================================================================
7 --- linux-2.6.5-7.286.orig/scripts/Makefile.modpost
8 +++ linux-2.6.5-7.286/scripts/Makefile.modpost
9 @@ -38,7 +38,8 @@ _modpost: __modpost
11 include scripts/Makefile.lib
13 -symverfile := $(objtree)/Module.symvers
14 +kernelsymfile := $(objtree)/Module.symvers
15 +modulesymfile := $(KBUILD_EXTMOD)/Module.symvers
17 # Step 1), find all modules listed in $(MODVERDIR)/
18 __modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod))
19 @@ -51,7 +52,9 @@ _modpost: $(modules)
21 quiet_cmd_modpost = MODPOST
22 cmd_modpost = scripts/modpost \
23 - $(if $(KBUILD_EXTMOD),-i,-o) $(symverfile) \
24 + $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
25 + $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
26 + $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
27 -s $(firstword $(wildcard $(dir $(MODVERDIR))/Module.supported \
28 $(objtree)/Module.supported /dev/null)) \
29 $(filter-out FORCE,$^)
30 Index: linux-2.6.5-7.286/scripts/modpost.c
31 ===================================================================
32 --- linux-2.6.5-7.286.orig/scripts/modpost.c
33 +++ linux-2.6.5-7.286/scripts/modpost.c
35 /* Postprocess module symbol versions
37 * Copyright 2003 Kai Germaschewski
38 - * 2002-2003 Rusty Russell, IBM Corporation
39 + * 2002-2004 Rusty Russell, IBM Corporation
40 + * Copyright 2006 Sam Ravnborg
42 * Based in part on module-init-tools/depmod.c,file2alias
46 /* Warn about undefined symbols? (do so if we have vmlinux) */
48 +/* If we are modposting external module set to 1 */
49 +static int external_module = 0;
52 fatal(const char *fmt, ...)
53 @@ -45,6 +48,19 @@ warn(const char *fmt, ...)
58 +is_vmlinux(const char *modname)
62 + if ((myname = strrchr(modname, '/')))
67 + return strcmp(myname, "vmlinux") == 0;
70 void *do_nofail(void *ptr, const char *expr)
73 @@ -101,6 +117,9 @@ struct symbol {
74 struct module *module;
77 + unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
78 + unsigned int kernel:1; /* 1 if symbol is from kernel
79 + * (only for external modules) **/
83 @@ -135,8 +154,8 @@ alloc_symbol(const char *name, struct sy
85 /* For the hash of exported symbols */
88 -new_symbol(const char *name, struct module *module, unsigned int *crc)
89 +static struct symbol *
90 +new_symbol(const char *name, struct module *module)
94 @@ -144,10 +163,7 @@ new_symbol(const char *name, struct modu
95 hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
96 new = symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
100 - new->crc_valid = 1;
106 @@ -168,19 +184,28 @@ find_symbol(const char *name)
108 /* Add an exported symbol - it may have already been added without a
109 * CRC, in this case just update the CRC */
111 -add_exported_symbol(const char *name, struct module *module, unsigned int *crc)
112 +static struct symbol *
113 +sym_add_exported(const char *name, struct module *mod)
115 struct symbol *s = find_symbol(name);
118 - new_symbol(name, module, crc);
124 + s = new_symbol(name, mod);
126 + s->vmlinux = is_vmlinux(mod->name);
132 +sym_update_crc(const char *name, struct module *mod, unsigned int crc)
134 + struct symbol *s = find_symbol(name);
137 + s = new_symbol(name, mod);
143 @@ -339,8 +364,7 @@ handle_modversions(struct module *mod, s
145 if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
146 crc = (unsigned int) sym->st_value;
147 - add_exported_symbol(symname + strlen(CRC_PFX),
149 + sym_update_crc(symname + strlen(CRC_PFX), mod, crc);
153 @@ -372,26 +396,12 @@ handle_modversions(struct module *mod, s
155 /* All exported symbols */
156 if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) {
157 - add_exported_symbol(symname + strlen(KSYMTAB_PFX),
159 + sym_add_exported(symname + strlen(KSYMTAB_PFX), mod);
166 -is_vmlinux(const char *modname)
168 - const char *myname;
170 - if ((myname = strrchr(modname, '/')))
175 - return strcmp(myname, "vmlinux") == 0;
181 @@ -451,12 +461,7 @@ read_symbols(char *modname)
182 /* When there's no vmlinux, don't print warnings about
183 * unresolved symbols (since there'll be too many ;) */
184 if (is_vmlinux(modname)) {
185 - unsigned int fake_crc = 0;
187 - /* May not have this if !CONFIG_MODULE_UNLOAD: fake it.
188 - If it appears, we'll get the real CRC. */
189 - add_exported_symbol("cleanup_module", mod, &fake_crc);
190 - add_exported_symbol("struct_module", mod, &fake_crc);
194 @@ -499,12 +504,7 @@ buf_printf(struct buffer *buf, const cha
197 len = vsnprintf(tmp, SZ, fmt, ap);
198 - if (buf->size - buf->pos < len + 1) {
200 - buf->p = realloc(buf->p, buf->size);
202 - strncpy(buf->p + buf->pos, tmp, len + 1);
204 + buf_write(buf, tmp, len);
208 @@ -512,7 +512,7 @@ void
209 buf_write(struct buffer *buf, const char *s, int len)
211 if (buf->size - buf->pos < len) {
213 + buf->size += len + SZ;
214 buf->p = realloc(buf->p, buf->size);
216 strncpy(buf->p + buf->pos, s, len);
217 @@ -522,7 +522,7 @@ buf_write(struct buffer *buf, const char
218 /* Header for the generated file */
221 -add_header(struct buffer *b)
222 +add_header(struct buffer *b, struct module *mod)
224 buf_printf(b, "#include <linux/module.h>\n");
225 buf_printf(b, "#include <linux/vermagic.h>\n");
226 @@ -676,8 +676,11 @@ read_supported(const char *fname)
230 +/* parse Module.symvers file. line format:
231 + * 0x12345678<tab>symbol<tab>module[<tab>something]
234 -read_dump(const char *fname)
235 +read_dump(const char *fname, unsigned int kernel)
237 unsigned long size, pos = 0;
238 void *file = grab_file(fname, &size);
239 @@ -691,6 +694,7 @@ read_dump(const char *fname)
240 char *symname, *modname, *d;
245 if (!(symname = strchr(line, '\t')))
247 @@ -712,13 +716,29 @@ read_dump(const char *fname)
248 mod = new_module(NOFAIL(strdup(modname)));
251 - add_exported_symbol(symname, mod, &crc);
252 + s = sym_add_exported(symname, mod);
253 + s->kernel = kernel;
254 + sym_update_crc(symname, mod, crc);
258 fatal("parse error in symbol dump file\n");
261 +/* For normal builds always dump all symbols.
262 + * For external modules only dump symbols
263 + * that are not read from kernel Module.symvers.
266 +dump_sym(struct symbol *sym)
268 + if (!external_module)
270 + if (sym->vmlinux || sym->kernel)
276 write_dump(const char *fname)
278 @@ -729,15 +749,10 @@ write_dump(const char *fname)
279 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
280 symbol = symbolhash[n];
282 - symbol = symbol->next;
286 - for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
287 - symbol = symbolhash[n];
289 - buf_printf(&buf, "0x%08x\t%s\t%s\n", symbol->crc,
290 - symbol->name, symbol->module->name);
291 + if (dump_sym(symbol))
292 + buf_printf(&buf, "0x%08x\t%s\t%s\n",
293 + symbol->crc, symbol->name,
294 + symbol->module->name);
295 symbol = symbol->next;
298 @@ -750,14 +765,19 @@ main(int argc, char **argv)
300 struct buffer buf = { };
302 - char *dump_read = NULL, *dump_write = NULL;
303 + char *kernel_read = NULL, *module_read = NULL;
304 + char *dump_write = NULL;
308 - while ((opt = getopt(argc, argv, "i:o:s:")) != -1) {
309 + while ((opt = getopt(argc, argv, "i:I:o:s:")) != -1) {
312 - dump_read = optarg;
313 + kernel_read = optarg;
316 + module_read = optarg;
317 + external_module = 1;
321 @@ -773,8 +793,10 @@ main(int argc, char **argv)
323 read_supported(supp);
326 - read_dump(dump_read);
328 + read_dump(kernel_read, 1);
330 + read_dump(module_read, 0);
332 while (optind < argc) {
333 read_symbols(argv[optind++]);
334 @@ -786,7 +808,7 @@ main(int argc, char **argv)
339 + add_header(&buf, mod);
340 add_supported_flag(&buf, mod);
341 add_versions(&buf, mod);
342 add_depends(&buf, mod, modules);