]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kbuild: generate Module.symvers only when vmlinux exists
authorMasahiro Yamada <masahiroy@kernel.org>
Thu, 25 Mar 2021 18:54:09 +0000 (03:54 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 May 2021 08:56:20 +0000 (10:56 +0200)
[ Upstream commit 69bc8d386aebbd91a6bb44b6d33f77c8dfa9ed8c ]

The external module build shows the following warning if Module.symvers
is missing in the kernel tree.

  WARNING: Symbol version dump "Module.symvers" is missing.
           Modules may not have dependencies or modversions.

I think this is an important heads-up because the resulting modules may
not work as expected. This happens when you did not build the entire
kernel tree, for example, you might have prepared the minimal setups
for external modules by 'make defconfig && make modules_preapre'.

A problem is that 'make modules' creates Module.symvers even without
vmlinux. In this case, that warning is suppressed since Module.symvers
already exists in spite of its incomplete content.

The incomplete (i.e. invalid) Module.symvers should not be created.

This commit changes the second pass of modpost to dump symbols into
modules-only.symvers. The final Module.symvers is created by
concatenating vmlinux.symvers and modules-only.symvers if both exist.

Module.symvers is supposed to collect symbols from both vmlinux and
modules. It might be a bit confusing, and I am not quite sure if it
is an official interface, but presumably it is difficult to rename it
because some tools (e.g. kmod) parse it.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
.gitignore
Documentation/dontdiff
Makefile
scripts/Makefile.modpost
scripts/mod/modpost.c

index 3af66272d6f10c5eccc0e00f3a6ff59a0d3990f1..127012c1f7170d20283c1274b46eeec3d666e5ba 100644 (file)
@@ -57,6 +57,7 @@ modules.order
 /tags
 /TAGS
 /linux
+/modules-only.symvers
 /vmlinux
 /vmlinux.32
 /vmlinux.symvers
index e361fc95ca293d80434ee0cdfae309046c17d612..82e3eee7363b0301a6aaccea965d077130c09f4d 100644 (file)
@@ -178,6 +178,7 @@ mktables
 mktree
 mkutf8data
 modpost
+modules-only.symvers
 modules.builtin
 modules.builtin.modinfo
 modules.nsdeps
index 0b1852621615cd0b334352c1162aae989f29cf6a..7503ffef64241c69c12cd0775c6695b5edfac2e1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1513,7 +1513,7 @@ endif # CONFIG_MODULES
 # make distclean Remove editor backup files, patch leftover files and the like
 
 # Directories & files removed with 'make clean'
-CLEAN_FILES += include/ksym vmlinux.symvers \
+CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
               modules.builtin modules.builtin.modinfo modules.nsdeps \
               compile_commands.json .thinlto-cache
 
index 066beffca09af0d753ba8ba976ec047a68f9dd85..4ca5579af4e4a4e67f0c4966c2d960663fd9049f 100644 (file)
@@ -68,7 +68,20 @@ else
 ifeq ($(KBUILD_EXTMOD),)
 
 input-symdump := vmlinux.symvers
-output-symdump := Module.symvers
+output-symdump := modules-only.symvers
+
+quiet_cmd_cat = GEN     $@
+      cmd_cat = cat $(real-prereqs) > $@
+
+ifneq ($(wildcard vmlinux.symvers),)
+
+__modpost: Module.symvers
+Module.symvers: vmlinux.symvers modules-only.symvers FORCE
+       $(call if_changed,cat)
+
+targets += Module.symvers
+
+endif
 
 else
 
index 24725e50c7b4b181f2b5bce1c9e9fd4ca18774f1..10c3fba26f03a34a34cf140d90f8f7f0623a1eb3 100644 (file)
@@ -2423,19 +2423,6 @@ fail:
        fatal("parse error in symbol dump file\n");
 }
 
-/* For normal builds always dump all symbols.
- * For external modules only dump symbols
- * that are not read from kernel Module.symvers.
- **/
-static int dump_sym(struct symbol *sym)
-{
-       if (!external_module)
-               return 1;
-       if (sym->module->from_dump)
-               return 0;
-       return 1;
-}
-
 static void write_dump(const char *fname)
 {
        struct buffer buf = { };
@@ -2446,7 +2433,7 @@ static void write_dump(const char *fname)
        for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
                symbol = symbolhash[n];
                while (symbol) {
-                       if (dump_sym(symbol)) {
+                       if (!symbol->module->from_dump) {
                                namespace = symbol->namespace;
                                buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
                                           symbol->crc, symbol->name,