Compiler, Obect Code / Relocatable Code, Linker

When we compile a C source file using GNU C compiler, it compiles our code into an assembly source. Then, the assembly source is assembled by the assembler (included with gcc (GNU C compiler)). It generates the object code (relocatable format machine code), and it is usually not directly executable. Next, the linker links libraries. Libraries are also in relocatable format, this is why we compile libraries with -shared / -fpic / -fPIC flags.

The linking process checks the library name that we included in the source file and it also checks whether the library is available in the system's default library path /usr/lib (GNU/Linux) if not, we can pass the specific libraries as an argument to gcc with -I flag (gcc -I/home/shuja/Documents/libmy.so ) 

finally, the linker links our sources(object codes) with libraries and generates the executable.
C Source File
 Assembly Source (generated  by GNU C compiler)
Disassembled object code (Disassembled because object code isn't human readable)
test.c - C source, test.s - assembly source, test.o - object code, exic - exicutable, test.bin - flat binary file
System default library path /usr/lib (GNU Linux)

Comments

Popular posts from this blog

Connect Huawei Modem Linux - USB Modeswitch

Department for Persons Registration of Sri Lanka

Java Byte Code, Interpreter and JIT