I've been trying to compile the latest Linux v4.8.9 kernel on Ubuntu 16.10 and this error keeps popping up after I've made the default .config, modified it with menuconfig and ran make by itself. I've also run make mrproper as soon as I untarred the file. This is the output right after I run make:

scripts/kconfig/conf  --silentoldconfig Kconfig
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_x32.h
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  HOSTCC  arch/x86/tools/relocs_common.o
  HOSTLD  arch/x86/tools/relocs
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
  WRAP    arch/x86/include/generated/asm/clkdev.h
  WRAP    arch/x86/include/generated/asm/cputime.h
  WRAP    arch/x86/include/generated/asm/dma-contiguous.h
  WRAP    arch/x86/include/generated/asm/early_ioremap.h
  WRAP    arch/x86/include/generated/asm/mcs_spinlock.h
  WRAP    arch/x86/include/generated/asm/mm-arch-hooks.h
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  CC      kernel/bounds.s
kernel/bounds.c:1:0: error: code model kernel does not support PIC mode
 /*

Kbuild:45: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:1015: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2

I've also tried compiling with the -no-pie option after the make command but it renders a set of new errors, constantly saying that there are "missing targets". I have gcc version 6.2.0. I also have gcc-5 installed because I assumed in the beginning it might be because gcc was too new but the same problem persists in gcc-5. Someone in the mailing lists or another forum mentioned that the problem was resolved by directly cloning from git but that didn't help in my scenario either.

I'm curious if anyone else has run into this problem and if so, what a possible fix might be?

NOTE:I'm running Ubuntu in Virtualbox on a Mac if that might be a possible source of problems.

up vote 7 down vote accepted

The issue is with your gcc installation, in gcc 6+ versions PIE( position independent executables) is enabled by default. So in order to compile you need to disable it. Even gcc 5 has the issue. This is a known bug for gcc. Bug Link.

So far there is no official patch from gcc side, so the workaround is to patch the Makefile of kernel source.

If you are familiar with patching the source file use the codes from this link to create the patch file then try to compile.Patch File

Let me know if you are having difficulties installing the patch.

  • I'm a complete linux noob, how would I go about installing the patch in the given website? I assume I copy and paste some portion into a file and run a command? – John Long Nov 21 '16 at 18:10
  • 1
    Unfortunately, I don't have enough rep points to do upvotes but I asked the same question that you just answered on Superuser and I wanted to ask if you would prefer I link this answer to the Superuser question and mark it as answered or you yourself could answer it on superuser. Just want to make sure to give credit where credit is due! – John Long Nov 24 '16 at 17:43
  • 1
    Hi Ninetainedo, please make sure you copied it correctly and copied only from "From" to "2.8.1". – Joy May 22 '17 at 1:10
  • 1
    @Joy I had the same error: patching file Makefile Hunk #1 FAILED at 608. 1 out of 1 hunk FAILED -- saving rejects to file Makefile.rej patch unexpectedly ends in middle of line – rainman Sep 4 '17 at 21:53
  • 1
    the patch doesn't work for 2.6.x versions(i tried in 2.6.39 ) getting this in my patch reject file - pastebin.com/Pmdv1MTT any ideas? – SatheeshJM Sep 8 at 21:16

Open the Makefile, look for CFLAGS_EXTRA and add the following option to it -fno-pie

I had the line:

EXTRA_CFLAGS += $(CFLAGS_EXTRA)

I changed it for:

EXTRA_CFLAGS += $(CFLAGS_EXTRA) -fno-pie

For building kernel 4, above flag is: KBUILD_CFLAGS.

And it started compiling again.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.