Linuxer.
全部博文(199)
分类: LINUX
2013-10-29 11:20:38
1.下载
官方下载地址
Modutils (2.4.27):
2.解压
tar -zxvf modutils-2.4.27.tar.gz
3.生成makefile
./configure
4.make
4.1 错误:
In file included from obj_kallsyms.c:26:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
obj_kallsyms.c: In function ‘obj32_kallsyms’:
obj_kallsyms.c:204: error: lvalue required as left operand of assignment
obj_kallsyms.c:279: error: lvalue required as left operand of assignment
make[1]: *** [obj_kallsyms.o] 错误 1
make[1]: Leaving directory '/usr/src/redflag/BUILD/modutils-2.4.27/obj'
make: *** [all] 错误 2
修改:
(1)将obj_kallsyms.c文件修改如下
将204行的:
a_hdr = (struct kallsyms_header *) osec->contents =xmalloc(osec->header.sh_size);
改成:
osec->contents = xmalloc(osec->header.sh_size);
a_hdr = (struct kallsyms_header *) osec->contents;
将279行的:
a_hdr = (struct kallsyms_header *) osec->contents = xrealloc(a_hdr, a_hdr->total_size);
改成:
osec->contents = xrealloc(a_hdr, a_hdr->total_size);
a_hdr = (struct kallsyms_header *) osec->contents;
4.2 继续make,再错误
In file included from insmod.c:79:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
insmod.c: In function ‘add_symbols_from’:
insmod.c:278: error: lvalue required as left operand of assignment
make[1]: *** [insmod.o] 错误 1
make[1]: Leaving directory ‘/usr/src/redflag/BUILD/modutils-2.4.27/insmod’
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.36012 (%build)
修改:
将insmod.c文件的第278行
((char *)s->name) += 8;
改成
s->name = (void *)((long)(s->name)+8);
再继续编译。
4.3 继续报错:
In file included from genksyms.c:32:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
genksyms.c:48: error: static declaration of ‘errors’ follows non-static declaration
./../include/util.h:43: error: previous declaration of ‘errors’ was here
make[1]: *** [genksyms.o] 错误 1
make[1]: Leaving directory ‘/usr/src/redflag/BUILD/modutils-2.4.27/genksyms’
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.97956 (%build)
修改:
将genksyms.c第48行的语句
static int errors;
移到文件的开头,紧跟注释后的第一行去。
4.4 继续报错:
bison: Command not found
修改:
sudo apt-get install bison
4.5 继续编译,继续报错
flex:Command not found
修改:
sudo apt-get install flex
4.6 继续编译,继续报错
In file included from depmod.c:44:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
depmod.c: In function ‘addksyms’:
depmod.c:1136: error: lvalue required as left operand of assignment
make[1]: *** [depmod.o] 错误 1
make[1]: Leaving directory ‘/usr/src/redflag/BUILD/modutils-2.4.27/depmod’
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.36319 (%build)
修改:
将depmod.c的第1136行:
((char *)ksym->name) += 8;
改成:
ksym->name = (void *)((long)(ksym->name)+8);
5. 终于编译成功,可以到insmod目录下,使用insmod指令加载模块了。注意编译出来的insmod指令只适合2.6 内核以前的版本。这个版本的modutils代码中的很多系统调用在现在的linux内核中已不存在。若想insmod指令能使用新版本的内核,需要下载最新的busybox源码去编译,编译出的insmod指令可以在新内核上使用。