Commit 8a69152b authored by Masahiro Yamada's avatar Masahiro Yamada

modpost: traverse unresolved symbols in order

Currently, modpost manages unresolved in a singly linked list; it adds
a new node to the head, and traverses the list from new to old.

Use a doubly linked list to keep the order in the symbol table in the
ELF file.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent e882e89b
...@@ -185,6 +185,8 @@ static struct module *new_module(const char *modname) ...@@ -185,6 +185,8 @@ 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->unresolved_symbols);
strcpy(mod->name, modname); strcpy(mod->name, modname);
mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
...@@ -207,6 +209,7 @@ static struct module *new_module(const char *modname) ...@@ -207,6 +209,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 module *module; struct module *module;
char *namespace; char *namespace;
unsigned int crc; unsigned int crc;
...@@ -261,8 +264,12 @@ static struct symbol *new_symbol(const char *name, struct module *module, ...@@ -261,8 +264,12 @@ static struct symbol *new_symbol(const char *name, struct module *module,
static void sym_add_unresolved(const char *name, struct module *mod, bool weak) static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
{ {
mod->unres = alloc_symbol(name, mod->unres); struct symbol *sym;
mod->unres->weak = weak;
sym = alloc_symbol(name, NULL);
sym->weak = weak;
list_add_tail(&sym->list, &mod->unresolved_symbols);
} }
static struct symbol *find_symbol(const char *name) static struct symbol *find_symbol(const char *name)
...@@ -2156,7 +2163,7 @@ static void check_exports(struct module *mod) ...@@ -2156,7 +2163,7 @@ static void check_exports(struct module *mod)
{ {
struct symbol *s, *exp; struct symbol *s, *exp;
for (s = mod->unres; s; s = s->next) { list_for_each_entry(s, &mod->unresolved_symbols, list) {
const char *basename; const char *basename;
exp = find_symbol(s->name); exp = find_symbol(s->name);
if (!exp) { if (!exp) {
...@@ -2277,7 +2284,7 @@ static void add_versions(struct buffer *b, struct module *mod) ...@@ -2277,7 +2284,7 @@ static void add_versions(struct buffer *b, struct module *mod)
buf_printf(b, "static const struct modversion_info ____versions[]\n"); buf_printf(b, "static const struct modversion_info ____versions[]\n");
buf_printf(b, "__used __section(\"__versions\") = {\n"); buf_printf(b, "__used __section(\"__versions\") = {\n");
for (s = mod->unres; s; s = s->next) { list_for_each_entry(s, &mod->unresolved_symbols, list) {
if (!s->module) if (!s->module)
continue; continue;
if (!s->crc_valid) { if (!s->crc_valid) {
...@@ -2303,13 +2310,14 @@ static void add_depends(struct buffer *b, struct module *mod) ...@@ -2303,13 +2310,14 @@ static void add_depends(struct buffer *b, struct module *mod)
int first = 1; int first = 1;
/* Clear ->seen flag of modules that own symbols needed by this. */ /* Clear ->seen flag of modules that own symbols needed by this. */
for (s = mod->unres; s; s = s->next) list_for_each_entry(s, &mod->unresolved_symbols, list) {
if (s->module) if (s->module)
s->module->seen = s->module->is_vmlinux; s->module->seen = s->module->is_vmlinux;
}
buf_printf(b, "\n"); buf_printf(b, "\n");
buf_printf(b, "MODULE_INFO(depends, \""); buf_printf(b, "MODULE_INFO(depends, \"");
for (s = mod->unres; s; s = s->next) { list_for_each_entry(s, &mod->unresolved_symbols, list) {
const char *p; const char *p;
if (!s->module) if (!s->module)
continue; continue;
......
...@@ -113,8 +113,8 @@ buf_write(struct buffer *buf, const char *s, int len); ...@@ -113,8 +113,8 @@ 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 unresolved_symbols;
bool is_gpl_compatible; bool is_gpl_compatible;
struct symbol *unres;
bool from_dump; /* true if module was loaded from *.symvers */ bool from_dump; /* true if module was loaded from *.symvers */
bool is_vmlinux; bool is_vmlinux;
bool seen; bool seen;
......
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