diff mbox series

[v2,12/26] modpost: make sym_add_exported() always allocate a new symbol

Message ID 20220501084032.1025918-13-masahiroy@kernel.org (mailing list archive)
State New
Headers show
Series kbuild: yet another series of cleanups (modpost and LTO) | expand

Commit Message

Masahiro Yamada May 1, 2022, 8:40 a.m. UTC
Currently, sym_add_exported() does not allocate a symbol if the same
name symbol already exists in the hash table.

This does not reflect the real use cases. You can let an external
module override the in-tree one. In this case, the external module
will export the same name symbols as the in-tree one. However,
modpost simply ignores those symbols, then Module.symvers for the
external module loses its symbols.

sym_add_exported() should allocate a new symbol.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

(no changes since v1)

 scripts/mod/modpost.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Nick Desaulniers May 3, 2022, 9:56 p.m. UTC | #1
On Sun, May 1, 2022 at 1:42 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Currently, sym_add_exported() does not allocate a symbol if the same
> name symbol already exists in the hash table.
>
> This does not reflect the real use cases. You can let an external
> module override the in-tree one. In this case, the external module
> will export the same name symbols as the in-tree one. However,
> modpost simply ignores those symbols, then Module.symvers for the
> external module loses its symbols.
>
> sym_add_exported() should allocate a new symbol.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
> (no changes since v1)
>
>  scripts/mod/modpost.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 1f01fc942f94..c9b75697d0fc 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -412,19 +412,17 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
>  {
>         struct symbol *s = find_symbol(name);
>
> -       if (!s) {
> -               s = new_symbol(name, mod, export);
> -               list_add_tail(&s->list, &mod->exported_symbols);
> -       } else if (!external_module || s->module->is_vmlinux ||
> -                  s->module == mod) {
> +       if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) {
>                 error("%s: '%s' exported twice. Previous export was in %s%s\n",
>                       mod->name, name, s->module->name,
>                       s->module->is_vmlinux ? "" : ".ko");
> -               return s;
>         }
>
> +       s = new_symbol(name, mod, export);
>         s->module = mod;
>         s->export    = export;
> +       list_add_tail(&s->list, &mod->exported_symbols);
> +
>         return s;
>  }
>
> --
> 2.32.0
>
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 1f01fc942f94..c9b75697d0fc 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -412,19 +412,17 @@  static struct symbol *sym_add_exported(const char *name, struct module *mod,
 {
 	struct symbol *s = find_symbol(name);
 
-	if (!s) {
-		s = new_symbol(name, mod, export);
-		list_add_tail(&s->list, &mod->exported_symbols);
-	} else if (!external_module || s->module->is_vmlinux ||
-		   s->module == mod) {
+	if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) {
 		error("%s: '%s' exported twice. Previous export was in %s%s\n",
 		      mod->name, name, s->module->name,
 		      s->module->is_vmlinux ? "" : ".ko");
-		return s;
 	}
 
+	s = new_symbol(name, mod, export);
 	s->module = mod;
 	s->export    = export;
+	list_add_tail(&s->list, &mod->exported_symbols);
+
 	return s;
 }