FATAL: modpost: Section mismatches detected错误解决

如题,写完驱动后编译内核的时候碰到了这个错误,头一次看到这个编译错误,略懵逼,先给出完整的错误:

WARNING: modpost: Found 2 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
FATAL: modpost: Section mismatches detected.
Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.

根据提示,加上编译选项“CONFIG_DEBUG_SECTION_MISMATCH=y”后可以看到详细的错误地方,然后就能看到下面的错误:

WARNING: drivers/misc/mediatek/built-in.o(.data+0x56ec): Section mismatch in reference from the variable aht10_init_info to the function .init.text:aht10_local_init()
The variable aht10_init_info references
the function __init aht10_local_init()
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console

如果看到这个提示还不懂什么意思的话,可以看看这篇文章:What is kernel section mismatch?。结合文章,意思就是变量aht10_init_info引用了__init aht10_local_init函数,因为函数用__init修饰后,会在执行完就释放函数所占用的内存,那么aht10_init_info再引用__init aht10_local_init函数就是非法的了,我们看一下两者的关系:

static struct hmdy_init_info aht10_init_info = {
		.name = "aht10",
		.init = aht10_local_init,
		.uninit = aht10_local_uninit,
	
};

static __init int aht10_local_init(void)
{
    ...
	return 0;
}

所以想解决这个问题,我们将函数的__init修饰符去掉就好:

static int aht10_local_init(void)
{
    ...
	return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值