modpost: add a separate error for exported symbols without definition
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 24 Apr 2022 19:07:48 +0000 (04:07 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 7 May 2022 18:16:59 +0000 (03:16 +0900)
It took me a while to understand the intent of "exp->module == mod".

This code goes back to 2003. [1]

The commit is not in this git repository, and might be worth a little
explanation.

You can add EXPORT_SYMBOL() without having its definition in the same
file (but you need to put a declaration).

This is typical when EXPORT_SYMBOL() is added in a C file, but the
actual implementation is in a separate assembly file.

One example is arch/arm/kernel/armksyms.c

In the old days, EXPORT_SYMBOL() was only available in C files (but
this limitation does not exist any more). If you forget to add the
definition, this error occurs.

Add a separate, clearer message for this case. It should be an error
even if KBUILD_MODPOST_WARN is given.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=2763b6bcb96e6a38a2fe31108fe5759ec5bcc80a

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

index c7cfeeb..969a081 100644 (file)
@@ -2147,13 +2147,18 @@ static void check_exports(struct module *mod)
        for (s = mod->unres; s; s = s->next) {
                const char *basename;
                exp = find_symbol(s->name);
-               if (!exp || exp->module == mod) {
+               if (!exp) {
                        if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
                                modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
                                            "\"%s\" [%s.ko] undefined!\n",
                                            s->name, mod->name);
                        continue;
                }
+               if (exp->module == mod) {
+                       error("\"%s\" [%s.ko] was exported without definition\n",
+                             s->name, mod->name);
+                       continue;
+               }
                basename = strrchr(mod->name, '/');
                if (basename)
                        basename++;