加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux内核中.mod.c文件中版本信息的含义

发布时间:2020-12-14 01:46:42 所属栏目:Linux 来源:网络整理
导读:在所有可加载的内核模块中,当给出make时,除了modulename.ko之外,它还会生成一个名为modulename.mod.c的文件. 以下代码摘录来自.mod.c文件,其中包含{number,function}对. 这个号码有什么意义?这个数字是如何由编译器生成的? static const struct modversion
在所有可加载的内核模块中,当给出make时,除了modulename.ko之外,它还会生成一个名为modulename.mod.c的文件.

以下代码摘录来自.mod.c文件,其中包含{number,function}对.
这个号码有什么意义?这个数字是如何由编译器生成的?

static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {

        { 0xa6d8dcb5,"module_layout" },{ 0x16c2b958,"register_netdevice" },{ 0x609f1c7e,"synchronize_net" },{ 0x90a60c63,"kmem_cache_destroy" },{ 0x402b8281,"__request_module" },{ 0x844a8af7,"netdev_info" },{ 0xdfdb0ee8,"kmalloc_caches" },{ 0x12da5bb2,"__kmalloc" },{ 0x92d42843,"cfg80211_cqm_rssi_notify" },{ 0xc86289e8,"perf_tp_event" },...
...
}

解决方法

__versions部分包含在所有单独的* .mod.c文件中

CRC         Symbol
{ 0xa6d8dcb5,...         ...

是一个符号列表及其相应的CRC.这有两个主要用途:

>所有导出符号的全局列表.
>加载ko模块时的模块版本检查.

模块版本控制背后的基本原理

Module versioning is enabled by the CONFIG_MODVERSIONS tag,and is
used as a simple ABI consistency check. A CRC value of the full
prototype for an exported symbol is created. When a module is
loaded/used,the CRC values contained in the kernel are compared with
similar values in the module; if they are not equal,the kernel
refuses to load the module as it indicates that the module is built with
reference to a different version of the Linux kernel source.

编译成功后,所有导出符号的所有CRC的全局列表都存储在Linux内核源目录的Module.symvers文件中.本质上,此检查确保从内核模块调用的任何导出符号都存在于模块所期望的相同位置(内核中的偏移量).

modpost工具在编译Linux内核期间生成CRC.它由modpost script调用.整个过程在Documentation/kbuild/modules.txt:438详细解释.

entire source code of the modpost tool在Linux内核源代码中可用. add_depends()是负责在每个* .mod.c文件中生成整个__versions部分的相关函数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读