Difference between revisions of "Kernel Build"

From LinuxMIPS
Jump to: navigation, search
(Formatting fixes.)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Problems caused by non-Linux/MIPS toolchain ==
+
First get Linux/MIPS kernel sources, for example from the [[git]] archive.  In the next step we need to configure the kernel sources by running <tt>make config</tt>, <tt>make menuconfig</tt>, <tt>make xconfig</tt>
  
  make[1]: Entering directory `/usr/src/linux-mips/arch/mips/kernel' mips_4KC-gcc  
+
== Build Requirements ==
  -D__ASSEMBLY__ -D__KERNEL__ -I/usr/eldk/usr/src/linux-mips/include
+
The following is about building vanilla linux-mips.org kernels using unmodified GNU toolchains.  Further requirements are documented in <tt>Documentation/Changes</tt>.  Below are additional MIPS-specific requirements.  If you're trying to build a vendor kernel, please consider the vendor supplied or recommended toolchain.
  -D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32 -D_MIPS_SZINT=32  -g -G 0 -mno-abicalls
+
 
  -fno-pic -pipe  -c -o entry.o entry.S
+
=== Linux 2.4 ===
 +
The recommended compiler for building Linux&nbsp;2.4 is gcc&nbsp;2.95 however the large majority of developers is probably user a more modern GCC.  New compilers up to gcc&nbsp;3.3 have been used successfully to build the kernel and only the latest 2.4 kernels have fixed the issues with gcc&nbsp;3.4. GCC 4.x can not be used and with Linux&nbsp;2.4 being in deep freeze mode we generally don't intend to fix such problems but rather recommend to use an older compiler for the kernel.
 +
 
 +
The latest official [http://gcc.gnu.org/ GCC 2] is version 2.95.3<ref>http://gcc.gnu.org/gcc-2.95/ GCC 2.95 release notes</ref>. GCC&nbsp;2.96<ref>http://gcc.gnu.org/gcc-2.96.html GCC steering committee on GCC 2.96</ref> is an unofficial, massively patched version. It provides more efficient optimization with -O2, more strict syntax checking and supports more recent C++ standards. Unfortunately the C++ ABI is not fully compatible<ref>http://www.redhat.com/advice/speaks_gcc.html Red Hat Speaks on gcc 2.96-RH</ref> with the official 2.95.3 nor 3.0.  This is not a concern for building the kernel or modules as those are written in plain C but is a consideration if using a single toolchain for an entire distribution or product.
 +
 
 +
=== Linux 2.6 ===
 +
==== Platform specific constraints ====
 +
* [[IP32|O2]] with an [[R10000]] or [[R12000]] and [[IP22|Indigo²]] with [[R10000]] processors need GCC 4.4 or a patched older version.
 +
* The Lemote 2F defconfig build requires binutils 2.20.2 or binutils 2.21 which at the time of this writing are both still unreleased.  It is not clear when they will be released.  Alternatively a recent binutils CVS version<ref>http://www.gnu.org/software/binutils/</ref>.
 +
 
 +
==== Restrictions of particular GCC versions ====
 +
* GCC 3.2 is a lost cause for building 64-bit kernels
 +
* GCC 3.3 is broken for 64-bit kernels but can just about be kludged to build a 64-bit kernel.
 +
* GCC 3.2 used to work for the rest but it's a very long time since I tested this for a modern kernel.
 +
 
 +
==== Restrictions of particular Linux versions ====
 +
* Linux 2.6 up to 2.6.15 need a gcc&nbsp;2.95..4.0.
 +
* Linux 2.6.16 and older need a GCC older than 4.3.0 to compile.
 +
* Linux 2.6.29 and older need a GCC older than 4.4.0 to compile.  This dependency is being fixed on 2010-05-29 while writing this so you may have to update your kernel to get rid of this dependency.
 +
 
 +
== Common problems ==
 +
=== Problems caused by non-Linux/MIPS toolchain ===
 +
 
 +
<pre>
 +
make[1]: Entering directory `/usr/src/linux-mips/arch/mips/kernel' mips_4KC-gcc  
 +
-D__ASSEMBLY__ -D__KERNEL__ -I/usr/eldk/usr/src/linux-mips/include
 +
-D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32 -D_MIPS_SZINT=32  -g -G 0 -mno-abicalls
 +
