Description
Information for Interested Students
There are generally considered 4 phases to GCC compilation for C programs in Linux
- Pre-Processing
- Compilation
- Assembly [Shown in Class]
- Linking
The pre-processing
stage the text file that you have written is pre-processed to strip unnecessary information such as comments. It also processes any include statements etc.
The compilation
stage converts the output of pre-processing and is responsible for converting it to an assembly layer. In this process the compiler is responsible for doing a lot of work and perform various optimizations in generating the assembly code
The assembly
stage converts the assembly into object level code.
The linking
stage manages the linking requirements to external calls such as printf
.
You can actually see these steps using -save-temps
option during compilation.
gcc -Wall -save-temps print.c -o print
There is a lot more to it under the surface - but this gives you a sense of the compilation process.
If you are really keen then here is some interesting reading: