0

Related to:

Cannot compile kernel: error, kernel does not support PIC mode

I also just had this issue, instead of patching;

I configured alternates with a different gcc version, jumped from v4 to v5, it's compiling now.

$ update-alternatives --config gcc
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-6     30        auto mode
  1            /usr/bin/gcc-4.8   10        manual mode
* 2            /usr/bin/gcc-5     20        manual mode
  3            /usr/bin/gcc-6     30        manual mode

What issues could arise, are there any best practice for choosing a GCC version for compiling the kernel?

The system is Debian Stretch.

closed as too broad by Thomas Dickey, HalosGhost, techraf, G-Man, countermode Oct 31 '16 at 3:05

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • See for example discussion on StackOverflow. – Thomas Dickey Oct 30 '16 at 15:47
  • i want to use gcc, that article is about using something other than gcc. – mikejonesey Oct 30 '16 at 15:55
3

According to the kernel documentation, you should be able to use any version of GCC starting with 3.2. In practice though, I don't think older versions of GCC tend to be tested much with kernel builds, so you're better off using newer versions of GCC (but not too new, there are issues with GCC 6).

In Debian, you can find out the appropriate version of GCC by looking at the kernel source package's build dependencies, or the kernel header package's dependencies. Thus, linux-headers-4.7.0-1-amd64 depends on linux-compiler-gcc-5-x86 which depends on gcc-5.

You can retrieve the correct value of CC automatically by pulling in the values from /usr/src/linux-headers-$(uname -r)/.kernelvariables (after installing linux-headers-$(uname -r) if necessary). For example, my system currently has

override ARCH = x86
override KERNELRELEASE = 4.7.0-1-amd64
CCACHE = ccache
CC = $(if $(DEBIAN_KERNEL_USE_CCACHE),$(CCACHE)) $(CROSS_COMPILE)gcc-5
ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
override CROSS_COMPILE = $(DEB_HOST_GNU_TYPE)-
endif

Using this CC will produce a working kernel (or module for the running kernel) regardless of the default GCC (I use GCC 6 as the default).

  • not using the OS kernels, but that's great info. One particular thing i was interested to know would be if any system library would have some sort of incompatibility having compiled the kernel with v5, but if the os kernel is using v5 then i guess not. – mikejonesey Oct 30 '16 at 15:59
  • No, there shouldn't be any incompatibility between the kernel and system libraries (if there were, it would be a bug, of the kind that would be fixed rather quickly). – Stephen Kitt Oct 30 '16 at 17:17

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