understanding LINUX_VERSION_CODE

拜拜、爱过 提交于 2019-12-11 01:04:06

问题


Im wrinting a kernel module and i found a problem testing my LKM again centos 7.

uname -a print 3.10.0-123.13.2.el7.x86_64, and i'm compiling my KM with this kernel-headers /usr/src/kernels/3.10.0-123.13.2.el7.x86_64/ and using LINUX_VERSION_CODE to define my code sections.

my problem is, the compilation fail because the kernel-headers include code added in more new kernel version but LINUX_VERSION_CODE returns 3.10.

for example, nf_hookfn was modify in kernel 3.13 and i have this modification already in my headers.

what can i do?


回答1:


the LINUX_VERSION_CODE return the Linux version 3.10 and not the CentOS Linux version 3.10.0-123.13.2.el7. Theoretically, they should not apply patch with API changes ... you just discovered the reason :)

If on CentOS is possible to change stable API, they should provide something similar to LINUX_VERSION_CODE for CentOS.

You can define your own pre-processor variable and at compile-time assert or de-assert it according to the kernel version that you want to use (standard 3.10 or CentOS 3.10)

#ifdef CENTOS_PATCH /* CentOS 3.10 */
    ....
#else /* Standard 3.10 */
    ....
#endif

But then you have to manage two different binaries




回答2:


Centos provides some useful macro for that purpose:

#if RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(7,2)
//
#else
//
#endif

And yep, Centos custom kernel pull up some changes from recent Linux kernels.



来源:https://stackoverflow.com/questions/27761061/understanding-linux-version-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!