分享
 
 
 

Kernel Compilation& Avoiding ‘Unresolved Symbol’

王朝other·作者佚名  2006-01-30
窄屏简体版  字體: |||超大  

Avoiding ‘Unresolved Symbol’ Sun, 08/01/2004 - 14:36 :: Web Servers & Systems | Tutorials

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 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

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//build/include -

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

-fno-strict-aliasing -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 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

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有