Linux驱动模块编译报错 ‘init_module‘ specifies less restrictive attribute than its target

在学习写Linux模块驱动的时候写了个demo,分别在自己的电脑和RockPi4B上分别尝试运行,在自己电脑上能顺利运行,但是在RockPi4B上编译时却发生如下报错

编译报错

include/linux/module.h:130:6: warning: 'init_module' specifies less restrictive attribute than its target 'demo_init': 'cold' [-Wmissing-attributes]
error, forbidden warning:module.h:130
  130 |  int init_module(void) __attribute__((alias(#initfn)));
      |      ^~~~~~~~~~~
/home/rock/Linux_driver/chardev_hello/chardevbase.c:76:1: note: in expansion of macro 'module_init'
   76 | module_init(demo_init);
      | ^~~~~~~~~~~
/home/rock/Linux_driver/chardev_hello/chardevbase.c:55:19: note: 'init_module' target declared here
   55 | static int __init demo_init(void)
      |                   ^~~~~~~~~
In file included from /home/rock/Linux_driver/chardev_hello/chardevbase.c:2:
include/linux/module.h:136:7: warning: 'cleanup_module' specifies less restrictive attribute than its target 'demo_exit': 'cold' [-Wmissing-attributes]
error, forbidden warning:module.h:136
  136 |  void cleanup_module(void) __attribute__((alias(#exitfn)));
      |       ^~~~~~~~~~~~~~
/home/rock/Linux_driver/chardev_hello/chardevbase.c:77:1: note: in expansion of macro 'module_exit'
   77 | module_exit(demo_exit);
      | ^~~~~~~~~~~
/home/rock/Linux_driver/chardev_hello/chardevbase.c:65:20: note: 'cleanup_module' target declared here
   65 | static void __exit demo_exit(void)

查阅了一些社区资料后大概确定这个报错与Linux内核代码和编译器gcc-9有关系。
GCC 9.0: ‘init_module’ specifies less restrictive attribute than its target

这个Bug貌似在Linux内核代码 5.0后的某个版本修复了,而我电脑上的内核代码版本为 5.13.0-40,RockPi4B上的内核代码为 4.4.154-116,所以会发生如上问题。

由于RockPi的官方并没有在RockPi4B上出新的内核版本系统,所以我直接选择更换make时使用的编译器

make CC=gcc-8	#指定使用gcc-8编译器

或者在Makefile首行中添加

CC := gcc-8

最后编译成功

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值