问题
I currently try to understand how cross-compilers work. I'm a bit confused about the two-staged compiler compilation process.
As far as I read, the following procedure is applied:
- Compile bintutils for the target architecture
- Compile GCC (stage 1)
- Compile newlib/eglibc/... with GCC
- Compile GCC with the libc (stage 2)
Why is there a second stage involved? Couldn't I just invoke the first stage compiler with some flag like -lc
to include libc?
回答1:
I'm not sure why gcc has such a complicated build process. My clang/LLVM based ELLCC (http://ellcc.org) cross tool chain project builds like this:
- Compile the compiler (using either gcc or a pre-built version of the ELLCC compiler available from the web site.).
- Use the compiler to build the C++ and C libraries for all targets.
- Build binutils and gdb for all targets (for all targets: don't make target specific utilitities except for the assemblers. ld, gdb, objdump, etc. all support this)
- (optional) Use your newly built compiler to cross build itself for all the targets.
BTW, ELLCC currently supports ARM, Microblaze, Mips, PowerPC, and x86 targets for Linux and bare metal execution environments.
来源:https://stackoverflow.com/questions/27457835/why-do-cross-compilers-have-a-two-stage-compilation