Chapter 3 Loaders and Linkers

Slides:



Advertisements
Similar presentations
Loaders Dr. Monther Aldwairi 10/21/2007 Dr. Monther Aldwairi.
Advertisements

1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
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.
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida.
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
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.
Machine Independent Assembler Features
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++
Loaders and Linkers Object Program contains the information:
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Memory Management Chapter 7.
Machine-Independent Loader Features
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Chapter 6: Machine dependent Assembler Features
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
CS2422 Assembly Language & System Programming January 2, 2007.
Loader- Machine Independent Loader Features
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
Loader- Machine Dependent Loader Features
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
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.
Chapter 1 Computer architecture Languages: machine, assembly, high
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
PART I SISTEM UTILITIES LECTURE 4.1 LINK_LOAD Ştefan Stăncescu 1.
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.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Loader and Linker.
CSc 453 Linking and Loading
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
UNIT III LOADERS AND LINKERS. This Unit gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Feature Loader.
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.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
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.
Lecture 3 Translation.
Machine dependent Assembler Features
System Programming and administration
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Assembler Design Options
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Loaders and Linkers.
Memory Management Tasks
Optional Assembler Features 2
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Machine Independent Assembler Features
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

Chapter 3 Loaders and Linkers System Software Chih-Shun Hsu

Introduction Loading: brings the object program into memory for execution Relocation: modifies the object program so that it can be loaded at an address different from the location originally specified Linking: combines two or more separate object programs and supplies the information needed to allow references between them A loader is a system program that performs the loading function

Basic Loader Functions Bringing an object program into memory and starting its execution Absolute loader: The Header record is checked to verify that the correct program has been presented for loading As each Text record is read, the object code it contains is moved to the indicated address in memory When the End record is encountered, the loader jumps to the specified address to begin execution Bootstrap loader: loads the first program to be run by the computer—usually an operating system

Loading of an Absolute Program

Algorithm for an Absolute Loader

Bootstrap Loader for SIC/XE(2/1)

Bootstrap Loader for SIC/XE(2/2)

Machine-Dependent Loader Features Relocation Program linking Linking loader

Relocation Loaders that allow for program relocation are called relocating loaders or relative loader The Text records are the same as before except that is a relocation bit associated with each word of object code If the relocation bit corresponding to a word of object code is set 1, the program’s starting address is to be added to this word when the program is relocated A bit value of 0 indicates that no modification is necessary

Example of a SIC/XE Program

Object Program with Relocation by Modification Records

Relocatable Program for a Standard SIC Machine(2/1)

Relocatable Program for a Standard SIC Machine(2/2)

Object Program with Relocation by bit Mask

Linking and Relocation(3/1)

Linking and Relocation(3/2)

Linking and Loading(3/3)

Object Programs(3/1)

Object Programs(3/2)

Object Programs(3/3)

After Linking and Loading

Relocation and Linking Operations Performed on REF4 from PROGA

Linking Loader(4/1) The required linking operation cannot be performed until an address is assigned to the external symbol involved, thus a linking loader usually makes two passes over its input Two passes linking loader Pass 1 assigns addresses to all external symbols Pass 2 performs the actual loading, relocation, and linking The main data structure needed for our linking loader is an external symbol table ESTAB A hashed organization is typically used for this table

External Symbol Table (ESTAB)

Linking Loader(4/2) Two important variables are PROGADDR (program load address) and CSADDR (control section address) PROGADDR is the beginning address in memory where the linked program is to be loaded Its value is supplied to the loader by the operating system CSADDR contains the starting address assigned to the control section currently being scanned by the loader

Linking Loader(4/3) The last step performed by the loader is usually the transferring of control to the loaded program to begin execution The End record for each control section may contain the address of the first instruction in that control section to be executed If more than one control section specifies a transfer address, the loader arbitrarily uses the last one encountered If no control section contains transfer address, the loader uses the beginning of the linked program as the transfer point

Linking Loader(4/4) Assign a reference number to each external symbol referred to in a control section to make the algorithm more efficient The main advantage of this reference-number mechanism is that it avoids multiple searches of ESTAB for the same symbol An external reference symbol can be looked up in ESTAB once for each control section that uses it The values for code modification can then be obtained by simply indexing into an array of these values

Algorithm for Pass 1 of a Linking Loader

Algorithm for Pass 2 of a Linking Loader

Object Programs using Reference numbers for Code Modification(3/1)

Object Programs using Reference numbers for Code Modification(3/2)

Object Programs using Reference numbers for Code Modification(3/3)

