Upload
benedict-booth
View
230
Download
0
Embed Size (px)
Citation preview
Compilation process
Lecture-1
Compilation process
C Compilation process
Preprocessor
Compiler
Assember
Linker
Components of Compiler
Assembly code
Object code Libraries
Source code( .c file)
Executable file
Preprocessor
Preprocessor
/* this is demo */#include<stdio.h>void main(){ printf (“hello”);}
code of stdio.h filevoid main(){ printf (“hello”);}Preprocessor remove comments and include
header files in source code, replace macro name with code.
Compiler
Compiler
code of stdio.h filevoid main(){ printf (“hello”);}
push ebpmov ebp, espand esp, -16sub esp, 16mov eax, OFFSET FLAT:.LC0mov DWORD PTR [esp], eaxcall printfleaveret
Compiler generate assebmly code.
Assembler
Assembler
Assebler convert assemble code into object code.
push ebpmov ebp, espand esp, -16sub esp, 16mov eax, OFFSET FLAT:.LC0mov DWORD PTR [esp], eaxcall printfleaveret
001010011001010011010111101010010101010010101011010010101010100101010100110011111110010001010010101001010111110111111111111101000000001110010010
Linker
Linker
0010100110010100110101111010100101010100101010110
0010100110010100110101111010100101010100101010110
0010100110010100110101111010100101010100101010110
Libraries
Linker: Static linking
Linker
001010011001010011010111110
Libraries
001010011001010011010111110
Call function one()
#include<stdio.h>void main(){ one(); }
01010100000101001010
one()
01010100000101001010
Code of function one included in final executable file.
Linker: Static Linking
Linker
Object file1
Object file2
Libraries
Code of file 1 calling 200 funtions.Code of file 2 calling 100 functions.
Size ?
Linker:Static Linking exe file generated.1
User take exe file.2
Some changes made in one function.
3
Libraries010100
Again compilation needed so that exe file include updated one function.
4
Linker: Dynamic linking
Linker
001010011001010011010111110
Libraries
001010011001010011010111110Address of one function in memory
Call function one()
#include<stdio.h>void main(){ one(); }
01010100000101001010
one()
Memory address, where one function is loaded , included in final executable file.
Memory
0x2EA126One functionLibrary
Linker: Dynamic Linking Benefits over static linking
Size No need to compile
Library Static Library
Windows .lib (Library) Linux .a (Archive)
Dynamic Library Windows .dll (Dynamic link library) Linux .so (Shared object)
Commands Linux (gcc)
Preprocessor step ( gcc -E <filename>) Compiler step( gcc -S <filename>) Generate Object code(gcc -O <filename>) Generate executable (gcc <object code>)