-fno-pic -pipe  -c -o entry.o entry.S
 
   
 
   
  entry.S: Assembler messages:
+
entry.S: Assembler messages:
  entry.S:225: Error: unrecognized opcode `reg_s $8,164($29)'
+
entry.S:225: Error: unrecognized opcode `reg_s $8,164($29)'
  entry.S:226: Error: unrecognized opcode `reg_s $8,164($29)'
+
entry.S:226: Error: unrecognized opcode `reg_s $8,164($29)'
 +
</pre>
  
_MIPS_SZLONG etc. are normally defined by the gcc compiler driver.  That is they
+
_MIPS_SZLONG etc. are normally defined by the gcc compiler driver.  That is they should never be defined by the application itself. The precense of such kludgery usually indicates the use of a [[Toolchains|toolchain]] that wasn't configured for a Linux/MIPS target.
should never be defined by the application itself. The precense of such kludgery usually indicates the use of a [[toolchain]] that wasn't configured for a Linux/MIPS target.
+
  
== Ld dies with signal 6 ==
+
=== <tt>ld</tt> dies with signal 6 ===
  
  collect2: ld terminated with signal 6 [Aborted]
+
<pre>
 +
collect2: ld terminated with signal 6 [Aborted]
 +
</pre>
  
 
This is a known bug in some ''very'' old binutils versions.  You will have to upgrade to at least binutils&nbsp;2.8.1 plus very current patches.  With Linux&nbsp;2.4 or newer binutils&nbsp;2.13.2.1 or newer is probably recommended.
 
This is a known bug in some ''very'' old binutils versions.  You will have to upgrade to at least binutils&nbsp;2.8.1 plus very current patches.  With Linux&nbsp;2.4 or newer binutils&nbsp;2.13.2.1 or newer is probably recommended.
  
== Linux 2.6 build fails early ==
+
=== Linux 2.6 build fails early ===
  
<code>
+
<code><pre>
  $ make
+
$ make
  CHK    include/linux/version.h
+
CHK    include/linux/version.h
  HOSTCC  scripts/basic/fixdep
+
HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/split-include
+
HOSTCC  scripts/basic/split-include
  HOSTCC  scripts/basic/docproc
+
HOSTCC  scripts/basic/docproc
  CC      scripts/mod/empty.o
+
CC      scripts/mod/empty.o
  gcc: cannot specify -o with -c or -S and multiple compilations
+
gcc: cannot specify -o with -c or -S and multiple compilations
  make[2]: *** [scripts/mod/empty.o] Error 1
+
make[2]: *** [scripts/mod/empty.o] Error 1
  make[1]: *** [scripts/mod] Error 2
+
make[1]: *** [scripts/mod] Error 2
  make: *** [scripts] Error 2
+
make: *** [scripts] Error 2
</code>
+
</pre></code>
  
 
There are two possible causes for this failure known:
 
There are two possible causes for this failure known:
 
