The compilation process of GCC mainly includes four stages: preprocessing, compilation, assembly, and linking. During this process, three tools are used: cc1, as, and collect2. Among them, cc1 is the compiler corresponding to the first and second stages, used to compile the source file hello.c into hello.s; as is the assembler corresponding to the third stage, used to assemble hello.s into the object file hello.o; the linker collect2 is a wrapper for the ld command, used to link the object files from the C runtime library (CRT) (crt1.o, crti.o, crtbegin.o, crtend.o, crtn.o) and the required dynamic link libraries (libgcc.so, libgcc_s.so, libc.so) into the executable hello.


The second stage of GCC compilation is the compilation stage, which performs a series of lexical analysis, syntax analysis, semantic analysis, and optimization on the preprocessed file, ultimately generating assembly code. By adding the compilation option “-S” in the command, the target can be either the source code hello.c or the preprocessed file hello.i. In fact, in the implementation of GCC, preprocessing and compilation have been combined.
GCC defaults to using AT&T syntax for assembly language; adding the compilation option “-masm=intel” can specify it to the familiar Intel format. The compilation option “-fno-asynchronous-unwind-tables” is used to generate assembly instructions without CFI macros to improve readability.