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.
You typically don't want to mess the system's default GCC because other packages may depend on the default version. Depending on the speed of your computer the build phase could take from about 30 minutes to a few hours.
It was implemented in C++ but translated by what Stroustrup calls a "preprocessor" from C++ to C; not a full compiler by his definition, but still C++ was bootstrapped in C. The 3-step version of the bootstrap build process is indeed for verification: the compiler itself is used as its own test case.
G++ builds object code directly from your C++ program source. There is no intermediate C version of the program. (By contrast, for example, some other implementations use a program that generates a C program from your C++ source.)
Stage 2. and 3. are a good test for the compiler itself: If it 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
.
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