LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language.

Slides:



Advertisements
Similar presentations
Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Advertisements

Loaders & Linkers. Introduction A “Loader” is a program which accepts the object program as input, makes them executable by the computer and initiates.
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
FIT1001- Computer Systems Lecture 12 Introduction to System Software.
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
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.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Machine Independent Assembler Features
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.
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++
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
Memory Management Chapter 7.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Programming Types of Testing.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Loader- Machine Independent Loader Features
CS2422 Assembly Language & System Programming December 22, 2005.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
An introduction to systems programming
A. Frank - P. Weisberg Operating Systems Real Memory Management.
CS2422 Assembly Language & System Programming December 14, 2006.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
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:
INTRODUCTION TO PROGRAMMING, ALGORITHMS & FLOWCHARTS Programming in C2 CHAPTER 1.
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
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.
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Memory Management. Introduction To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes.
Loader and Linker.
Question What technology differentiates the different stages a computer had gone through from generation 1 to present?
– S YSTEM S OFTWARE U NIT 5 - L INKERS AND L OADERS Compiled By: Navtej Bhatt PIET-MCA.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
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.
Linkers.
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers.
Chapter Linkers and Loaders
Lecture 3 Translation.
Machine dependent Assembler Features
Memory management.
System Programming and administration
Assembler Design Options
Chapter 7 LC-2 Assembly Language.
Loaders and Linkers: Features
Machine Independent Features
CSCE Fall 2013 Prof. Jennifer L. Welch.
Memory Management Tasks
Computer Organization and Design Assembly & Compilation
The Assembly Language Level
A Simple Two-Pass Assembler
CSCE Fall 2012 Prof. Jennifer L. Welch.
Machine Independent Assembler Features
Machine Independent Assembler Features
An introduction to systems programming
Program Assembly.
Presentation transcript:

LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language L. 2.Linking of the program with other programs needed for its execution 3.Relocation of the program to execute from the specific memory area allocated to it: Steps 2 and 3 are performed by the linker. 4.Loading of the program in the memory for the purpose of execution. Step 4 is performed by the loader. The translator outputs a program form called object module for the program. The linker processes a set of object modules to produce a ready-to-execute program form, which we will call a binary program. The loader loads this program into the memory for the purpose of execution. The object modules and ready-to-execute program forms can be stored in the form of files for repeated use. TranslatorLinkerLoaderBinary Program Source Program Object Modules Binary Programs Data Results Data flow Control flow A schematic of program execution

Translated, Linked and load time address: Translated origin: While compiling a program P, a translator is given an origin specification for P which is called the Translated origin of P. The translator uses the value of the translated origin to perform memory allocation for the symbols declared in P. This results in the assignment of a translation time address t synb to each symbol symb in the program. The execution start address or simply the start address of a program is the address of the instruction from which its execution must begin. The start address specified by the translator is the translated start address of the program. The origin of a program has to be changed for the following reasons: 1.The same set of translated addresses may have been used in different object modules constituting a program. Memory allocation to such programs would conflict unless their origins are changed. 2.An OS may require that a program should execute from a specific area of memory. 1.Translation time (or translated) address: Address assigned by the translator. 2.Linked address: Address assigned by the linker. 3.Load time (or load) address: Address assigned by the loader.

We also have the following terminologies: 1.Translated origin: Address of the origin assumed by the translator. This is the address specified by the programmer in an ORIGIN statement. 2.Linked origin: Address of the origin assigned by the linker while producing a binary program. 3.Load origin: Address of the origin assigned by the loader while loading while loading the program for execution. The linked and load origins may differ from the translated origin of a program. RELOCATION AND LINKING CONCEPTS: Program Relocation: Program relocation is the process of modifying the addresses used in the address sensitive instructions of a program such that the program can execute correctly from the designated area of memory. If the linked origin <> linked origin, relocation must be performed by the linker. If load origin <> linked origin, relocation must be performed by the loader. In general, a linker always performs relocation, whereas some loaders do not. For simplicity we assume that loaders do not perform relocation i.e. load origin = linked origin. Such loaders are called absolute loaders. Hence load origin and linked origin will be used interchangeably. However, it would have been more precise to use the term ‘linked origin’. (Loaders that perform relocation are called relocating loaders.)

