Why does GCC compile itself 3 times?

ng.newbie :

I have compiled GCC from source but I can't seem to fully understand the utility of gcc compiling itself three times.

What benefit does this serve ?

This answer says:

  • Build new version of GCC with existing C compiler
  • re-build new version of GCC with the one you just built
  • (optional) repeat step 2 for verification purposes.

Now my question is that once the first step is complete and the compiler is built why waste time rebuilding it ?

Is it just for verification ? If so, it seems pretty wasteful.

Things get more complicated over here,

The build for this is more complex than for prior packages, because you’re sending more information into the configure script and the make targets aren’t standard.

I mean the whole compiler is written in C right, so why not just do everything in one pass ?

What is the use of the 3-phase bootstrap ?

Thanks in advance.

emacs drives me nuts :
  • Stage 2. and 3. are a good test for the compiler itself: It is can compile itself (and usually also some libraries like libgcc and libstdc++-v3) then it can chew non-trivial projects.

  • In stage 2. and 3., you can generate the compiler different options, for example without optimization (-O0) or with optimization on (-O2). As the output / side effects of a program should not depend on the optimization level used, either version of the compiler must produce same binaries, even though they are binary very different. This is yet another (run-time test) for the compiler.

If you prefer non-bootstrap for some reason, configure --disable-bootstrap.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=28179&siteId=1