chapter iii: loaders and linkers

Post on 02-Jan-2016

92 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Chapter goal: To realize how a source program be loaded into memory Loading Relocation Linking. Overview: Design of an absolute loader The Bootstrap loader Relocation Program linking Algorithm for a linking loader Other loader design options. Chapter III: Loaders and Linkers. Loading - PowerPoint PPT Presentation

TRANSCRIPT

3. Loaders & Linkers1

Chapter III: Loaders and Linkers

Chapter goal: To realize how a source

program be loaded into memory Loading Relocation Linking

Overview: Design of an absolute loader The Bootstrap loader Relocation Program linking Algorithm for a linking loader Other loader design options

3. Loaders & Linkers2

Loading Bring 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.

Introduction

3. Loaders & Linkers3

Loader is a system program that performs the loading function.

Linker perform the linking operations.

P.s. 1. Many loader also support relocation and linking. P.s. 2. Some system have a linker to perform the linking

operations and a separate loader to handle relocation and loading.

Introduction (cont.)

3. Loaders & Linkers4

No need to perform functions as linking and program relocation.

The operation is very simple.

All functions are accomplished in a single pass.

Basic loader functions – The absolute loader

3. Loaders & Linkers5

The Object code for the program in @2.1

3. Loaders & Linkers6

The Object code for the program in @2.1 (cont.)

3. Loaders & Linkers7

The Object code for the program in @2.1 (cont.)

3. Loaders & Linkers8

The object program for the program in @2.1

3. Loaders & Linkers9

Loading of an absolute program

3. Loaders & Linkers10

Algorithm for an absolute loader

3. Loaders & Linkers11

Basic loader functions – Bootstrap loader

When a computer is first turned on or restarted, a special type of absolute loader, called a bootstrap loader, is executed.

The bootstrap loader itself begins at address 0 in the memory of the machine.

It loads the operating system (or some other program) starting at address 80.

3. Loaders & Linkers12

Bootstrap loader for SIC/XE

3. Loaders & Linkers13

Bootstrap loader for SIC/XE (cont.)

3. Loaders & Linkers14

Machine-dependent loader features

The advantages and disadvantages for absolute loader Advantage: Simple and efficient. Disadvantage:

Need the programmer to specify the actual address at which it will be loaded into memory. It is difficult to use subroutine libraries efficiently.

So we need --- the capability of program relocation.

3. Loaders & Linkers15

Machine-dependent loader features --- Relocation

Loaders that allow for program relocation are called relocating loaders or relative loaders.

The relocating loaders need to take care of the modification record which must be changed when the program is relocated.

3. Loaders & Linkers16

Example of a SIC/XE program

3. Loaders & Linkers17

Example of a SIC/XE program (cont.)

3. Loaders & Linkers18

Example of a SIC/XE program (cont.)

3. Loaders & Linkers19

Object program with relocation by modification records.

3. Loaders & Linkers20

Relocation (cont.)

In SIC/XE machine, most of the code is not need to relocation (e.g., PC relative addressing or immediate addressing). Only the Format 4 (e.g, +SUB…) needed.

Since the SIC machine does not support the PC relative mode, so lots of the instructions need to be relocated.

The SIC machine use bit mask to indicate, whether the relocation is needed or not.

E.g., bit mask FFC (=1111 1111 1100) means the first 10 words need to be relocated.

3. Loaders & Linkers21

Relocatable program for a standard SIC machine

3. Loaders & Linkers22

Relocatable program for a standard SIC machine (cont.)

3. Loaders & Linkers23

Relocatable program for a standard SIC machine (cont.)

3. Loaders & Linkers24

Object program with relocation by bit mask.

3. Loaders & Linkers25

Program Linking

3. Loaders & Linkers26

Program Linking (cont.)

3. Loaders & Linkers27

Program Linking (cont.)

3. Loaders & Linkers28

Object program corresponding to above program

3. Loaders & Linkers29

Object program corresponding to above program (cont.)

3. Loaders & Linkers30

Object program corresponding to above program (cont.)

3. Loaders & Linkers31

External symbol table (ESTAB)

3. Loaders & Linkers32

Relocation an linking operations performed on REF4 from PROGA

3. Loaders & Linkers33

Program from above program after linking and loading

3. Loaders & Linkers34

Algorithm and Data structure for a Linking Loader

Two passes of a linking loader Pass1 Assigns addresses to all external symbols Pass2 Performs the actual loading, relocation, and linking.

3. Loaders & Linkers35

Algorithm and Data structure for a Linking Loader (cont.)

3. Loaders & Linkers36

Algorithm and Data structure for a Linking Loader (cont.)

3. Loaders & Linkers37

Enhancing the object program

Reference number To indicated each external symbol referred to in a

control section. Reference number 01 is corresponding to the control

section name.

3. Loaders & Linkers38

Enhancing the object program (cont.)

3. Loaders & Linkers39

Enhancing the object program (cont.)

3. Loaders & Linkers40

Enhancing the object program (cont.)

3. Loaders & Linkers41

Machine-independent loader features – Automatic library search

Automatic library call (library search) Libraries such as mathematical or statistical routines.

The subroutines called by the program being loaded are automatically fetched from the library, linked with the main program, and loaded.

The programmer does not need to take any action beyond mentioning the subroutines names as external references in the source program.

3. Loaders & Linkers42

Machine-independent loader features – Loader options

A special command language that is used to specify options.

E.g., INCLUDE program-name(library-name) DELETE csect-name CHANGE name1,name2

INCLUDE READ(UTLIB) INCLUDE WRITE(UTLIB) DELETE RDREC, WRREC CHANGE RDREC, READ CHANGE WRREC, WRITE

3. Loaders & Linkers43

Loader design options – Linkage Editors

A linking loader performs all linking and relocation operations, and loads the linked program directly into memory for execution.

A linkage editor produces a linked version of the program (loader module or executable image) which is written to a file or library for later execution.

3. Loaders & Linkers44

Loader design options – Linkage Editors (cont.)

3. Loaders & Linkers45

Loader design options – Dynamic linking

The linkage editors perform linking operations before the program is loaded for execution.

The dynamic linking (dynamic loading or load on call) load a subroutine and linked to the rest of the program when it is first called.

3. Loaders & Linkers46

Loader design options – Dynamic linking (cont.)

3. Loaders & Linkers47

Loader design options – Dynamic linking (cont.)

top related