Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

modpost: dump Module.symvers in the same order of modules.order

modpost dumps the exported symbols into Module.symvers, but currently
in random order because it iterates in the hash table.

Add a linked list of exported symbols in struct module, so we can
iterate on symbols per module.

This commit makes Module.symvers much more readable; the outer loop in
write_dump() iterates over the modules in the order of modules.order,
and the inner loop dumps symbols in each module.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

+14 -16
+13 -16
scripts/mod/modpost.c
··· 185 185 mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); 186 186 memset(mod, 0, sizeof(*mod)); 187 187 188 + INIT_LIST_HEAD(&mod->exported_symbols); 188 189 INIT_LIST_HEAD(&mod->unresolved_symbols); 189 190 INIT_LIST_HEAD(&mod->missing_namespaces); 190 191 INIT_LIST_HEAD(&mod->imported_namespaces); ··· 212 211 213 212 struct symbol { 214 213 struct symbol *next; 215 - struct list_head list; /* link to module::unresolved_symbols */ 214 + struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */ 216 215 struct module *module; 217 216 char *namespace; 218 217 unsigned int crc; ··· 414 413 415 414 if (!s) { 416 415 s = new_symbol(name, mod, export); 416 + list_add_tail(&s->list, &mod->exported_symbols); 417 417 } else if (!external_module || s->module->is_vmlinux || 418 418 s->module == mod) { 419 419 warn("%s: '%s' exported twice. Previous export was in %s%s\n", ··· 2458 2456 static void write_dump(const char *fname) 2459 2457 { 2460 2458 struct buffer buf = { }; 2461 - struct symbol *symbol; 2462 - const char *namespace; 2463 - int n; 2459 + struct module *mod; 2460 + struct symbol *sym; 2464 2461 2465 - for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { 2466 - symbol = symbolhash[n]; 2467 - while (symbol) { 2468 - if (!symbol->module->from_dump) { 2469 - namespace = symbol->namespace; 2470 - buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n", 2471 - symbol->crc, symbol->name, 2472 - symbol->module->name, 2473 - export_str(symbol->export), 2474 - namespace ? namespace : ""); 2475 - } 2476 - symbol = symbol->next; 2462 + list_for_each_entry(mod, &modules, list) { 2463 + if (mod->from_dump) 2464 + continue; 2465 + list_for_each_entry(sym, &mod->exported_symbols, list) { 2466 + buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n", 2467 + sym->crc, sym->name, mod->name, 2468 + export_str(sym->export), 2469 + sym->namespace ?: ""); 2477 2470 } 2478 2471 } 2479 2472 write_buf(&buf, fname);
+1
scripts/mod/modpost.h
··· 113 113 114 114 struct module { 115 115 struct list_head list; 116 + struct list_head exported_symbols; 116 117 struct list_head unresolved_symbols; 117 118 bool is_gpl_compatible; 118 119 bool from_dump; /* true if module was loaded from *.symvers */