* Make sure you have set CONFIG_CROSSCOMPILE or add <code>CROSS_COMPILE=<[[Endianess#GNU_Configuration_Names|target]]></code> to the make invocation.
 
* Make sure you have set CONFIG_CROSSCOMPILE or add <code>CROSS_COMPILE=<[[Endianess#GNU_Configuration_Names|target]]></code> to the make invocation.
 
* A few early Linux&nbsp;2.6 kernels had a bug which would always result in this error message.  In this case you really should upgrade.
 
* A few early Linux&nbsp;2.6 kernels had a bug which would always result in this error message.  In this case you really should upgrade.
 +
 +
=== Linux 2.6 build fails with <tt>"ld: final link failed: Bad value"</tt> ===
 +
This is caused by a linker bug that exists in at least binutils&nbsp;2.15.  If you hit it you should upgrade to binutils&nbsp;2.16.
 +
 +
== References ==
 +
<references/>

Latest revision as of 15:26, 13 August 2010

First get Linux/MIPS kernel sources, for example from the git archive. In the next step we need to configure the kernel sources by running make config, make menuconfig, make xconfig

Build Requirements

The following is about building vanilla linux-mips.org kernels using unmodified GNU toolchains. Further requirements are documented in Documentation/Changes. Below are additional MIPS-specific requirements. If you're trying to build a vendor kernel, please consider the vendor supplied or recommended toolchain.

Linux 2.4

The recommended compiler for building Linux 2.4 is gcc 2.95 however the large majority of developers is probably user a more modern GCC. New compilers up to gcc 3.3 have been used successfully to build the kernel and only the latest 2.4 kernels have fixed the issues with gcc 3.4. GCC 4.x can not be used and with Linux 2.4 being in deep freeze mode we generally don't intend to fix such problems but rather recommend to use an older compiler for the kernel.

The latest official GCC 2 is version 2.95.3[1]. GCC 2.96[2] is an unofficial, massively patched version. It provides more efficient optimization with -O2, more strict syntax checking and supports more recent C++ standards. Unfortunately the C++ ABI is not fully compatible[3] with the official 2.95.3 nor 3.0. This is not a concern for building the kernel or modules as those are written in plain C but is a consideration if using a single toolchain for an entire distribution or product.

Linux 2.6

Platform specific constraints

  • O2 with an R10000 or R12000 and Indigo² with R10000 processors need GCC 4.4 or a patched older version.
  • The Lemote 2F defconfig build requires binutils 2.20.2 or binutils 2.21 which at the time of this writing are both still unreleased. It is not clear when they will be released. Alternatively a recent binutils CVS version[4].

Restrictions of particular GCC versions

  • GCC 3.2 is a lost cause for building 64-bit kernels
  • GCC 3.3 is broken for 64-bit kernels but can just about be kludged to build a 64-bit kernel.
  • GCC 3.2 used to work for the rest but it's a very long time since I tested this for a modern kernel.

Restrictions of particular Linux versions

  • Linux 2.6 up to 2.6.15 need a gcc 2.95..4.0.
  • Linux 2.6.16 and older need a GCC older than 4.3.0 to compile.
  • Linux 2.6.29 and older need a GCC older than 4.4.0 to compile. This dependency is being fixed on 2010-05-29 while writing this so you may have to update your kernel to get rid of this dependency.

Common problems

Problems caused by non-Linux/MIPS toolchain

make[1]: Entering directory `/usr/src/linux-mips/arch/mips/kernel' mips_4KC-gcc 
-D__ASSEMBLY__ -D__KERNEL__ -I/usr/eldk/usr/src/linux-mips/include
-D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32 -D_MIPS_SZINT=32  -g -G 0 -mno-abicalls
-fno-pic -pipe   -c -o entry.o entry.S
 
entry.S: Assembler messages:
entry.S:225: Error: unrecognized opcode `reg_s $8,164($29)'
entry.S:226: Error: unrecognized opcode `reg_s $8,164($29)'

_MIPS_SZLONG etc. are normally defined by the gcc compiler driver. That is they should never be defined by the application itself. The precense of such kludgery usually indicates the use of a toolchain that wasn't configured for a Linux/MIPS target.

ld dies with signal 6

collect2: ld terminated with signal 6 [Aborted]

This is a known bug in some very old binutils versions. You will have to upgrade to at least binutils 2.8.1 plus very current patches. With Linux 2.4 or newer binutils 2.13.2.1 or newer is probably recommended.

Linux 2.6 build fails early

$ make
CHK     include/linux/version.h
HOSTCC  scripts/basic/fixdep
HOSTCC  scripts/basic/split-include
HOSTCC  scripts/basic/docproc
CC      scripts/mod/empty.o
gcc: cannot specify -o with -c or -S and multiple compilations
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2

There are two possible causes for this failure known:

  • Make sure you have set CONFIG_CROSSCOMPILE or add CROSS_COMPILE=<target> to the make invocation.
  • A few early Linux 2.6 kernels had a bug which would always result in this error message. In this case you really should upgrade.

Linux 2.6 build fails with "ld: final link failed: Bad value"

This is caused by a linker bug that exists in at least binutils 2.15. If you hit it you should upgrade to binutils 2.16.

References

  1. http://gcc.gnu.org/gcc-2.95/ GCC 2.95 release notes
  2. http://gcc.gnu.org/gcc-2.96.html GCC steering committee on GCC 2.96
  3. http://www.redhat.com/advice/speaks_gcc.html Red Hat Speaks on gcc 2.96-RH
  4. http://www.gnu.org/software/binutils/