简体   繁体   English

Linux内核模块编程-不能使用CONFIG_CC_STACKPROTECTOR_REGULAR:编译器不支持-fstack-protector

[英]Linux kernel module programming - Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler

I am on Linux Ubuntu 14.04. 我在Linux Ubuntu 14.04上。 I want to start Linux Kernel Module Programming. 我想开始Linux内核模块编程。 I have hello.c (simple Hello World module) and Makefile. 我有hello.c(简单的Hello World模块)和Makefile。 But, on "make" command, I get error. 但是,在“ make”命令上,我得到了错误。

I tried Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler , but it did not work for me. 我尝试过不能使用CONFIG_CC_STACKPROTECTOR_STRONG:编译器不支持-fstack-protector-strong ,但是对我不起作用。

hello.c 你好ç

/* hello.c − Illustrating the __init, __initdata and __exit macros. */

#include <linux/module.h>
/* Needed by all modules */
#include <linux/kernel.h>
/* Needed for KERN_INFO */
#include <linux/init.h>
/* Needed for the macros */

static int hello3_data __initdata = 3;

static int __init hello_3_init(void)
{
  printk(KERN_INFO "Hello, world %d\n", hello3_data);
  return 0;
}

static void __exit hello_3_exit(void)
{
  printk(KERN_INFO "Goodbye, world 3\n");
} 

module_init(hello_3_init);
module_exit(hello_3_exit);

Makefile 生成文件

obj-m += hello.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

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

On "make" :- 在“ make”上:-

k@k-Inspiron-3542:~/Kernel programs$ make
make -C /lib/modules/4.2.0-27-generic/build M=/home/k/Kernel programs modules
make[1]: Entering directory `/usr/src/linux-headers-4.2.0-27-generic'
arch/x86/Makefile:138: CONFIG_X86_X32 enabled but no binutils support
Makefile:662: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
make[1]: *** No rule to make target `programs'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-4.2.0-27-generic'
make: *** [all] Error 2

Currently, my ubuntu has 4.2 kernel. 目前,我的ubuntu有4.2内核。 I even tried this on 3.x kernel, but there was this same error. 我什至在3.x内核上尝试过此操作,但存在相同的错误。

Please help me in this. 请帮助我。 Thanks. 谢谢。 :) :)

I had searched a lot before asking this question, but no solution worked for me. 在问这个问题之前,我进行了很多搜索,但是没有解决方案对我有用。 I continued my search and finally, this solution worked for me. 我继续搜索,最后,此解决方案对我有用。 https://askubuntu.com/questions/367838/compiling-error-while-installing-realtek-rtl8111e-in-64-bit-13-10-config-x86-x https://askubuntu.com/questions/367838/compiling-error-while-installing-realtek-rtl8111e-in-64-bit-13-10-config-x86-x

Strangely, there should be no space(s) in the directory name in which kernel modules are there. 奇怪的是,目录名称中不应包含内核模块的空格。 So, I removed the space and it worked. 因此,我删除了空间,它开始工作了。

Hope it will help someone in future. 希望以后能对某人有所帮助。 :) :)

Your file works OK here. 您的文件在这里工作正常。 With your Makefile, and with the default Makefile: 使用您的Makefile和默认的Makefile:

obj-m   := hello.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD     := $(shell pwd)

default:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
    $(MAKE) -C $(KDIR) M=$(PWD) clean

The files hello.ko, hello.mod.c, hello.mod.o, hello.o, modules.order, Module.symvers are created. 将创建文件hello.ko, hello.mod.c, hello.mod.o, hello.o, modules.order, Module.symvers May be install this: sudo apt install g++ binutils-dev 可能是这样安装的: sudo apt install g++ binutils-dev

If you don't have spaces in your compile directory and you're still getting this error, your kernel compilation may be failing because its directory belongs to root and you're running as an unprivileged user. 如果您的编译目录中没有空格,并且仍然出现此错误,则内核编译可能会失败,因为其目录属于root并且您以非特权用户身份运行。 Try sudo make 尝试sudo make

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

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