# [solved]Kernel Build Fails: Kbuild does not support PIC mode

## grellyd

Hi all,

I am having some troubles after the 17.0 upgrade. In particular with the -PIC flag on the new gcc 6+ compiler and building the kernel.

I am experiencing the same symptoms from https://bugs.gentoo.org/621848.

I have corrected all emerge errors and every package has been rebuilt successfully on my system. However the problem comes when attempting to add new kernel flags. 

After doing `make menuconfig` and selecting a few new options, when I go to do `make` I get:

```

  CHK     include/config/kernel.release

  CHK     include/generated/uapi/linux/version.h

  CHK     include/generated/utsrelease.h

  CC      kernel/bounds.s

kernel/bounds.c:1:0: error: code model kernel does not support PIC mode

 /*

 

make[1]: *** [Kbuild:45: kernel/bounds.s] Error 1

make: *** [Makefile:986: prepare0] Error 2

```

After extensive searching and trying the fixes suggested in various forum threads and the above bug thread, nothing has resolved my issue. 

I also noted the bug thread was marked as 'Fixed and Resolved', yet I did not see where or how. Thinking it may just be in the most recent Linux tree, I re-emerged the Linux sources and tried to upgrade to Linux-4.9, but to no avail.

Any help would be highly appreciated. 

---Grellyd

----------

## fedeliallalinea

It seems a gcc 6 bug, you have two workaround

 Remove CONFIG_CC_STACKPROTECTOR_STRONG from kernel config

 Apply a patch (not personal tested) to kernel Makefile

----------

## NeddySeagoon

grellyd,

4.4.6-gentoo is an old kernel. Update it. Current stable is 4.9.76-r1

----------

## fedeliallalinea

 *NeddySeagoon wrote:*   

> 4.4.6-gentoo is an old kernel. Update it. Current stable is 4.9.76-r1

 

Mmm I don't see that, thanks NeddySeagoon.

grellyd probably changing  with a newest  kernel is the best solution, forgets my workarounds

----------

## grellyd

 *Quote:*   

> 4.4.6-gentoo is an old kernel. Update it. Current stable is 4.9.76-r1 

 

Thanks for the replies you two. The kernel upgrade was one of the last things that I tried. That also doesn't build.

Currently I get:

```

/usr/src/linux # eselect kernel list

Available kernel symlink targets:

  [1]   linux-4.4.6-gentoo

  [2]   linux-4.9.76-gentoo-r1 *

/usr/src/linux # make silentoldconfig

scripts/kconfig/conf  --silentoldconfig Kconfig

/usr/src/linux # make -j4

  CHK     include/config/kernel.release

  CHK     include/generated/uapi/linux/version.h

  CHK     include/generated/utsrelease.h

  HOSTCC  scripts/kallsyms

  CC      scripts/mod/empty.o

scripts/mod/empty.c:1:0: error: code model kernel does not support PIC mode

 /* empty file to figure out endianness / word size */

 

  HOSTCC  scripts/selinux/genheaders/genheaders

make[2]: *** [scripts/Makefile.build:259: scripts/mod/empty.o] Error 1

make[1]: *** [scripts/Makefile.build:403: scripts/mod] Error 2

make[1]: *** Waiting for unfinished jobs....

  HOSTCC  scripts/selinux/mdp/mdp

make: *** [Makefile:545: scripts] Error 2

make: *** Waiting for unfinished jobs....

```

which seems to be the same error as before? 

The one thing I have not tried yet is nuking the directory as suggested in https://wiki.gentoo.org/wiki/Kernel/Upgrade#Solving_build_problems. I'll try that next.

----------

## grellyd

 *Quote:*   

> The one thing I have not tried yet is nuking the directory as suggested in https://wiki.gentoo.org/wiki/Kernel/Upgrade#Solving_build_problems. I'll try that next.

 

That got a bit farther, but same produced the same result:

