I am coding outside the kernel source tree. There are two modules, the first one printt have a function printtty()
to print string to the current tty, and the second module hello which invokes printtty()
during initialization.
I have added EXPORT_SYMBOL(printtty)
in module printt, and after insmod ./printt.ko
, the information of printtty()
can be seen in /proc/kallsyms
.
The make
process of module hello goes all right. But insmod ./hello.ko
will cause an error like:
insmod: ERROR: could not insert module hello.ko: Invalid parameters
and dmesg
shows
hello: no symbol version for printtty
hello: Unknown symbol printtty (err -22)`.
I've fixed this by
(1) Copy the hello.ko
file to a location beneath /lib/modules/version/kernel
(2) Add the exported symbols from hello.ko
to /lib/modules/version/build/Module.symvers
But I wonder is there any way to export a symbol just from an external module(without modifying kernel source tree)?
Add this line at the very top of your Makefile for your hello module:
KBUILD_EXTRA_SYMBOLS := /home/your-user/path/to/printt/Module.symvers
(be sure to put in the correct path to your printt module).
Now rebuild your hello module and it will be loaded just fine.
For details see Documentation/kbuild/modules.txt, "6.3 Symbols From Another External Module".