The entire process of a program from source code to executable file

Programs are translated into different formats by other programs

Although the source file of the hello program can be read by people, in order for it to run on the system, each c statement must be converted into a series of low-level machine language instructions by other programs, and then these instructions are executed according to an executable target The format of the program is packaged and stored in the form of a binary disk file before it can be run in the system.
On Unix systems, the conversion from source files to object files is done by the compiler driver.

gcc -o hello hello.c

   
   
    
    
  • 1

This command will make the GCC compiler driver read the source program file hello.c and translate it into an executable object file hello. This translation process is divided into four stages:
translation process
1. Preprocessing stage: preprocessor ( cpp) According to the command starting with the character #, modify the original C program, such as the first line in the hello.c file #include<stdio.h> tells the preprocessor to read the content in the system header file stdio.h, so in At this stage, the preprocessor (cpp) will insert the contents of the header file into the hello.c program text to obtain another C program. Usually, the newly obtained C program has .i as the file extension. 2. Compilation stage: the compiler (ccl) translates the text file hello.i into a text file hello.s, which contains an assembly language program, that is, compiles the C language program into an assembly language program 3. Assembly stage: assembler (as) Translate hello.s into machine language instructions, then pack these instructions into a format called relocatable object program, and save the result in the object file hello.o, hello.o file is a binary file, its word Section encodings are machine language instructions (01) rather than characters. 4. Linking stage:






The hello program calls the printf function, which is a function in the standard C library provided by every C compiler. The printf function exists in a separate precompiled object file called printf. The understanding of the words is that the printf function is first implemented in a printf.c file, and then the target file printf.o is formed after preprocessing, compilation, and assembly. Maybe every function that is not implemented by yourself in your own program is An object file with a .o suffix, and then the linker (ld) combines all these object files in the linking stage, and finally realizes a complete program, an executable file , that can be loaded into memory and executed by the system.)

In-depth understanding of computer system notes:

  1. representation of information in a computer
  2. Representation and processing of information in computers
  3. The entire process of a program from source code to executable file
  4. The underlying principle of executable file operation
  5. How the operating system provides services to programs
  6. Telecommunication

Programs are translated into different formats by other programs

Although the source file of the hello program can be read by people, in order for it to run on the system, each c statement must be converted into a series of low-level machine language instructions by other programs, and then these instructions are executed according to an executable target The format of the program is packaged and stored in the form of a binary disk file before it can be run in the system.
On Unix systems, the conversion from source files to object files is done by the compiler driver.

gcc -o hello hello.c

   
   
  
  
  • 1

This command will make the GCC compiler driver read the source program file hello.c and translate it into an executable object file hello. This translation process is divided into four stages:
translation process
1. Preprocessing stage: preprocessor ( cpp) According to the command starting with the character #, modify the original C program, such as the first line in the hello.c file #include<stdio.h> tells the preprocessor to read the content in the system header file stdio.h, so in At this stage, the preprocessor (cpp) will insert the contents of the header file into the hello.c program text to obtain another C program. Usually, the newly obtained C program has .i as the file extension. 2. Compilation stage: the compiler (ccl) translates the text file hello.i into a text file hello.s, which contains an assembly language program, that is, compiles the C language program into an assembly language program 3. Assembly stage: assembler (as) Translate hello.s into machine language instructions, then pack these instructions into a format called relocatable object program, and save the result in the object file hello.o, hello.o file is a binary file, its word Section encodings are machine language instructions (01) rather than characters. 4. Linking stage:






The hello program calls the printf function, which is a function in the standard C library provided by every C compiler. The printf function exists in a separate precompiled object file called printf. The understanding of the words is that the printf function is first implemented in a printf.c file, and then the target file printf.o is formed after preprocessing, compilation, and assembly. Maybe every function that is not implemented by yourself in your own program is An object file with a .o suffix, and then the linker (ld) combines all these object files in the linking stage, and finally realizes a complete program, an executable file , that can be loaded into memory and executed by the system.)

In-depth understanding of computer system notes:

  1. representation of information in a computer
  2. Representation and processing of information in computers
  3. The entire process of a program from source code to executable file
  4. The underlying principle of executable file operation
  5. How the operating system provides services to programs
  6. Telecommunication

Guess you like

Origin blog.csdn.net/weixin_43743711/article/details/127159536