![无法编译内核:错误,内核不支持 PIC 模式](https://linux22.com/image/97533/%E6%97%A0%E6%B3%95%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8%EF%BC%9A%E9%94%99%E8%AF%AF%EF%BC%8C%E5%86%85%E6%A0%B8%E4%B8%8D%E6%94%AF%E6%8C%81%20PIC%20%E6%A8%A1%E5%BC%8F.png)
我在重新编译内核时遇到问题。下载源码包,解压并运行
fakeroot make-kpkg kernel_image
导致我犯了错误
[...]
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
该问题可以通过更改使用 获得的内核配置来解决make menuconfig
。
如何消除此错误并成功编译
答案1
您可以尝试以下补丁:
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 :=
一些相关的 Debian 票证:
- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=835148
- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841420
以及相关的海湾合作委员会报告: