The role of Linux in the pretreatment program, compile, assemble, link, running steps

Create a hello.c file, follow the steps:

A precompiled <hello.i generated file>

Procedure: gcc -E hello.c -o hello.i

1. Delete all #define and expand all the macro definitions; 

2. The process of pre-compiled instructions for all, for example: # if, # elif, # else, # endif; 

3. The pre-compiler process #include command file will be included into the pre-compiled instructions inserted position; 

4. Add the line number information file name information to facilitate debugging; 

5. Delete all comments: // / ** /; 

6. Keep all #pragma compiler directives, as in the preparation of procedures, we often use the #pragma directive to set the status of the compiler or instructs the compiler to perform some specific action. 

.I file is generated.

Comprising (1) to Note (2) macro substitution (3) to expand the file header (4) conditional compilation
two, compiled (high-level language -> assembly language) <hello.s generated file>

Procedure: gcc -S hello.c -o hello.s   

Main functions: 1. Scanning (lexical analysis), 2 syntax analysis, a semantic analysis 3, 4 source code optimization (intermediate language generation), 5 code generation, code optimization target.....

Third, the assembler (assembly language -> binary file) <file generated hello.o>

Procedure: gcc -c hello.c -o hello.o

Main functions: assembler is converted into assembly code instructions may be executed to generate an object file.

Fourth, the link (to generate exe files)

Procedure: gcc hello.o -o hello

The main role: the linking process include: assigning addresses and space, symbol resolution and relocation.

And address space: the address assigned by the system and space for functions, variables.

Symbol resolution: it can be said address binding, static and dynamic linking sub-link,

Relocation: assuming that the document has two: A, B. A mov a function of the need to address B, the former is not linked to the address 0 is set, when the destination address modification A and B link to complete the relocation

6.3.5 Operating

Procedure: ./ hello

The main function: to run the program

Guess you like

Origin www.cnblogs.com/single-dont/p/11315980.html