Everything I've read seems to imply that building a cross-compiler is significantly harder than building a compiler that targets the platform it runs on. Is this true? If so, why? It seems like generating assembly code and system calls for an arbitrary platform shouldn't be any harder than generating such code and system calls for the platform the compiler is running on, but maybe I'm just being naive.
This doesn't have to be harder, but it can be depending on the compiler architecture.
A compiler is not only translating source code into asm and system calls. It's also integrating pre-existing helper code into the generated files. This is code includes startup code, functions preamble, part of the C api that can be inlined, etc.
In a normal compiler C1 for platform A built on platform A, the original compiler C0 can build C1 and its helper code (for A, since C0 targets A) directly.
In a cross compiler C2 for platform B built on platform A, the original compiler C0 must first build a special version of C2 which doesn't need the helper code (because the helper code is for B, while C0 targets A), then it must run C2 to generate the helper code. Depending on the compiler, it may then have to generate a second version of C2 that includes the helper code.
The act of building the limited version of C2, without helper code is the bootstrapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With