Issue
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.
Solution
Stage 2. and 3. are a good test for the compiler itself: If it can compile itself (and usually also some libraries like
libgcc
andlibstdc++-v3
) then it can chew non-trivial projects.In stage 2. and 3., you can generate the compiler with different options, for example without optimization (
-O0
) or with optimization turned 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 the same binary for the same source file, even though the two compilers 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
.
Answered By - emacs drives me nuts Answer Checked By - Pedro (WPSolving Volunteer)