Monday, April 30, 2007

Calling one kernel module function in another

Say I have a LKM foo1.ko which has "my_foo1()" as the exported function. Now, another LKM foo2.ko calls this "my_foo1()". When this second LKM is compiled, it is generating a warning that "my_foo1() undefined!". Though this is just a warning, this can be avoided. How? I found it out via a forum. There are FOUR ways to remove the warning.

ONE: "insmod" foo1 before comiling foo2.

TWO: Compile both the LKMs in the same Makefile, in one shot; like below



$ cat Makefile
obj-m = foo1/foo1.o foo2/foo2.o

here:
make -C /lib/modules/`uname -r`/build M=`pwd` modules


THREE: Starting 2.6.17, you can copy the Module.symvers generated by the compilation of foo1 to the foo2 source directory and compile foo2.

FOUR: Be a proper programmer and ignore it. It works anyway ! Why Worry :-)

Common symbol error in Mac

Multiple C files. Few global variables. A single dynamic library. Thats what I was trying to do in Mac. But, the compiler went jittery and complained
ld: common symbols not allowed with MH_DYLIB output format
. Googling taught me that I need to either initialize the global variable(s) or add "-fno-common" switch to the compiler flags. That solved the issue and I am happy "trying" to link it. Oh Yeah. Am facing another issue. Will update as soon as I find the solution. Cheerio.

Thursday, April 05, 2007

loading shared libraries with gdb

While trying to validate a particular utility which uses a shared library (which again was developed by me and resides in user-specified path), gdb reported error that it was not able to find the shared library (although compiling the utility was not a problem). ldd also was not able to find the library, although i had used ldconfig -n /path/to/lib/dir and properly created the soname.

After some googling, I found that gdb was trying to use the ld.so.conf directory and its contents to search for the shared library objects. So, I added my path to /etc/ld.so.conf/ directory. After this, the shared object loaded without any complaint.

mmMmm...