Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is building a cross-compiler harder than building a regular compiler?

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.

like image 376
dsimcha Avatar asked Feb 17 '09 17:02

dsimcha


1 Answers

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.

like image 100
Doub Avatar answered Oct 20 '22 23:10

Doub