Kernel compilation & avoiding 'unresolved symbol'

Source: Internet
Author: User
Avoiding 'unresolved symbol' sun, 08/01/2004-: Web servers & Systems | tutorials

Percent 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 shocould 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 stored 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 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 cocould 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 encryption Ric 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 'bzimag'

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

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 our 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 missing 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 shocould 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 shoshould compile your module with the following compiler flags.

For instance if your module name is xyz. C then

Bash # gcc-I/lib/modules // build/include-

D__kernel _-dmodule-dlinux-O2-wall-wstrict-prototypes

-Fno-strict-aliasing-c-o XYZ. o xyz. c

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 uugly 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 .. /include directory getting deleted, so in such situations you have to reinstall your kernel sources once again and try the above.

Conclusion

Inspite of all the above still you will get some warnings like "This is a tainted module blahh blahhh" 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, he a Linux freak since ages, currently working as a Linux programmer in the city of Hyderabad, India.

Printer-friendly version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.