Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Part IV: Memory Management
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
Linking & Loading CS-502 Operating Systems
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
Memory Management Chapter 7.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Loader- Machine Independent Loader Features
A. Frank - P. Weisberg Operating Systems Real Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
MIPS coding. SPIM Some links can be found such as:
© 2004, D. J. Foreman 1 Memory Management. © 2004, D. J. Foreman 2 Building a Module -1  Compiler ■ generates references for function addresses may be.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Chapter 4 Storage Management (Memory Management).
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
CSc 453 Linking and Loading
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Lecture 3 Translation.
Computer Architecture & Operations I
Memory management.
The University of Adelaide, School of Computer Science
Linking & Loading.
Memory Management © 2004, D. J. Foreman.
Chapter 8 Main Memory.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Program Execution in Linux
CS-3013 Operating Systems C-term 2008
Loaders and Linkers: Features
Machine Independent Features
Multistep Processing of a User Program
Memory Management Tasks
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Computer Organization and Design Assembly & Compilation
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
Program Execution in Linux
Linking & Loading CS-502 Operating Systems
point when a program element is bound to a characteristic or property
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Presentation transcript:

Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)

Memory Relocation Concept

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.

What happens when memory location allocated to x is not available ?

Variable can be assigned a location relative to an assumed origin(or first address in program P)

Multistep Processing Of A User Program

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

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

BINDING Early binding Dynamic Binding

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); }

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”;} };

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; }

Contents Dynamic Linking Definition Types of Linking Implementation example Why Dynamic Linking?

What happens to your program … …after it is compiled, but before it can be run?

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.

Object files Linking Process

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

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

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.

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.

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

Implementation Example Load the called subroutine into memory Issue a load-and-call service request

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

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)

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

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