Meaning of version info in .mod.c file in Linux kernel

前端 未结 1 1664
予麋鹿
予麋鹿 2021-01-18 09:09

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

Fo

相关标签:
1条回答
  • 2021-01-18 09:34

    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.rst:450.

    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.

    0 讨论(0)
提交回复
热议问题