Automatic Library Search The subroutines called by the program being loaded are automatically fetched from the library, linked with the main program, and loaded Linking loader that support automatic library search must keep track of external symbols that are referred to, but not defined, in the primary input to the loader The loader searches the libraries specified for routines that contain the definitions of these symbols, and processes the subroutines found by this search exactly as if they had been part of the primary stream Allows the programmer to override the standard subroutines in the library by supplying his or her own routines

Loader Options(2/1) INCLUDE program-name (library-name): direct the loader to read the designated object program from a library and treat it as if it were part of the primary loader input DELETE csect-name: instruct the loader to delete the named control section(s) from the set of programs being loaded CHANGE name1, name2: cause the external symbol name1 to be changed to name2 wherever it appears in the object programs INCLUDE READ(UTLIB) INCLUDE WRITE(UTLIB) DELETE RDREC, WRREC CHANGE RDREC, READ CHANGE WRREC, WRITE

Loader Options(2/2) LIBRARY MYLIB: allow the user to specify alternative libraries to be searched NOCALL STDDEV, PLOT, CORREL: instruct the loader that these external references are to remain unresolved This avoids the overhead of loading and linking the unneeded routines, and saves memory space Other options: specify the location at which execution is begin, control whether or not the loader should attempt to execute the program if errors are detected during the load

Linkage Editors(3/1) A linking loader performs all linking and relocation operations, including automatic library search if specified, and loads the linked program directly into memory for execution A linkage editor produces a linked version of the program ( often called a load module or an executable image), which is written to a file or library for later execution

Linking Loader vs. Linkage Editor

Linkage Editor(3/2) If a program is to be executed many times without being reassembled, the use of a linkage editor substantially reduces the overhead required If a program is reassembled for nearly every execution (e.g. program development and testing), it is more efficient to use a linking loader The linked program produced by the linkage editor is generally in a form that is suitable for processing by a relocating loader (all external references are resolved, and relocation is indicated by some mechanism)

Linkage Editor(3/3) A subroutine (PROJECT) used by the program (PLANNER) is changed to correct an error or to improve efficiency INCLUDE PLANNER(PROGLIB) DELETE PROJECT INCLUDE PROJECT(NEWLIB) REPLACE PLANNER(PROGLIB) Linkage editors can be used to build packages of subroutines or other control sections that are generally used together Compared to linking loaders, linkage editor in general tend to offer more flexibility and control, with a corresponding increase in complexity and overhead

Dynamic Linking Dynamic linking: a subroutine is loaded and linked to the rest of the program when it is first called Dynamic linking is often used to allow several executing programs to share one copy of a subroutine or library Dynamic linking provides the ability to load the routines only when they are needed When dynamic linking is used, the binding of the name to an actual address is delayed from load time until execution time

Example of Dynamic Linking(2/1)

Example of Dynamic Linking(2/2)

Bootstrap Loaders Have a built-in hardware function that reads a fixed-length record from some device into memory at a fixed location This record contains machine instructions that load the absolute program that follows If the loading process requires more instructions than can be read in a single record, this first causes the reading of others, and these can cause the reading of still more records—hence the term bootstrap The first record is generally referred as a bootstrap loader Such a loader is added to the beginning of all object programs that are to be loaded into an empty system

MS-DOS Linker MS-DOS LINK is a linkage editor that combines one or more object modules to produce a complete executable program This executable program has the file name extension .EXE LINK can combine the translated programs with other modules from object code libraries LINK performs its processing in two passes Pass 1 computes a starting address for each segment in the program During Pass 2, LINK extracts the translated instructions and data from the object module, and builds an image of the executable program in memory After the memory image is complete, LINK writes it to the executable (.EXE) file

MS-DOS Object Module

SunOS Linkers(3/1) SunOS actually provides two different linkers, called the link-editor and the run-time linker The link-editor takes one or more object modules produced by assemblers and compilers, and combines them to produce a single output module Different types of output modules: relocatable object module, static executable, dynamic executable, shared object The object module includes a list of the relocation and linking operations that need to be performed

SunOS Linkers(3/2) Symbolic references from the input files that do not have matching definitions are processed by referring to archives and shared objects An archive is a collection of relocatable object modules Selected modules from an archive are automatically included to resolve symbolic references A shared object is an indivisible unit that was generated by a previous link-edit operation

SunOS Linkers(3/3) The SunOS run-time linker is used to bind dynamic executable and shared objects at execution time When a procedure is called for the first time, control is passed via the linkage table to the run-time linker The linker looks up the actual address of the called procedure and inserts it into the linkage table, thus subsequent calls will go directly to the called procedure This process is sometimes referred to as lazy binding During execution, a program can dynamically bind to new shared objects depending on the exact services required