Download presentation
Presentation is loading. Please wait.
Published byKathryn Sparks Modified over 8 years ago
1
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
2
Memory Relocation Concept
3
Example Suppose we have variable x in program P Compiler allocates fixed address to x (This allocation of address by the compiler is called binding) P will execute only when x could be put in its allocated memory location.
4
What happens when memory location allocated to x is not available ?
5
Variable can be assigned a location relative to an assumed origin(or first address in program P)
6
Multistep Processing Of A User Program
7
Types of Addressess Symbolic addresses – Can have these in program language code and in Object Modules – Translated to relocatable or absolute addresses through linking Relocatable addresses – Can be bound to specific addresses, after compile time By a dynamic linking process – Addresses generated relative to part of program, not to start of physical memory (e.g., 0 is first byte of program) Absolute (physical) addresses – Specific addresses in memory, relative to 0 at start of memory. – Eventually all program addresses must resolve to absolute addresses
8
Address Binding Definition – Converting the (relative or symbolic) address used in a program to an actual physical (absolute) address Address binding time – During compilation But, often don’t know where program will be loaded when it is compiled (or assembled) – During load time In order for a program to be initially loaded, decisions must be made about where it will execute in computer memory, so at least initial specific addresses must be bound – During execution We may want to move a program, during execution, from one region of memory to another
9
BINDING Early binding Dynamic Binding
10
Example of Early Binding Add(int x, int y) { return x+y; } Add(int x,int y, int z) { return x+y+z;} main() { Add (2,3); }
11
Example of Dynamic Binding Class Base{ public: virtual void show() {cout<<“I am a Base”;} }; Class Derv1: public Base{ public: void show() {cout<<“I am a Derv1”;} }; Class Derv2: public Base{ public: void show() {cout<<“I am a Derv2”;} };
12
main( ) { Derv1 dv1; Derv2 dv2; Base *ptr; ptr = &dv1; ptr->show();// it will call show() of Derv1 ptr = &dv2; ptr->show(); // it will call show() of Derv2 return 0; }
13
Contents Dynamic Linking Definition Types of Linking Implementation example Why Dynamic Linking?
14
What happens to your program … …after it is compiled, but before it can be run?
15
Linking Linking : Copying together a main program with the routines it uses, update the symbol table. Final stage of Compilation. Executable File Combines Object Files Or Libraries In doing so, it resolves: assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation ). The linker actually enables separate compilation.
16
Object files Linking Process
17
The steps from source......to executing image Compile a.c and get a.o Link several.o into.so/.dll, or into an executable. Load & run the executable. Load.so/.dll libraries when needed.SourceProgram Other object (.o) modules SourceProgram System library.so.dll SourceProgram Dymically Loaded system Load Time Execution Time In-memoryBinaryimage Link editor Loader SourceProgram Loadmodule SourceProgram SourceProgram.c Compile Time Compiler or Assembler SourceProgram Object module.o
18
Different Type of Libraries Libraries – Collection of sub-programs Images of library function is copied into executable file o Two types of libraries: Static Libraries Shared Libraries
20
Static Linking Performed before program execution. Carried out only once to produce an executable file. If static libraries are called, the linker will copy all the modules referenced by the program to the executable.
21
Dynamic Linking Allows a process to add, remove, replace or relocate object modules during its execution. If shared libraries are called, 1.Only copy a little reference information when the executable file is created. 2.Completing the linking during loading time or running time.
22
Dynamic Linking.. Dynamically Linked ??? i.e. binding between program & shared object is done at runtime Program Libraries Refers Not combined together by linker at link time Linker Executable - - - - - - - - - - - - - - - - - - - - - - - - - - - Loader Places info. Tells about shared object module
23
Implementation Example Load the called subroutine into memory Issue a load-and-call service request
24
Called subroutine this time is already loaded. Control is passed to the loaded subroutine. Control is returned to loader & later returned to the user program
25
A Big Difference If several processes call the same object module of a shared library simultaneously, Only one copy in memory (dynamic) Several copies each for a process in memory (static)
26
Which one is better, static or dynamic? Construct some programs of different size linked in both versions to compare: – Executable size – Loading time – Running time – System call – Memory usage
27
Why Dynamic linking? Drawback of Static Linking: The executable is quite big in size because all the needed to be brought together. Advantages of Dynamic Linking: Easier to create Easier to update Routines can be loaded / unloaded at runtime Save both Memory & Disk Space
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.