Calling Kernel Module's Function from The Other Kernel Module
###### Contents

I made two kernel modules, one of which calls a function of the other module, but it kept saying me that WARNING: "<function_name>" undefined!. Even though I exported the function, there actually is another step that I should follow.

References: http://stackoverflow.com/a/9499893

What I did before finding the reference was to export the target function.

1
2
3
/kernel1/functions.h

void function1(void);

1
2
3
4
5
/kernel1/functions.c

#include <linux/module.h>
void function1(void){};
EXPORT_SYMBOL(function1);


However, the other kernel module (say it kernel2) does not know where function1() exists. Hence, to use this function from kernel2, we need to import Module.symvers of kernel1 into Kbuild.in of kernel module kernel2.

As in the reference post, we just define KBUILD_EXTRA_SYMBOLS in Kbuild.in. We don’t have to any more things.

1
2
3
4
5
6
7
/kernel2/Kbuild.in

...
KBUILD_EXTRA_SYMBOLS = /kernel1/Module.symvers

EXTRA_CFLAGS = -I/kernel1/functions.h
...

• Note that EXTRA_CFLAGS seems deprecated and ccflags-y should be used instead.

Now compiling kernel2 will show no warnings.