的版本信息,在Linux内核.mod.c文件含义 [英] Meaning of version info in .mod.c file in Linux kernel

查看:429
本文介绍了的版本信息,在Linux内核.mod.c文件含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有可加载的内核模块,当制作被赋予它会产生一个名为 modulename.mod.c 中除了 modulename.ko

继code摘录从 .mod.c 文件,其中包含一个 {数,函数} 对。
这个数字是什么意义?由编译器是如何产生这个数字?

 静态常量结构modversion_info ____版本[]
__用过的
__attribute __((节(__版本)))= {        {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},
...
...
}


解决方案

包含在所有单个的 __版本部分 *。mod.c 文件

  CRC符号
{0xa6d8dcb5,module_layout},
{0x16c2b958,register_netdevice},
  ......

是符号和它们相应的CRC的列表。这有两个主要用途:


  1. 所有导出的符号的全局列表。

  2. 当加载模块的版本检查 模块。


后面的模块依据版本


  

模块版本是由 CONFIG_MODVERSIONS 标记启用,是
  用作简单的ABI一致性检查。完整的CRC值
  原型导出的符号被创建。当一个模块
  加载/使用时,包含在内核中的CRC值相比较
  在模块中相似的价值观;如果它们不相等,内核
  拒绝,因为它表明该模块是建立与加载模块
  参照不同版本的Linux内核源代码的。


当编译成功后,所有的输出符号的所有CRC的全局列表存储在Linux内核源代码目录中的文件 Module.symvers 英寸基本上这个检查确保正在被从内核模块调用任何导出符号在相同的位置(在内核偏移)存在由模块预期

modpost 工具Linux内核的编译过程中产生的CRC。它是由 modpost脚本。整个过程进行了详细的的文档/的kbuild / modules.txt:438

借助整个源$该modpost工具的C $ c。在Linux内核源代码是可用的。 add_depends() 是相关职能负责在每个生成整个 __版本部分 *。mod.c 文件。

In all loadable kernel modules, when make is given it produces a file called modulename.mod.c in addition to modulename.ko.

Following code excerpt is from a .mod.c file, which contains a {number, function} pair. What is the significance of this number? How this number is generated by the compiler?

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" },
...
...
}

解决方案

The __versions section contained in all the individual *.mod.c files

  CRC         Symbol
{ 0xa6d8dcb5, "module_layout" },
{ 0x16c2b958, "register_netdevice" },
  ...         ...

is a list of symbols and their corresponding CRCs. This has 2 main uses :

  1. Global list of all exported symbols.
  2. Module versioning check when loading ko modules.


Rationale behind Module versioning

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.

Upon successful compilation, The global list of all the CRCs of all the exported symbols is stored in the file Module.symvers in the Linux kernel source directory. Essentially this check ensures that any exported symbol that is being called from a kernel module exists in the same location (offset in the kernel) as expected by the module.

The modpost tool generates the CRCs during compilation of the Linux Kernel. It is invoked by the modpost script. The entire process is explained in detail at the Documentation/kbuild/modules.txt:438.

The entire source code of the modpost tool is available in the Linux kernel source. add_depends() is the relevant function responsible for generating the entire __versions section in each of the *.mod.c files.

这篇关于的版本信息,在Linux内核.mod.c文件含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