Search code examples
eclipsegcckernel32bit-64bittoolchain

Is it necessary to use a toolchain to compile a Kernel?


I want to start using this board for development purposes: Pm-Pv-D525

My aim is to compile a 32bit Kernel and constrcut a root file system etc. The board runs on an Intel Atom D525 (architecture: x86_64). I want to use Eclipse and perform cross-compiling and debugging over it. I'm using ubuntu 14.04 LTS on a x64 machine.

I searched for a long time. I installed libs and other packages. But I didn't come up with a complete toolchain to use for Intel Atom development, like thos used by ARM or PowerPC.

Should I use the GNU toolchain as a cross tool with options -m32 etc? Would this be the way to go? Any thoughts are welcome!


Solution

  • 100% necessary no, should you yes. When you build a kernel, especially a 32 bit kernel on a 64 bit machine, without a cross compiler you are are using a gcc that isn't developed for your target architecture. This leads to compatibility issues. One of the big offender are things such as stddef.h, stdint.h and stdarg.h. This is architecture specific. To get around this you often see the -nostdinc flag passed when building a kernel without a cross compiler. This disables including the default headers such as stddef.h and leaves you the developer to create these. You can implement these but it is often tricky and if you get it wrong it will be difficult to debug. Another big issue that, I have experiences personally, is compiler releases will break your kernel build. Lets say you upgrade your machine to the next Linux distribution. There is now a decent chance that your kernel will not build because of the change in gcc. I experiences this when I upgraded from a gcc/ld that did not know about .eh_frames to one that did. This broke the linking step and required the linker script to be adjusted. If my group was using a cross compiler this would not have been an issue (on a side note this was the thing that caused us to switch to a cross compiler). There are many other reasons, some more opinion based then others. For more information you can check out the osdev page Why do I need a Cross Compiler?.

    Also a relatively simple 32 bit x86 toolchain to install is the one used by the yocto project. You can find instructions for installing it here. I prefer the approach titled "Using a Cross-Toolchain Tarball" and you can find the necessary downloads here. First select your host architecture (from your question most likely x86_64) and then select your target architecture (again from your question most likely poky-glibc-x86_64-core-image-sato-i586-toolchain-1.8.sh).