[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Symbol Versioning [Was Re: Unresolved Symbol in Module]
On Thu, 8 Mar 2001, Narayana, Venkat A. wrote:
> Hi,
> I am learning to write kernel modules, and while experimenting
> with a simple module, i got
> " hello.o: unresolved symbol printk_Rsmp_1b7d4074" error
> while loading this module via insmod hello.o command.
>
> I noticed that /proc/ksyms contains printk symbol.
>
> What is that i am doing which is not correct?
> Help me out.
As other people have pointed out this has to do with versioning.
The simple answer to the question is that you need to include modversions.h
before the header file for printk if you want the module to load into a kernel
with CONFIG_MODVERSIONS turned on.
You could do this in two ways
o in each of your c files, at the top (before you include linux/kernel.h)
#idef CONFIG_MODVERSIONS
#include <linux/modversions.h>
#endif
o or in you makefile you could have
ifdef CONFIG_MODVERSIONS
CPPFLAGS += -include /usr/src/linux/modversions.h
endif
------------
Now, I'll try and explain how it all works. (Jay, a section on this is definetly
need in the module programming guide ;).
Okay, this can be a bit difficult to explain, but I'll give it a go. I've
probably got some of it wrong anyway, but at least, then, someone will
correct me.
(all this assumes CONFIG_MODVERSIONS is turned on)
o the kernel is compiled with -include /usr/src/linux/modversions.h. What
this effectively means is that modversions.h is included at the top of every
c file in the kernel.
o so what does this do? Well, if you have a look at modversions.h, it includes
loads of .ver files. Each of these files have loads of lines like (in ksyms.ver)
#define __ver_printk 1b7d4074
#define printk _set_ver(printk)
this winds up having a #define along the line of
#define printk printk_R1b7d4074
o so what does this do? Well, now everywhere printk is mentioned it gets
replaced by printk_R1b7d4074 by the preprocessor. So when the kernel is compiled
there is no such function as printk, there is only one called printk_R1b7d4074.
o so if you want to write a module that uses the 'printk' function(sorry,
I mean the 'printk_R1b7d4074' function) you're going to have to include
modversions.h before printk is defined.
------------
Another question you might ask is how the .ver files get generated?
o well the basic command is along the lines of
gcc -E -D__GENKSYMS__ <the-c-file> | genksys -k <your-kernel-version> > <your-ver-file>
o the gcc part puts the c file through the preprocessor with __GENKSYMS__ defined
o the output of this is passed through to genkyms which generates output like
#define __ver_printk 1b7d4074
#define printk _set_ver(printk)
where the 1b7d4074 depends on the kernel version you supply.
------------
I haven't checked over this carefully so I'm bound to have got some of it
wrong - let me know if I have!
I hope no one is offended by me going through this in baby steps ;)
Good Luck,
Mark
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.surriel.com/kernelnewbies.shtml