编译内核模块出现CONFIG_DEBUG_SECTION_MISMATCH=y的警告

来源:互联网 发布:域名没钱 编辑:程序博客网 时间:2024/06/15 17:37
编写kernel驱动时,出现了如下警告:
WARNING: modpost: Found 1 section mismatch(es).


为了确实搞清楚问题所在,利用一个简单的例子来说明
这里我使用的内核版本是 linux-2.6.32.25
其他的版本在编译出错是的提示信息,可能稍微不同。

hello.ko的源代码:
#include <linux/init.h>
#include <linux/module.h>


static int hello_init(void)
{
printk(KERN_INFO " Hello World enter\n");
return 0;
}


static void __exit hello_exit(void) /* 问题所在,具体看下文 */
{
printk(KERN_INFO " Hello World exit\n ");
}


module_init(hello_init);
module_exit(hello_exit);


EXPORT_SYMBOL(hello_init); /* 导出没有 __init 的函数 */
EXPORT_SYMBOL(hello_exit); /* 尝试导出有 __init 标示的函数 */


MODULE_AUTHOR("Jack");
MODULE_LICENSE("Dual BSD/GPL");


/****************************熟悉的分割线********************************/


执行 make 编译时,会出现问题:
WARNING: modpost: Found 1 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
  CC      drivers/char/hello.mod.o
  LD [M]  drivers/char/hello.ko


解决办法:
执行提示的命令:
$ make CONFIG_DEBUG_SECTION_MISMATCH=y

会出现错误的详细信息:
  Building modules, stage 2.
  MODPOST 133 modules
WARNING: drivers/char/hello.o(__ksymtab+0x0): Section mismatch in reference from the variable __ksymtab_hello_init to the function .init.text:hello_init()
The symbol hello_init is exported and annotated __init
Fix this by removing the __init annotation of hello_init or drop the export./* 这句指出了解决这个问题的方法 */


去掉"__init",将
static int __init hello_init(void)
改为:
static int hello_init(void)


重新执行 make -j8 编译,使用-j8多线程编译,加快速度,时间珍贵...
  Building modules, stage 2.
  MODPOST 133 modules
  CC      drivers/char/hello.mod.o
  LD [M]  drivers/char/hello.ko
得到了需要的.ko文件,问题解决
0 0
原创粉丝点击