```

/usr/src/linux # cp .config /usr/src/kernel_config_bk

/usr/src/linux # ls /usr/src

kernel_config_bk  linux  linux-4.12.12-gentoo  linux-4.12.5-gentoo  linux-4.4.6-gentoo  linux-4.9.76-gentoo-r1

/usr/src/linux # make distclean

  CLEAN   .

  CLEAN   arch/x86/entry/vdso

  CLEAN   arch/x86/kernel/cpu

  CLEAN   arch/x86/kernel

  CLEAN   arch/x86/realmode/rm

  CLEAN   arch/x86/lib

  CLEAN   drivers/firmware/efi/libstub

  CLEAN   drivers/tty/vt

  CLEAN   drivers/video/logo

  CLEAN   firmware

  CLEAN   lib

  CLEAN   security/selinux

  CLEAN   usr

  CLEAN   arch/x86/boot/compressed

  CLEAN   arch/x86/boot

  CLEAN   arch/x86/tools

  CLEAN   .tmp_versions

  CLEAN   scripts/basic

  CLEAN   scripts/kconfig

  CLEAN   scripts/mod

  CLEAN   scripts/selinux/genheaders

  CLEAN   scripts/selinux/mdp

  CLEAN   scripts

  CLEAN   include/config include/generated arch/x86/include/generated

  CLEAN   .config .config.old .version Module.symvers

/usr/src/linux # mv /usr/src/kernel_config_bk .config

/usr/src/linux # make -j9

  HOSTCC  scripts/basic/fixdep

  HOSTCC  scripts/kconfig/conf.o

  SHIPPED scripts/kconfig/zconf.tab.c

  SHIPPED scripts/kconfig/zconf.lex.c

  SHIPPED scripts/kconfig/zconf.hash.c

  HOSTCC  scripts/kconfig/zconf.tab.o

  HOSTLD  scripts/kconfig/conf

scripts/kconfig/conf  --silentoldconfig Kconfig

  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_32.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

  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

  HOSTCC  scripts/kallsyms

  HOSTCC  scripts/conmakehash

  HOSTCC  scripts/pnmtologo

  HOSTCC  scripts/sortextable

  CC      scripts/mod/empty.o

  HOSTCC  scripts/selinux/genheaders/genheaders

scripts/mod/empty.c:1:0: error: code model kernel does not support PIC mode

 /* empty file to figure out endianness / word size */

 

make[2]: *** [scripts/Makefile.build:259: scripts/mod/empty.o] Error 1

make[1]: *** [scripts/Makefile.build:403: scripts/mod] Error 2

make[1]: *** Waiting for unfinished jobs....

  HOSTCC  scripts/selinux/mdp/mdp

make: *** [Makefile:545: scripts] Error 2

make: *** Waiting for unfinished jobs....

```

----------

## grellyd

While looking back at your comment @fedeliallalinea  *Quote:*   

> Remove CONFIG_CC_STACKPROTECTOR_STRONG from kernel config

  I wanted to see if it was set, and how I could remove it. So I grepped the file. 

```
/usr/src/linux # grep STACKPROTECTOR .config

CONFIG_HAVE_CC_STACKPROTECTOR=y

# CONFIG_CC_STACKPROTECTOR is not set

CONFIG_CC_STACKPROTECTOR_NONE=y

# CONFIG_CC_STACKPROTECTOR_REGULAR is not set

# CONFIG_CC_STACKPROTECTOR_STRONG is not set

```

Does this look correct for a 4.9 Kernel? 'STRONG' does not appear to be set.

Could I have made an error while upgrading my kernel?

----------

## Jaglover

After setting the symlink with eselect you need to do:

```
cd ../linux
```

----------

## grellyd

 *Jaglover wrote:*   

> After setting the symlink with eselect you need to do:
> 
> ```
> cd ../linux
> ```
> ...

 

Ah that makes sense. Otherwise I'm still in the wrong directory. 

I'll try that now. It seems promising. 

I missed that on https://wiki.gentoo.org/wiki/Kernel/Upgrade I'll put in a wiki edit.

----------

## grellyd

My kernel compile is now running well. 

Thanks for the help everyone.

My wiki edit to hopefully stop someone making the same mistake in the future: https://wiki.gentoo.org/wiki/Kernel/Upgrade#Moving_to_the_new_folder

----------

