无法编译内核:错误,内核不支持 PIC 模式

use*_*456 10 kernel-modules linux-kernel kali-linux kernel-parameters

我在重新编译内核时遇到了麻烦。下载源码包,解压运行

fakeroot make-kpkg kernel_image  
Run Code Online (Sandbox Code Playgroud)

导致我出错

               [...]

  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  CHK     include/generated/package.h
  UPD     include/generated/package.h
  CC      kernel/bounds.s
kernel/bounds.c:1:0: error: code model kernel does not support PIC mode
Run Code Online (Sandbox Code Playgroud)

该问题可以通过更改使用 获得的内核配置来解决make menuconfig。

如何摆脱这个错误并成功编译

小智 8

来自http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.8-rc2/0002-UBUNTU-SAUCE-no-up-disable-pie-when-gcc-has-it-enabl.patch

您可以尝试以下补丁:

diff --git a/Makefile b/Makefile
index 5c18baa..e342473 100644
--- a/Makefile
+++ b/Makefile
 @@ -612,6 +612,12 @@ endif # $(dot-config)
 # Defaults to vmlinux, but the arch makefile usually adds further targets
 all: vmlinux
 
+# force no-pie for distro compilers that enable pie by default
+KBUILD_CFLAGS += $(call cc-option, -fno-pie)
+KBUILD_CFLAGS += $(call cc-option, -no-pie)
+KBUILD_AFLAGS += $(call cc-option, -fno-pie)
+KBUILD_CPPFLAGS += $(call cc-option, -fno-pie) 
+
 # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
 # values of the respective KBUILD_* variables
 ARCH_CPPFLAGS :=
Run Code Online (Sandbox Code Playgroud)

几个相关的 Debian 门票:

以及相关的 GCC 报告: