Reputation: 1857
I tried to compile the Linux kernel 3.10.31 on Ubuntu 16.04 LTS. I used to compile the exact same kernel on Ubuntu 12.04 LTS, and everything works well.
On Ubuntu 16.04, the gcc version is gcc-5
;
On Ubuntu 12.04, the gcc version is gcc-4.6
.
It seems that the Linux kernel kernel before 3.18 cannot compile with the gcc-5
. The kernel 3.10.31 reports the following error when it is compiled by make
fatal error: linux/compiler-gcc5.h: No such file or directory
I tried to install gcc-4.7 onto Ubuntu 16.04 and change the /usr/bin/gcc
to point to the gcc-4.7. This could solve the above error. However, it leads to new issues after I run make
$linux/arch/x86/Makefile:98: stack protector enabled but no compiler support
make[1]: Nothing to be done for 'all'.
make[1]: Nothing to be done for 'relocs'.
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CC kernel/bounds.s
gcc-4.7.real: error: unrecognized command line option ‘-no-pie’
linux/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:835: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
My question is:
Is there a neat way to use the old compiling chain to compile the old kernel 3.10.31 on Ubuntu 16.04?
Thank you very much for your help! Any advice is really appreciated.
Upvotes: 1
Views: 6030
Reputation: 164
Open the Makefile, look for CFLAGS_EXTRA and add the following option to it -fno-pie. See, https://askubuntu.com/questions/851433/kernel-doesnt-support-pic-mode-for-compiling.
Upvotes: 0
Reputation: 35
Ubuntu 16.04 now still supports gcc-4.7 so you can install it and then you can choose the version of gcc before using it by update-alternatives
.
For examples:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --config gcc # here you choose by hint
If you directly download compiler-gcc5.h
, you may meet problems like arch/x86/kvm/svm.c error invalid character
that I met when compiling 3.3.8
in Ubuntu 16.04.3 x64.
Upvotes: 0