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
:
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>
For example:
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.
If 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.
If a 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.
if 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
and bar.ko
, where 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/
And executing
$ 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
modprobe --force
? – Alexander Oct 15 '18 at 08:49modprobe
on the system doesn't have--force
(they stripped it in every way they could), I'll look into syscalls kmod uses and try to write my own simple program. In the meantime, here's the configuration if you'd like to take a look: http://www.olio.watch/3.10.0-g2ae2f33-config – Billy Oct 16 '18 at 00:33undefined symbols
? – Louis Go Oct 26 '20 at 07:46