First, in order to answer your question "can I compile Linux kernel module without Module.symvers", we need to understand what is the purpose of
Module.symvers serves two main purposes:
1) It lists all exported symbols from vmlinux and all modules.
2) It lists the CRC if
CONFIG_MODVERSIONS is enabled. Without
CONFIG_MODVERSIONS enabled, the CRC would read 0x00000000.
Module.symvers will be generated during a kernel build, it contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored. The syntax of the Module.symvers file is:
<CRC> <Symbol> <module>
0x2d036834 scsi_remove_host drivers/scsi/scsi_mod
Having said that, if we have
Module.symvers then we can build any module because it contain all the necessary symbols.
Module.symvers is not available, we still able to build an external module either by building this file or by borrowing it from another module.
Usually, when building an external module, the build system needs access to the symbols from the kernel to check if all external symbols are defined. This is done in a build step called
MODPOST. This step obtains the symbols by reading
Module.symvers from the kernel source tree.
Module.symvers file is present in the directory where the external module is being built, this file will be read too. During the
MODPOST step, a new
Module.symvers file will be written containing all exported symbols that were not defined in the kernel.
Module.symvers file is not present, then an external module might be using an exported symbols from another external module,
kbuild needs to have full knowledge of all symbols to avoid spitting out warnings about undefined symbols.
For this situation, there are three solutions:
1) Use a top-level
kbuild file: If you have two modules,
foo.ko needs symbols from
bar.ko, you can use a common top-level
kbuild file so both modules are compiled in the same build. Consider the following directory layout:
./foo/ <= contains foo.ko
./bar/ <= contains bar.ko
The top-level kbuild file would then look like:
#./Kbuild (or ./Makefile):
obj-y := foo/ bar/
$ make -C $KDIR M=$PWD
will then do the expected and compile both modules with
full knowledge of symbols from either module.
2) Use an extra
Module.symvers file: When an external module is built, a
Module.symvers file is generated containing all exported symbols which are not defined in the kernel. To get access to symbols from
bar.ko, copy the Module.symvers file from the compilation of bar.ko to the directory where foo.ko is built. During the module build,
kbuild will read the
Module.symvers file in the directory of the external module, and when the build is finished, a new
Module.symvers file is created containing the sum of all symbols defined and not part of the kernel.
3) Use "make" variable
KBUILD_EXTRA_SYMBOLS: If it is impractical to copy
Module.symvers from another module, you can assign a space separated list of files to
KBUILD_EXTRA_SYMBOLS in your build file. These files will be loaded by
modpost during the initialization of its symbol tables.
More details 1