Commit f841536e authored by Masahiro Yamada's avatar Masahiro Yamada

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: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent ab489d60
...@@ -185,6 +185,7 @@ static struct module *new_module(const char *modname) ...@@ -185,6 +185,7 @@ static struct module *new_module(const char *modname)
mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
memset(mod, 0, sizeof(*mod)); memset(mod, 0, sizeof(*mod));
INIT_LIST_HEAD(&mod->exported_symbols);
INIT_LIST_HEAD(&mod->unresolved_symbols); INIT_LIST_HEAD(&mod->unresolved_symbols);
INIT_LIST_HEAD(&mod->missing_namespaces); INIT_LIST_HEAD(&mod->missing_namespaces);
INIT_LIST_HEAD(&mod->imported_namespaces); INIT_LIST_HEAD(&mod->imported_namespaces);
...@@ -211,7 +212,7 @@ static struct module *new_module(const char *modname) ...@@ -211,7 +212,7 @@ static struct module *new_module(const char *modname)
struct symbol { struct symbol {
struct symbol *next; struct symbol *next;
struct list_head list; /* link to module::unresolved_symbols */ struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */
struct module *module; struct module *module;
char *namespace; char *namespace;
unsigned int crc; unsigned int crc;
...@@ -413,6 +414,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, ...@@ -413,6 +414,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
if (!s) { if (!s) {
s = new_symbol(name, mod, export); s = new_symbol(name, mod, export);
list_add_tail(&s->list, &mod->exported_symbols);
} else if (!external_module || s->module->is_vmlinux || } else if (!external_module || s->module->is_vmlinux ||
s->module == mod) { s->module == mod) {
warn("%s: '%s' exported twice. Previous export was in %s%s\n", warn("%s: '%s' exported twice. Previous export was in %s%s\n",
...@@ -2456,22 +2458,17 @@ static void read_dump(const char *fname) ...@@ -2456,22 +2458,17 @@ static void read_dump(const char *fname)
static void write_dump(const char *fname) static void write_dump(const char *fname)
{ {
struct buffer buf = { }; struct buffer buf = { };
struct symbol *symbol; struct module *mod;
const char *namespace; struct symbol *sym;
int n;
for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { list_for_each_entry(mod, &modules, list) {
symbol = symbolhash[n]; if (mod->from_dump)
while (symbol) { continue;
if (!symbol->module->from_dump) { list_for_each_entry(sym, &mod->exported_symbols, list) {
namespace = symbol->namespace; buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n", sym->crc, sym->name, mod->name,
symbol->crc, symbol->name, export_str(sym->export),
symbol->module->name, sym->namespace ?: "");
export_str(symbol->export),
namespace ? namespace : "");
}
symbol = symbol->next;
} }
} }
write_buf(&buf, fname); write_buf(&buf, fname);
......
...@@ -113,6 +113,7 @@ buf_write(struct buffer *buf, const char *s, int len); ...@@ -113,6 +113,7 @@ buf_write(struct buffer *buf, const char *s, int len);
struct module { struct module {
struct list_head list; struct list_head list;
struct list_head exported_symbols;
struct list_head unresolved_symbols; struct list_head unresolved_symbols;
bool is_gpl_compatible; bool is_gpl_compatible;
bool from_dump; /* true if module was loaded from *.symvers */ bool from_dump; /* true if module was loaded from *.symvers */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment