The header file linux/version.h is empty from MRG version 2 realtime kernel
Environment
- Red Hat Enterprise Linux 6
- MRG-Realtime v2
- kernel-rt-3.6.11.5-rt36 or earlier
Issue
- The version information linux/version.h is empty
- kernel-rt-devel creates an empty version.h file.
- What happened to the contents of linux/version.h
Resolution
There are two possible options.
1) remove the empty version.h file
# mv /usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64/include/linux/version.h /tmp/
2) Upgrade to kernel-rt-3.6.11.5-rt37 or newer
This is tracked in this bugzilla and fixed in HSA-2013-1264
Root Cause
The example below shows building a simple kernel module in the affected MRG kernel.
-- The module init uses an explicit var from LINUX_VERSION_CODE which is usually included in version.h --
static int hello_init(void)
{
printk(KERN_ALERT "version code %d\n", LINUX_VERSION_CODE);
return 0;
}
So when this is attempted to be compiled, the expected defined variable is considered missing.
make -C /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build M=/root/test-module modules
make[1]: Entering directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
CC [M] /root/test-module/hello.o
/root/test-module/hello.c: In function ‘hello_init’:
/root/test-module/hello.c:11: error: ‘LINUX_VERSION_CODE’ undeclared (first use in this function)
/root/test-module/hello.c:11: error: (Each undeclared identifier is reported only once
/root/test-module/hello.c:11: error: for each function it appears in.)
make[2]: *** [/root/test-module/hello.o] Error 1
When building out-of-tree kernel modules the kernel can include a default search include path to gcc. This is usually hidden to reduce the complexity visible to module developers.
Internally the system is adding the-I parameter to gcc for the /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build directory, along with a few other directories to search, the one that we need to use is the generated generated/uapi/linux/version.h .
The -I directive can specify multiple include directories and the first to success the match, is the included file that gcc accepts. In this circumstance it is the -wrong- version.h.
Under the covers gcc's include directive includes -I generated/uapi/
If we remove or delete the empty version.h file
And then attempt to build:
# make
make -C /lib/modules/3.10.18-rt14.7.el6rt.x86_64/build M=/root/test-module modules
make[1]: Entering directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
CC [M] /root/test-module/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /root/test-module/hello.mod.o
LD [M] /root/test-module/hello.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.18-rt14.7.el6rt.x86_64'
The correct versions.h is used and the module builds.
This seems to be a bug to have the blank version.h included in the MRG -devel package, and it should not be included.
The file can be removed as part of the "make" if required (although this does mean you run make with sufficient privileges), or you can alternatively specify the FULL path to version.h as shown below:
Something similar to this (untested):
#ifdef VERSION_H_WORKAROUND
#include <generated/uapi/linux/version.h>
#endif
#include <linux/version.h> // this should include an empty file, which.. doesn't matter.
And then set it as a define at compile time, (likely through the makefile).
# gcc -Wall -DVERSION_H_WORKAROUND module_name.c etc etc.
Diagnostic Steps
# rpm -ql kernel-rt-devel|grep linux/version.h
/usr/src/kernels/3.8.13-rt14.25.el6rt.x86_64/include/generated/uapi/linux/version.h
/usr/src/kernels/2.6.33.9-rt31.86.el5rt-x86_64/include/linux/version.h
#define LINUX_VERSION_CODE 132641
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
