I'm trying to compile an older version of Linux (3.4) on my Linux box with its current gcc-6.3. But running the make command shows errors like this:

scripts/kconfig/conf.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC

And I haven't found any solution yet. It seems that the gcc requires using fPIC flag for some objects which the 3.4 kernel config files haven't asked so. Preferably I don't want to touch the kernel defaults. How should I ask the gcc to stop requiring this flag or to disable it?


My guess is that you are using a version of gcc that is modified to produce PIE (position independent executables) by default. According to this page at least Ubuntu has done this switch. The code in the scripts/kconfig directory is for auxiliary programs that is not linked into the kernel, and (afaik) does not link to external static libraries. Thus it shouldn't really matter what the default is, unless you have some leftovers from a previous run with a compiler version with a different default. Run make clean and recompile.

If this does not help, take a look at the Makefile for the current kernel, which forces -no-pie.

  • Thanks I did a make clean and the previous error disappeared but a new one is now shown: scripts/mod/empty.c:1:0: error: code model kernel does not support PIC mode. Also a warning says: arch/x86/Makefile:81: stack protector enabled but no compiler support – user2808671 Apr 7 '18 at 6:07
  • You will have to copy the -fno-pie setting from the current Makefile to tell your compiler to not produce position independent code. Or, you will have to get (build) a compiler which does not generate PIC by default. Editing the Makefile is probably easier. I guess you can ignore the stack protector warning. – Johan Myréen Apr 7 '18 at 6:22
  • I edited the Makefile and the previous error gave way to another new one: include/linux/compiler-gcc.h:100:30: fatal error: linux/compiler-gcc6.h: No such file or directory. I looked at the include directory of this kernel and it only has header files for gcc3 and gcc4. It seems that I have to use an older gcc to compile this. Am I right? – user2808671 Apr 7 '18 at 6:26
  • Yes, it's beginning to look like using an older compiler is the safest and easiest way. – Johan Myréen Apr 7 '18 at 7:02

Whatever error I solved a new one appeared in next compilation try. Unfortunately the best solution I found was to use an older gcc to compile this kernel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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