Social Icons

Monday, July 14, 2014


We have seen briefly about the Runtime code in my previous article. This article will give you a better understanding about the differences between the relocatable and executable files. Now look at the below screen shots:-
 => This is the relocatable object files main function.

Below is the main function of the executable file.

Now if you clearly observe the above images we can clearly understand that the relocatable object file has only offset addresses.(0: , 1: , 3: ,... ) where as the executable object file has load addresses like 80483e4: , 80483e5: ,........

This is called "Instruction Relocation". The linker decides where to load the above instructions in the executable file. The order in which it has to be loaded into the memory is only decided by the assembler. 

If we observe the above two images there are call instruction in both the object files but, in the relocatable object file its referring to some offset address 38<main+0x38> where as in the executable object file its referring to the load address directly 8048300 <printf@plt>. This functionality of the linker is called function relocation.
Now don't get confused about the tern plt. It's called procedure linkage table. We will talk briefly about it in my later articles.

We have also discussed about what is runtime. It's a compiled set of instruction which is appended by the linker in the executable file. This runtime code is responsible for initialization of the executable file. There are three important initialization functions which Linux provided us.
_init(), _start(), _fini().
The above functions need to be appended to the executable file in order to initialize the object code. Observe the below images. These are the functions which are used to initialize the executable image file.

  Without these functions appended into the executable file we cannot initialize the executable code. These functions are responsible for requesting the operating system for the memory to execute the program, more specifically these are the functions responsible for initializing the function stacks, calling the main function and termination of the program. As we move further we will learn more about these functions. We will write our own _init(), _start(), and _fini() functions and understand how it works.

No comments:

Post a Comment