简体   繁体   English

使用较新的编译器编译linux 2.6内核模块

[英]Compile a linux 2.6 kernel module with newer compiler

I build embedded machines that run an RT_PREMPT version of Linux. 我构建了运行RT_PREMPT版Linux的嵌入式机器。 It's an Ubuntu 10.04 installation running an Linux 2.6 kernel. 这是运行Linux 2.6内核的Ubuntu 10.04安装。 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. 当我编译内核时,我使用了gcc 4.4版。 On this system, there is a kernel module I have been compiling successfully for three years. 在这个系统上,有一个我已经成功编译了三年的内核模块。

From my Makefile... 从我的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. 我当前的项目需要支持c ++ 14,所以我通过从源代码构建将gcc和g ++更新到版本5.1.0。 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. 如果我再次使用gcc 4.4(我把它安装在我的计算机上的不同目录中),它会编译并运行完美。

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. 我运行apt来更新build-essential,但它是最新的。 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. 先感谢您。

Your kernel version is too old and it is missing linux/compiler-gcc5.h . 你的内核版本太旧了,缺少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: 头文件包含在linux / compiler-gcc.h中 ,其名称由预处理器宏根据当前编译器版本生成:

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

This header was introduced around version 3.18 . 这个标题是在版本3.18附近引入的。

You might try to get this file from a newer kernel source and put in into include/linux . 您可能尝试从较新的内核源获取此文件并将其放入include/linux

Open a terminal and type: 打开终端并输入:

$ ls -r /usr/src/linux-headers-$(uname -r)/include/linux/ | \
  grep -P "compiler-gcc\d.h" | \
  head -n 1

this will hopefully output the latest gcc header suitable for your linux kernel. 这将有希望输出适合您的Linux内核的最新gcc头。

In my case it is compiler-gcc4.h . 在我的例子中,它是compiler-gcc4.h Now you can link this file to compiler-gcc5.h in the following way: 现在,您可以通过以下方式将此文件链接到compiler-gcc5.h

$ sudo ln -s /usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc4.h \
             /usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc5.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM