10

I have troubles recompiling my Kernel. Downloading the source package, decompress it and running

fakeroot make-kpkg kernel_image  

leads me to the error

               [...]

  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

The issue may be solved by changing the Kernel configuration obtained with make menuconfig.

How to get rid of this error and have successful compilation

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
user123456
  • 4,758
  • 11
  • 52
  • 78
  • That PIE has nothing to do with your problem. What exact distribution and package versions are you using? What version of make and gcc? On what architecture? – Gilles 'SO- stop being evil' Oct 29 '16 at 22:07
  • `uname -a` gives me `Linux hostname 4.6.0-kali1-amd64 #1 SMP Debian 4.6.4-1kali1 (2016-07-21) x86_64 GNU/Linux` and gcc version is `gcc (Debian 6.2.0-9) 6.2.0 20161019`. I have followed [those](http://docs.kali.org/development/recompiling-the-kali-linux-kernel) precise indications . – user123456 Oct 29 '16 at 23:22

1 Answers1

8

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

You might try the following 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 :=

A couple of related Debian tickets:

And a related GCC report:

Toby Speight
  • 8,460
  • 3
  • 26
  • 50
  • How does one apply this patch? See also my related question about compiling the Intel e1000e driver, which gives the same error: http://askubuntu.com/questions/851721/ubuntu-16-10-intel-e1000e-driver-cannot-be-compiled-because-kernel-does-not-supp – Amedee Van Gasse Nov 21 '16 at 21:26
  • /usr/src/linux-headers-4.8.0-27/arch/x86$ cat ~/e1000e-3.3.4/disable-pie.patch | sudo patch -p1 patching file Makefile patch: **** malformed patch at line 7: all: vmlinux – Amedee Van Gasse Nov 21 '16 at 22:02
  • For the patch I show above, this is meant to be applied to the Makefile in the linux directory. For example, after downloading https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.8.15.tar.xz, and expanding the source, change into linux-4.8.15, and there should be a Makefile there. The patch above is applied to that Makefile, or just manually edit the file (I use sed to apply the change). Another note: the flags are needed with gcc6 but not with gcc5. – Raymond Burkholder Jan 02 '17 at 17:28
  • I use the following for my kernel builds: https://github.com/rburkholder/vagrant/blob/master/bldkrnlpkg/buildkrnl.sh on debian/stretch – Raymond Burkholder Jan 02 '17 at 17:34