0
votes

I intend to cross compile for Raspberry Pi, basically a small ARM computer. The host will be an i686 box running Arch Linux.

My first instinct is to use cross compiler provided by Arch Linux, arm-elf-gcc-base and arm-elf-binutils. However, every wiki and post I read seems to use some version of custom gcc build. They seem to spend significant time on cooking their own gcc. Problem is that they never say WHY it is important to use their gcc over another.

  1. Can stock distro provided cross compilers be used for building Raspberry Pi or ARM in general kernels and apps?

  2. Is it necessary to have multiple compilers for ARM architecture? If so, why, since single gcc can support all x86 variants?

  3. If 2), then how can I deduce what target subset is supported by a particular version of gcc?

  4. More general question, what general use cases call for custom gcc build?

Please be as technical as you can, I'd like to know WHY as well as how.

1
yes you can use a pre-built. download gcc or binutils sources then ./configure --help and look at the choices, if nothing else those are choices that can and do vary for a custom vs pre-built. the pre-built is just a custom using one persons preferences. also with a custom you can use specific versions of gcc, perhaps newer. also the pre-builts like codesourcery (now mentor) have improvements or changes to the source for various reasons (Addding or fixing support for a target core or operating system not in the stable source)old_timer
a sigle gcc can support all x68 variants is too vague of a statement, gcc 2.95 cannot support the features of a 2012 released x86 can it? Nope. For the same reason you can and will see custom gcc builds with various distros or applications within x86. If gcc were perfect, no bugs at all, and finished (all features supported, completed, bug free) then there wouldnt be any updates to gcc other than adding new processors right? I dont see development on gcc demonstrating that it is finished and bug free.old_timer
successfully building a gnu based cross compiler may give you something you can do some work with but not necessarily build all of the applications or drivers needed for a distro. If you dig inside gcc you will find an ugly beast held together with duct tape and bailing wire. It takes a fair amount of time to learn to tame that beast (only to have to start learning again each release).old_timer
@dwelch see this one about perfect compiler: en.wikipedia.org/wiki/Full_employment_theoremauselen
just get the (formerly) codesourcery (now mentor graphics) lite toolchain. or use buildroot to make one and use that until your project is done or it fails then worry about how to fix your toolchain. both of those groups of people have experience and spend time worrying about the toolchain build so you dont have to. solve one problem at a time (making applications or making a toolchain).old_timer

1 Answers

2
votes

When developers talk about building software (cross compiling) for a different machine (target) compared to their own (host) they use the term toolchain to describe the set of tools necessary to build binary files. That's because when you need to build an executable binary, you need more than a compiler.

You need routines (crt0.o) to initialize runtime according to requirements of operating system and standard libraries. You need standard set of libraries and those libraries need to be aware of the kernel on target because of the system calls API and several os level configurations (f.e. page size) and data structures (f.e. time structures).

On the hardware side, there are different set of ARM architectures. Architectures can be backward compatible but a toolchain by nature is binary and targeted for a specific architecture. You can have the most widespread architecture by default but then that won't be too fruitful for an already constraint environment (embedded device). If you have the latest architecture, then it won't be useful for older architecture based targets.

When you build a binary on your host for your host, compiler can look up all the necessary bits from its own environment or use what's on the host - so most of the above details are invisible to developer. However when you build for a different target than your host type, toolchain must know about hardware, os and standard library details. The way you tell these to toolchain is... by building it according to those details which might require some level of bootstrapping. (or you can do this via extensive set of parameters if toolchain supports / built for it.)

So when there is a generic (stock) cross compile toolchain, it has already some target specifics set and that might not meet your requirements. Please see this recent question about the situation on Ubuntu for an example.