Performing relocation: Let the translated and linked origins of program P be t_origin P and l_origin P, respectively. Consider a symbol symb in P.Let its translation time address be t symb and link time address be l symb.The relocation factor of P is defined as: relocation_factor P = l_origin P - t_origin P (1) Note that relocation_factor P can be positive, negative or zero. Consider a statement which uses symb as an operand. The translator puts the address t symb in the instruction generated for it. Now, t symb = t_origin P + d symb where d symb is the offset of symb in P. Hence l symb = l_origin P + d symb Using (1), l symb = t_origin P + relocation_factor P + d symb = t_origin P + d symb + relocation_factor P = t symb + relocation_factor P Let IRR P designate the set of instructions requiring relocation in program P. Following (2), relocation of program P can be performed by computing the relocation factor for P and adding it to the translation time address(es) in every instruction i belongs to IRR P.

START500 ENTRYTOTAL EXTRNMAX, ALPHA READA LOOP500) MOVERAREG, ALPHA518) BCANY, MAX519) BCLT, LOOP538) STOP539) ADS1540) TOTALDS1541) END A sample assembly program and its generated code.

START200 ENTRYALPHA ---- ALPHADS25231) END Program unit Q. Let the program unit of the above two programs

Linking: An Application Program (AP) consists of many SP = {Pi}. A program unit Pi interacts with another program unit Pj by using addresses of Pj’s instructions and data in its own instructions. To realize such interactions, Pj and Pi must contain public definitions and external references as defined: Public definitions :a symbol pub_symb defined in a program unit which may be referenced in other program units External reference :a reference to a symbol ext_symb which is not defined in the program unit containing the reference. The ENTRY statement lists the public definitions of a PU,i.e. it lists those symbols defined in the program unit which may be referenced in other PUs. The EXTRN statement lists the symbols to which external references are made in the program unit.

Resolving external references: Before the AP can be executed, it is necessary that for each Pi in SP, every external reference in Pi should be bound to the correct link time address. Linking: It is the process of binding an external reference to the correct link time address. Unresolved – until linking is performed. Resolved – after linking is performed. Binary Programs: A Binary Program is a machine language program comprising a set of program units SP such that  Pi  SP. 1.Pi has been relocated to the memory area starting at its link origin. 2.Linking has been performed for each external reference in Pi.

Object Module: The object module of a program contain all information necessary to relocate and link the program with other programs. The object module of a program P consists of 4 components: 1.Header:Translated origin, size and execution start address of P. 2.Program: It contains the machine language program corresponding to P. 3.Relocation Table: Translated address i.e. translated address of an address sensitive instruction. 4.Linking Table(LINKTAB): It has three fields. 1.Symbol:Symbolic name 2.Type:PD/EXT indicating whether public definition or external reference. 3.Translated address: For a public definition, this is the address of the first memory word allocated to the symbol. For an external reference, it is the address of the memory word which is required to contain the address of the symbol.

SELF - RELOCATING PROGRAMS: 1.Non-relocatable programs: This cannot be executed in any memory other than the area starting on its translated origin. Eg. a hand coded machine language program 2.Relocatable programs: It can be processed to relocate to a desired area of memory. For e.g. an object module. 3.Self-relocatable programs: It performs the relocation of its own address sensitive instructions. It contains the following two provisions for this purpose: 1.A table of information concerning the address sensitive instructions exists as a part of the program. 2.Code to perform the relocation of address sensitive instructions also exists as a part of the program. This is called the relocating logic.

LINKING FOR OVERLAYS: Overlay: An overlay is a part of a program (or software package) which has the same load origin as some other part(s) of the program. Overlays are used to reduce the main memory requirement of the program. Overlay structured Program: A program containing overlays is an overlay structured program. It consists of: 1.A permanently resident portion called the root. 2.A set of overlays. Eg. Consider a program with 6 sections named init, read, trans_a, trans_b, trans_c and write. init performs some initializations and passes control to read. read reads one set of data and invokes one of trans_a, trans_b or trans_c depending on the values of the data. write is called to print/write results.