On Sun, 9 Sep 2001, Shobhit Mathur wrote:
> Hello,
>
> This might be a frequently asked Question. But, I am afraid, I
> have to repeat
> the question.....
> I wrote a fundamental "hello world" module on my newly
> installed 7.1
> Linux PC . The code compiles successfully with a "gcc -c
> <file-name>".
> Upon attempting an "insmod <file.o>", I get the following error
> :
> "unresolved symbol printk"
>
> Upon perusing through other mailing-lists, I found that this
> problem has been
> around for quite a while. Currently, I have a kernel with the
> flag
> CONFIG_MODVERSIONS being disabled. But, it does not make any
> difference. I get the same error before and after the
> recompilation with the
> changed flag. insmod continues to fail !
>
Here is my module:
#define MODULE
#include <linux/module.h>
int init_module (void)
{
printk ("<1>Hello world\n");
return (0);
}
void cleanup_module (void)
{
printk ("<1>Good Bye\n");
}
This is the printk symbol name in the kernel:
$ fgrep ' printk' /proc/ksyms
c0115fb0 printk_R1b7d4074
$
When I compile the module with gcc -c hello.c, nm gives me the following
screendump:
$ nm hello.o
00000000 ? __module_kernel_version <----------
00000020 T cleanup_module
00000000 t gcc2_compiled.
00000000 T init_module
U printk
$
Here you can see that the module will be checked against the kernel
version - insmod works fine on my system.
Now I set the MODVERSIONS flag so that insmod also compares the versions
of the symbols in the modules against the version of the symbols in the
kernel:
gcc -c -DMODVERSIONS hello.c
Now when I run insmod, it cannot resolve the printk symbol because printk
in the module has not been mangled (no checksum included):
# insmod hello.o
hello.o: unresolved symbol printk
#
# nm hello.o
00000000 ? __module_kernel_version
00000018 ? __module_using_checksums <----------
00000020 T cleanup_module
00000000 t gcc2_compiled.
00000000 T init_module
U printk <----------
#
To mangle the names of each symbol in the module, add the following line
to your module:
#include <linux/modversions.h>
Compile your module again (specify the directory for modversions.h):
gcc -c -DMODVERSIONS -I/usr/src/linux/include hello.c
The printk symbol in my module has now been mangled and insmod works fine:
$ nm hello.o
00000000 ? __module_kernel_version
00000018 ? __module_using_checksums
00000020 T cleanup_module
00000000 t gcc2_compiled.
00000000 T init_module
U printk_R1b7d4074 <----------
$
Hope this helps
Werner
_______________________________________________
Seawolf-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/seawolf-list