Home  >  Q&A  >  body text

linux - 为什么编译内核模块需要内核的source code?

鸟哥说

由於核心模組的編譯其實與核心原本的原始碼有點關係的,因此如果你需要重新編譯模組時, 那除了 make, gcc
等主要的編譯軟體工具外,你還需要的就是 kernel-devel
這個軟體!記得一定要安裝喔!而如果你想要在預設的核心底下新增模組的話,那麼就得要找到 kernel 的 SRPM 檔案了!
將該檔案給他安裝,並且取得 source code 後,才能夠順利的編譯喔!

这里前半段话说的很清楚,编译内核模块需要gcc,make,kernel-devel提供的头文件,那这句话是什么意思呢:

而如果你想要在預設的核心底下新增模組的話,那麼就得要找到 kernel 的 SRPM 檔案了!

这句话的意思是不是把内核模块编译进内核,变成内核的一部分,也就是built-in?不然又为什么需要内核的源码呢?

大家讲道理大家讲道理2766 days ago371

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 13:16:27

    For example, when doing embedded development, the kernel of your local machine and the target machine are different. How can you program a kernel module on the local machine that can work on the target machine?

    In addition to the compilation tool chain corresponding to the target machine architecture, you also need a kernel source corresponding to the target machine kernel version. The method to obtain this kernel source is to install a kernel-devel SRPM corresponding to the target machine kernel version ( source RPM), and specify the parameters of the make -C option during compilation to the kernel source directory of the target machine version.

    Additional note:
    The kernel is changing all the time. A kernel module will inevitably use functions exported by the kernel and other modules. How to ensure that these interfaces can correspond to its kernel module? The kernel's approach is to provide each release of the kernel version. Make a tag. This value can be viewed from the output of uname -r.
    When using the modinfo command to view the attributes of a kernel module, the signature saved in the vergemic field must be consistent with the output of uname -r on the target machine, so that the kernel module can be inserted.

    reply
    0
  • Cancelreply