How to export a character from an external module?

I am coded outside of the source kernel tree. There are two modules, the first printt has a printtty() function for printing a string in the current tty, and the second is a hello module that calls printtty() during initialization.

I added EXPORT_SYMBOL(printtty) to the printt module, and after insmod ./printt.ko printtty() can be seen in /proc/kallsyms .

The make module hello process is appropriate. But insmod ./hello.ko will insmod ./hello.ko error, for example:

 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 fixed it with

(1) Copy the .ko file to the location under / lib / modules / version / kernel

(2) Add exported characters to /lib/modules/version/build/Module.symvers

But I wonder if there is a way to export a symbol only from an external module (without changing the original kernel tree)?

+6
source share
1 answer

Add this line to the very top of your Makefile for your hi module:

 KBUILD_EXTRA_SYMBOLS := /home/your-user/path/to/printt/Module.symvers 

(do not forget to specify the correct path to your printt module).

Now rebuild your hi module and it will load just fine.

See Documentation / kbuild / modules.txt , "6.3 Symbols from Another External Module" for details.

+6
source

Source: https://habr.com/ru/post/985056/


All Articles