Question

I just had one of the "wait what, mmm ... " moments.

Assuming that you want to produce the compiler A for the targeted architecture a usually the outcome of the configuration phase depends on the value that you use for --target=, meaning that your tools need to be able to produce and deal with compiled objects for a.

Now, usually under a common GNU/Linux distribution with gcc as the main compiler the first thing that you want is to get the binutils and build them for your target, but you don't have a compiler that is compatible with your given target because that's what you are trying to do in the first place, creating a toolchain for a, so here starts the conundrum: how to break this loop ?

Now assuming that my previous example was taking into account and running on a machine with an architecture b, clearly different from a because we are always talking about the cross compilation case, you get lucky and the hardware manufacturer releases gcc for a on machines with the a architecture, you still have to solve the riddle on how to build a on b and break the previous loop. In other words even if you get support for your compiler on the original architecture this doesn't play any role when you want to cross compile.

So what's the logic behind this and how to break the loop ?

Was it helpful?

Solution

The "gcc" compiler is also "self-hosting". So, you usually build a "stage1" compiler on the non-target platform and then move to the target system and re-build the compiler with the "stage1" (running through "stage3").

You first need to understand the "Target Triplets" (you listed one "--target"), but you also have "--host" and "--build". From the link,

--build=build-type

the type of system on which the package is being configured and compiled. It defaults to the result of running config.guess.

--host=host-type

the type of system on which the package runs. By default it is the same as the build machine. Specifying it enables the cross-compilation mode.

--target=target-type

the type of system for which any compiler tools in the package produce code (rarely needed). By default, it is the same as host.

See also, Cross Linux From Scratch and the astonishing work at NetBSD.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top