LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Linux Answers > Programming
User Name
Password

Notices

By vikram_cvk at 2004-07-03 04:21
Kernel Compilation & Avoiding 'Unresolved Symbol' HOWTO

Introduction
Many of the kernel newbies are not aware of certain important concepts which are essential for proper compilation and insertion of the modules into the kernel This HOWTO is all about kernel compilation , how to avoid the annoying ''unresolved symbols''errors while Insmoding the modules .

Kernel Compilation

Why a Kernel should be compiled?

By default kernel module version has to be disabled when developing new modules, but this is enabled by default in some older versions of popular distribution.
Apart from this there are many other reasons why a kernel has to be recompiled . I'm not listing all those reasons due to lack of space.

Following are the things to be taken into consideration before compilation.

Creating copy of complete kernel sources at different location other than /usr/src .
Taking a backup of important user data is a good precautionary measure .

Prerequisite for kernel recompilation

Logging in as root.
Kernel sources directory has to be installed on the system ,this could be done by installing the kernel source rpm's from the installation CD's or downloading latest kernels from kernel.org.

Important things to enable/disable in the 'menuconfig' dialog box.

Under Loadable module support
* Enabling 'Enable loadable module support'
* Disabling 'Set version information on all module symbols'

Under Processor type and features
* Selecting the correct processor type
* Enabling Symmetric multi-processing support (regardless of whether your system is single processor or multi processor one)

Under USB Support
* Enabling USB support (If you intend to develop USB drivers)

Under Kernel Hacking
* Enable Kernel Debugging.

Steps in Kernel Compilation

Untar or Install kernel source rpm's.

Go through the 'readme' under kernel source directory.

bash#make menuconfig - Make the above changes and additionally any other changes you want.

bash#make depends - This for knowing about the file dependencies.

bash#make bzImage - This is for creating bootable kernel.

bash#make modules

bash#make modules_install - 6 & 7 commands for compiling the kernel modules if any.

After the above step bootable kernel image is found under /boot/arch/i386/boot/ directory with the file name 'bzImage'

In order to make the BIOS find the above bootable image file any of the below 2 things can be done

10. Making the entry in bootloaders (lilo or grub)

If 'Lilo' is the bootloader then do the following

bash# man lilo
bash# man lilo.conf

In /etc/lilo.conf file add the following lines
image=/boot/bzImage
label=User_Defined_Kernel
root=/dev/hda1
read-only

After editing /etc/lilo.conf
bash# /sbin/lilo

If 'Grub' is the bootloader

In /etc/grub.conf add the following

title Red Hat Linux (2.4.18-19.8.0.19mar2003)
root (hd0,8)
kernel /boot/bzImage ro root=/dev/hda1

Following is optional

Dumping the boot image to a floppy with the following command

bash#cat bzImage > /dev/fd0
Important Tip:

Instead of using kernel sources which comes with the distribution CD's.

It is always better to download the latest kernel from kernel.org. The reason being the kernel sources in the distribution CD's are altered and in many cases it has been found that some header files were missing or they were of the older versions

Avoiding Unresolved Symbols /Version mismatch Errors

Most of the kernel newbie's are intimidated by the Unresolved symbols / Version mismatch errors which they face when trying to compile and 'insmod' there newly compiled kernel modules.

The reasons for this error.............
Though there are many reasons , the most common reason is

Kernel and modules are compiled with different modversion information.

Now you might get a doubt what is this modversion ! Every kernel module created consists of information about the kernel version on which it is compiled , for instance if module X is compiled on kernel 2.4.18 and if you are trying to run this module X on a kernel whose version is 2.4.22 then there will be a mismatch of module versions .

How to avoid this Problem

Add the following at the starting to the kernel module source file you are creating.

#if defined __KERNEL__

#include <linux/config.h>

#if defined( CONFIG_MODVERSIONS ) && ! defined( MODVERSIONS )
#define MODVERSIONS
#endif

/* modversions.h should be before should be before module.h */

#if defined( MODVERSIONS )
#include <linux/modversions.h>
#endif

#include <linux/module.h>
#include <linux/version.h>

/* Now your module include files & source code follows */

Apart from the above you should compile your module with the following compiler flags.

For instance if your module name is xyz.c then -

bash#gcc -I/lib/modules/<current kernel version name >/build/include -

D__KERNEL__ -DMODULE -DLINUX -O2 -Wall -Wstrict-prototypes

-fno-strict-aliasing -fno-strict-aliasing -c -o xyz.o xyz.c

<current kernel source directory >

Substitute the above with the kernel version name you are currently using.You can know that with the following command.

Bash# uname -r

NOTE:
The above hack will help you get rid of the ugly unresolved symbols error only if you have not compiled your brand new kernel , If you have already compiled your kernel then the above will not work because during kernel compilation there is a possibility of some of the header files in the ../include directory getting deleted ,so in such situations you have to reinstall your kernel sources once again and try the above .

CONCLUSION
In spite of all the above still you will get some warnings like 'this is a tainted module blahh blahh' just ignore them. Hope this HOWTO will help you in getting started comfortably in your Kernel programming endeavor !!!!! Very soon I'll come out with a HOWTO on device driver programming , in this I'll try to simplify the task of writing full-fledged device driver (Real device - not a simple 'hello world' program )

This HOWTO is authored by Vikram Kumar C, I'm a Linux freak since ages , currently working as a Linux programmer in the city of Hyderabad, India You can reach me at vikram_147@hotmail.com.

by deoren on Sat, 2004-09-18 13:56
Why is that? I can see that there seems to be a requirement, but is that something that is in the 2.4.x series or is that a distrobution quirk?

by deoren on Sat, 2004-09-18 13:58
Oh yeah, thanks for the HOWTO!

by jp_srirengan on Mon, 2004-11-29 04:52
Hi,
Presrently we are using kernel 2.4.18-14.
I compiled the RH kernel 2.4.25 on 2.4.18.
All the "make" steps gone fine.But in the make modules, modules_install step it throws the message "nothing done".
When i booted the server with new kernel(2.4.25), It doesn't load many modules.Because in make module& modules_install step, it did not build the new modules.

I found this "howto" pdf in a website, It has solution. By including the some "C" code.

But i don't know in which file to include that code and where is that file.

Can anyone please Help me?

Regards,
Jayaprakash

by jp_srirengan on Mon, 2004-11-29 04:55
In the previous post i didnot give my mail-id
This is my mail id- jp_srirengan@yahoo.co.in

by deoren on Sat, 2005-01-15 21:46
Quote:
Originally posted by jp_srirengan
Hi,
Presrently we are using kernel 2.4.18-14.
I compiled the RH kernel 2.4.25 on 2.4.18.
All the "make" steps gone fine.But in the make modules, modules_install step it throws the message "nothing done".
When i booted the server with new kernel(2.4.25), It doesn't load many modules.Because in make module& modules_install step, it did not build the new modules.

I found this "howto" pdf in a website, It has solution. By including the some "C" code.

But i don't know in which file to include that code and where is that file.

Can anyone please Help me?

Regards,
Jayaprakash
What howto and what C code?


  



All times are GMT -5. The time now is 07:44 AM.

Main Menu

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration