Information About The Compiler Toolchain

 A compiler is one component in a toolchain of programs used to create executables from source code. Typically, when you invoke a single command to compile the program, a whole sequence of programs is invoked in the background. the programs typically used in a Unix system for compiling C source code to assembly code.


by clicking the diagram the names will be clearly visible.

• The preprocessor prepares the source code for the compiler properly. In the C and C++ languages, this means consuming all directives that start with the # symbol. For example, an #include directive causes the preprocessor to open the named file and insert its contents into the source code. 
A # define directive causes the preprocessor to substitute a value wherever a macro name is encountered. (Not all languages rely on a preprocessor.)

 • The compiler properly consumes the clean output of the preprocessor. It scans and parses the source code, performs type-checking another semantic routine, optimizes the code, and then produces assembly language as the output.

 • The assembler consumes the assembly code and produces object code. Object code is “almost executable” in that it contains raw machine language instructions in the form needed by the CPU. However, object code does not know the final memory addresses in which it will be loaded, and so it contains gaps that must be filled in by the linker.

 • The linker consumes one or more object files and library files and combines them into a complete, executable program. It selects the final memory locations where each piece of code and data will be loaded, and then “links” them together by writing in the missing address information. 

For example, an object file that calls the printf function does not initially know the address of the function. An empty (zero) address will be left where the address must be used. Once the linker selects the memory location of printf, it must go back and write in the address at every place where printf is called. 

In Unix-like operating systems, the preprocessor, compiler, assembler, and linker are historically named cpp, cc1, as, and ld respectively. The user-visible program cc simply invokes each element of the toolchain in order to produce the final executable.


Post a Comment

Previous Post Next Post