Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile a linux 2.6 kernel module with newer compiler

Tags:

I build embedded machines that run an RT_PREMPT version of Linux. It's an Ubuntu 10.04 installation running an Linux 2.6 kernel. Yes, it's an old kernel, but I'm stuck with it for awhile.

When I compiled the kernel, I used gcc version 4.4. On this system, there is a kernel module I have been compiling successfully for three years.

From my Makefile...

all:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) \
    modules

My current project requires support for c++14, so I updated gcc and g++ to version 5.1.0 by building from source. All my user-mode software compiles, but when I went to build an updated version of my kernel module, I get the following error right away:

make[1]: Entering directory `/usr/src/linux-headers-2.6.32-54-generic'
  CC [M]  /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.o
In file included from include/linux/compiler.h:40:0,
             from include/linux/stddef.h:4,
             from include/linux/list.h:4,
             from include/linux/module.h:9,
             from /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.c:31:
include/linux/compiler-gcc.h:86:30: fatal error: linux/compiler-gcc5.h: No such file or directory

In short:

fatal error: linux/compiler-gcc5.h: No such file or directory

If I use gcc 4.4 again (I left it installed on my computer in a different directory), it compiles and runs perfectly.

Obviously, I'm missing something. Is it not possible to compile a kernel module with a newer version of the compiler than what the operating system was compiled with? That seems unlikely to me. Is there a configuration step I'm missing? Is there a system variable I need to update? Are there extra headers I'm supposed to download? I ran apt to update build-essential, but it was up to date. I have the source and headers for the kernel on my system. I'm not sure what else I would download.

Any insights to this problem are greatly appreciated. Thank you in advance.

like image 515
user761576 Avatar asked Apr 28 '15 16:04

user761576


People also ask

How do I cross compile a kernel module?

Build the kernel After we downloaded the kernel and fetched the configuration we can rebuild the kernel. We first need to set the ARCH and CROSS_COMPILE variable. We just need the kernel so that we have all build headers configured and available on the build machine.

What compiler is compile Linux kernel?

The Linux kernel has always traditionally been compiled with GNU toolchains such as GCC and binutils. Ongoing work has allowed for Clang and LLVM utilities to be used as viable substitutes.

What is the difference between insmod and modprobe?

insmod is similar to modprobe: it can insert a module into the Linux kernel. Unlike modprobe, however, insmod does not read its modules from a set location, automatically insert them, and manage any dependencies. insmod can insert a single module from any location, and does not consider dependencies when doing so.


1 Answers

Your kernel version is too old and it is missing linux/compiler-gcc5.h.

The header is included from linux/compiler-gcc.h and its name is generated by preprocessor macro based on current compiler version:

#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)

This header was introduced around version 3.18.

You might try to get this file from a newer kernel source and put in into include/linux.

like image 147
baf Avatar answered Nov 17 '22 10:11

baf