Hello everyone,
I am new to this forum. Recently I am learning how to link static libraries to kernel module.
I have found simliar posts in :
http://www.linuxquestions.org/questi...module-587406/
I have a test.c file with the following contents :
int TEST ( int p1 , int p2 )
{
return p1 + p2 ;
}
I compiled it with :
gcc -o test.o -c test.c
I made the static library with :
ar -rcs test.a test.o
I tried to use the TEST function in a kernel module, however, I found out that the passed in values of the parameters are totally wrong, and made the function give wrong result. Does any one know if there is special ways or flags should be added when making the static library for kernel module? Thank you in advanced for your advise !
John Sung
The kernel module file looks like below :
//=================================================================
// module.c
//=================================================================
#include <linux/module.h>
int TEST ( int , int ) ;
static int __init Module_Init ( void )
{
printk ( "TEST result %d\n" , TEST( 1 , 2 ) ) ;
return 0 ;
}
static void __exit Module_Exit ( void )
{
return ;
}
module_init ( Module_Init ) ;
module_exit ( Module_Exit ) ;
MODULE_AUTHOR ( "test <test@test.com>" ) ;
MODULE_DESCRIPTION ( "This is a Test Module" ) ;
MODULE_LICENSE ( "GPL" ) ;
//=================================================================
// Makefile
//=================================================================
ifndef KERNELDIR
KERNELDIR := /lib/modules/$(shell uname -r)/build
endif
obj-m := TestMod.o
TestMod-objs := module.o test.a
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
/sbin/depmod -ae