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
package creates an emptyversion.h
file.- What happened to the contents of
linux/version.h
Resolution
Perform either of the following options.
-
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.
-
Module initialization for our custom module below uses an explicit variable
LINUX_VERSION_CODE
which is usually included inversion.h
static int hello_init(void) { printk(KERN_ALERT "version code %d\n", LINUX_VERSION_CODE); return 0; }
-
Because
version.h
is empty, compilation fails due to the missing symbolLINUX_VERSION_CODE
# 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 togcc
for the/lib/modules/3.10.18-rt14.7.el6rt.x86_64/build
directory, along with a few other directories to search. One such directory isgenerated/uapi/linux/version.h
which is generated during compilation. -
The
-I
directive can specify multiple include directories and the first to match successfully is the included file thatgcc
accepts. In this circumstance it is the wrongversion.h
. -
If we remove or delete the empty
version.h
file and then attempt to build, the following should occur:# 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. The discrepancy in whichversion.h
to use was tracked in BZ983603 and fixed in RHSA-2013-1264 -
The empty
version.h
file can be safely 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 toversion.h
as shown below:#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 [...]
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.
Comments