Message ID | 20220424190811.1678416-11-masahiroy@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kbuild: yet another series of cleanups (modpost and LTO) | expand |
On Sun, Apr 24, 2022 at 12:09 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > Currently, modpost manages unresolved in a singly liked list; it adds s/liked/linked/ > 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: Masahiro Yamada <masahiroy@kernel.org> > --- > > scripts/mod/modpost.c | 20 ++++++++++++++------ > scripts/mod/modpost.h | 2 +- > 2 files changed, 15 insertions(+), 7 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index 1c7d2831e89d..e1eb188d6282 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -185,6 +185,8 @@ static struct module *new_module(const char *modname) > mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); > memset(mod, 0, sizeof(*mod)); > > + INIT_LIST_HEAD(&mod->unresolved_symbols); > + > strcpy(mod->name, modname); > mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); > mod->gpl_compatible = true; > @@ -201,6 +203,7 @@ static struct module *new_module(const char *modname) > > struct symbol { > struct symbol *next; > + struct list_head list; Isn't `list` meant to replace `next`? > struct module *module; > unsigned int crc; > bool crc_valid; > @@ -255,8 +258,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) > { > - mod->unres = alloc_symbol(name, mod->unres); > - mod->unres->weak = weak; > + struct symbol *sym; > + > + sym = alloc_symbol(name, NULL); > + sym->weak = weak; > + > + list_add_tail(&sym->list, &mod->unresolved_symbols); Because I was curious here why NULL was passed, rather than remove the assignment to struct symbol's next member in alloc_symbol. I get why you replace the `unres` member of struct module. I guess I'm curious then why yet another list is added to struct symbol, rather than replace the next member. Also, does adding a struct list_head member really not specify the _type_ of the next element? I guess when I look at the definition of struct module, at the member unresolved symbols, I don't know whether it's a list of struct module* or a list of struct symbol*. <snip> > diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h > index c3b5d2f0e2bb..6a90bfc08458 100644 > --- a/scripts/mod/modpost.h > +++ b/scripts/mod/modpost.h > @@ -117,7 +117,7 @@ struct namespace_list { > struct module { > struct list_head list; > int gpl_compatible; > - struct symbol *unres; > + struct list_head unresolved_symbols; > bool from_dump; /* true if module was loaded from *.symvers */ > bool is_vmlinux; > bool seen; > -- > 2.32.0 >
On Wed, Apr 27, 2022 at 2:08 AM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Sun, Apr 24, 2022 at 12:09 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > Currently, modpost manages unresolved in a singly liked list; it adds > > s/liked/linked/ > > > 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: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > scripts/mod/modpost.c | 20 ++++++++++++++------ > > scripts/mod/modpost.h | 2 +- > > 2 files changed, 15 insertions(+), 7 deletions(-) > > > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > > index 1c7d2831e89d..e1eb188d6282 100644 > > --- a/scripts/mod/modpost.c > > +++ b/scripts/mod/modpost.c > > @@ -185,6 +185,8 @@ static struct module *new_module(const char *modname) > > mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); > > memset(mod, 0, sizeof(*mod)); > > > > + INIT_LIST_HEAD(&mod->unresolved_symbols); > > + > > strcpy(mod->name, modname); > > mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); > > mod->gpl_compatible = true; > > @@ -201,6 +203,7 @@ static struct module *new_module(const char *modname) > > > > struct symbol { > > struct symbol *next; > > + struct list_head list; > > Isn't `list` meant to replace `next`? No. 'next' is still used for the hash table. modpost used it in various ways. You need to read the code closely if you are interested in how modpost works. > > > struct module *module; > > unsigned int crc; > > bool crc_valid; > > @@ -255,8 +258,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) > > { > > - mod->unres = alloc_symbol(name, mod->unres); > > - mod->unres->weak = weak; > > + struct symbol *sym; > > + > > + sym = alloc_symbol(name, NULL); > > + sym->weak = weak; > > + > > + list_add_tail(&sym->list, &mod->unresolved_symbols); > > Because I was curious here why NULL was passed, rather than remove the > assignment to struct symbol's next member in alloc_symbol. > I get why you replace the `unres` member of struct module. I guess I'm > curious then why yet another list is added to struct symbol, rather > than replace the next member. 'next' is used for ad-hoc hash table implementation. I will be cleaned up by a later commit. See this patch: https://patchwork.kernel.org/project/linux-kbuild/patch/20220424190811.1678416-20-masahiroy@kernel.org/ > > Also, does adding a struct list_head member really not specify the > _type_ of the next element? I guess when I look at the definition of > struct module, at the member unresolved symbols, I don't know whether > it's a list of struct module* or a list of struct symbol*. This is how include/linux/list.h works. struct list_head is really generic, does not specify a specific type definition. > > <snip> > > > diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h > > index c3b5d2f0e2bb..6a90bfc08458 100644 > > --- a/scripts/mod/modpost.h > > +++ b/scripts/mod/modpost.h > > @@ -117,7 +117,7 @@ struct namespace_list { > > struct module { > > struct list_head list; > > int gpl_compatible; > > - struct symbol *unres; > > + struct list_head unresolved_symbols; > > bool from_dump; /* true if module was loaded from *.symvers */ > > bool is_vmlinux; > > bool seen; > > -- > > 2.32.0 > > > > > -- > Thanks, > ~Nick Desaulniers
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 1c7d2831e89d..e1eb188d6282 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -185,6 +185,8 @@ static struct module *new_module(const char *modname) mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); memset(mod, 0, sizeof(*mod)); + INIT_LIST_HEAD(&mod->unresolved_symbols); + strcpy(mod->name, modname); mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); mod->gpl_compatible = true; @@ -201,6 +203,7 @@ static struct module *new_module(const char *modname) struct symbol { struct symbol *next; + struct list_head list; struct module *module; unsigned int crc; bool crc_valid; @@ -255,8 +258,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) { - mod->unres = alloc_symbol(name, mod->unres); - mod->unres->weak = weak; + struct symbol *sym; + + sym = alloc_symbol(name, NULL); + sym->weak = weak; + + list_add_tail(&sym->list, &mod->unresolved_symbols); } static struct symbol *find_symbol(const char *name) @@ -2147,7 +2154,7 @@ static void check_exports(struct module *mod) { struct symbol *s, *exp; - for (s = mod->unres; s; s = s->next) { + list_for_each_entry(s, &mod->unresolved_symbols, list) { const char *basename; exp = find_symbol(s->name); if (!exp) { @@ -2268,7 +2275,7 @@ static void add_versions(struct buffer *b, struct module *mod) buf_printf(b, "static const struct modversion_info ____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) continue; if (!s->crc_valid) { @@ -2294,13 +2301,14 @@ static void add_depends(struct buffer *b, struct module *mod) int first = 1; /* 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) s->module->seen = s->module->is_vmlinux; + } buf_printf(b, "\n"); 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; if (!s->module) continue; diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index c3b5d2f0e2bb..6a90bfc08458 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -117,7 +117,7 @@ struct namespace_list { struct module { struct list_head list; int gpl_compatible; - struct symbol *unres; + struct list_head unresolved_symbols; bool from_dump; /* true if module was loaded from *.symvers */ bool is_vmlinux; bool seen;
Currently, modpost manages unresolved in a singly liked 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: Masahiro Yamada <masahiroy@kernel.org> --- scripts/mod/modpost.c | 20 ++++++++++++++------ scripts/mod/modpost.h | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-)