Sunteți pe pagina 1din 25

Loaders and Linkers

Submitted to:
Ramakrishna
Asst. Prof.

Submitted by:
A. Sonu Devi
Ayush Upadhyay
Dipti Rani
Lincoln

Content

Introduction
Basic Loader Functions
Design of an Absolute Loader
Algorithm for an Absolute Loader
A Simple Bootstrap Loader
Machine-Dependent Loader Features
Relocating Loaders
Modification Record
Relocation Bit
Program Linking
Linking Loader
Algorithm and Data structures of a Linking Loader

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 computerusually an operating
system

Design of an Absolute Loader

Absolute Program
Advantage

Simple and efficient

Disadvantage

the need for programmer to specify the actual


address
difficult to use subroutine libraries

Program Logic

Algorithm for an Absolute Loader

A Simple Bootstrap Loader

Bootstrap Loader

When a computer is first tuned on or restarted, a special type of


absolute loader, called bootstrap loader is executed
This bootstrap loads the first program to be run by the computer
-- usually an operating system

Example (SIC bootstrap loader)

The bootstrap itself begins at address 0

It loads the OS starting address 0x80

No header record or control information, the object code is


consecutive bytes of memory

Machine-Dependent Loader
Features
Relocation
Program linking
Linking loader

Relocating Loaders

Motivation

efficient sharing of the machine with larger memory and when


several independent programs are to be run together

support the use of subroutine libraries efficiently

Two methods for specifying relocation

modification record

relocation bit

each instruction is associated with one relocation bit

these relocation bits in a Text record is gathered into bit


masks

Modification Record
For complex machines
Also called RLD specification

Relocation

and Linkage Directory

Modification record
col 1: M
col 2-7: relocation
address
col 8-9: length (halfbyte)
col 10: flag (+/-)
col 11-17: segment
name

Relocation Bit

For simple machines


Relocation bit
0: no modification is necessary
1: modification is needed

Text record
col 1: T
col 2-7: starting address
col 8-9: length (byte)
col 10-12: relocation bits
col 13-72: object code

Twelve-bit mask is used in each Text record


since each text record contains less than 12 words
unused words are set to 0
any value that is to be modified during relocation must coincide with one
of these 3-byte segments
e.g. line 210

Program Linking

Goal

Resolve the problems with EXTREF and EXTDEF from different control
sections

Linking
1.

User, 2. Assembler, 3. Linking loader

Example

Program in Fig. 3.8 and object code in Fig. 3.9


Use modification records for both relocation and linking

address constant
external reference

Program Linking Example


Label

Expression

REF1 LISTA

Program A
Program B
Program C
LISTA, ENDA LISTB, ENDB LISTC, ENDC
local, R, PC

external

external

REF2 LISTB+4

external

local, R, PC

external

REF3 ENDA-LISTA

local, A

external

external

REF4 ENDA-LISTA+LISTC

local, A

external

local, R

REF5 ENDC-LISTC-10

external

external

local, A

REF6 ENDC-LISTC+LISTA-1

local, R

external

local, A

REF7 ENDA-LISTA-(ENDB-LISTB)
REF8 LISTB-LISTA

local, A
local, R

local, A
local, R

external
external

Linking Loader

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

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

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

Algorithms and Data structures for a linking loader

Modification record:

.
Two passes:

Make the linking and relocation to be processed similarly

Assign addresses to all external symbols


Perform actual loading, relocation, and linking.

Data structures used by linking loaders


External symbol tab: ESTAB
Name, address, and control session belonging to
Also control sessions (name, address, length)
Hash table
ESTAB with control sessions and external symbols

Algorithms and Data structures for a linking loader (cont.)

Program load address : PROGADDR

Control session address: CSADDR

The beginning address in memory where the linked program is to be loaded.


Supplied to loader by OS

The starting address of the current control session.


Added to all relative addresses in the control session to get actual addresses.

Execution starting address: EXECADDR.

Algorithms and Data structures for a linking loader (cont.)

Algorithms for Pass 1 of a linking loader

In Pass 1:

Just process Header and Define records


PROGADDR is initialized from OS, also becoming the starting address of
the first control session (CSADDR)
Control session is entered ESTAB with name from Header record, address
from CSADDR
For each symbol in Define record, enter to ESTAB with name, address
(value in the Define record +CSADDR)
When End record is encountered, CSLTH (given in Header record) is added
to CSADDR, which become CSADDR of the next control session.

Algorithms and Data structures for a linking loader (cont.)

In pass 2:

May print a load map for all control sessions and symbols, useful in program debugging
Actually loading, relocation, and linking
CSADDR is used as in Pass 1
For each Text record, the object code is placed to the address (=the address in the
instruction + CSADDR).
For each Modification record, from the name, looking for ESTAB to get the address (in
another control session), then add or subtract from the indicated location.

Transfer the control to the starting address indicated by EXECADDR

THANK YOU

S-ar putea să vă placă și