chapter iii: loaders and linkers

47
3. Loaders & Linkers 1 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

Upload: kelly-weeks

Post on 02-Jan-2016

92 views

Category:

Documents


3 download

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

Page 1: Chapter III: Loaders and Linkers

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

Page 2: Chapter III: Loaders and Linkers

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

Page 3: Chapter III: Loaders and Linkers

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.)

Page 4: Chapter III: Loaders and Linkers

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

Page 5: Chapter III: Loaders and Linkers

3. Loaders & Linkers5

The Object code for the program in @2.1

Page 6: Chapter III: Loaders and Linkers

3. Loaders & Linkers6

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

Page 7: Chapter III: Loaders and Linkers

3. Loaders & Linkers7

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

Page 8: Chapter III: Loaders and Linkers

3. Loaders & Linkers8

The object program for the program in @2.1

Page 9: Chapter III: Loaders and Linkers

3. Loaders & Linkers9

Loading of an absolute program

Page 10: Chapter III: Loaders and Linkers

3. Loaders & Linkers10

Algorithm for an absolute loader

Page 11: Chapter III: Loaders and Linkers

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.

Page 12: Chapter III: Loaders and Linkers

3. Loaders & Linkers12

Bootstrap loader for SIC/XE

Page 13: Chapter III: Loaders and Linkers

3. Loaders & Linkers13

Bootstrap loader for SIC/XE (cont.)

Page 14: Chapter III: Loaders and Linkers

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.

Page 15: Chapter III: Loaders and Linkers

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.

Page 16: Chapter III: Loaders and Linkers

3. Loaders & Linkers16

Example of a SIC/XE program

Page 17: Chapter III: Loaders and Linkers

3. Loaders & Linkers17

Example of a SIC/XE program (cont.)

Page 18: Chapter III: Loaders and Linkers

3. Loaders & Linkers18

Example of a SIC/XE program (cont.)

Page 19: Chapter III: Loaders and Linkers

3. Loaders & Linkers19

Object program with relocation by modification records.

Page 20: Chapter III: Loaders and Linkers

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.

Page 21: Chapter III: Loaders and Linkers

3. Loaders & Linkers21

Relocatable program for a standard SIC machine

Page 22: Chapter III: Loaders and Linkers

3. Loaders & Linkers22

Relocatable program for a standard SIC machine (cont.)

Page 23: Chapter III: Loaders and Linkers

3. Loaders & Linkers23

Relocatable program for a standard SIC machine (cont.)

Page 24: Chapter III: Loaders and Linkers

3. Loaders & Linkers24

Object program with relocation by bit mask.

Page 25: Chapter III: Loaders and Linkers

3. Loaders & Linkers25

Program Linking

Page 26: Chapter III: Loaders and Linkers

3. Loaders & Linkers26

Program Linking (cont.)

Page 27: Chapter III: Loaders and Linkers

3. Loaders & Linkers27

Program Linking (cont.)

Page 28: Chapter III: Loaders and Linkers

3. Loaders & Linkers28

Object program corresponding to above program

Page 29: Chapter III: Loaders and Linkers

3. Loaders & Linkers29

Object program corresponding to above program (cont.)

Page 30: Chapter III: Loaders and Linkers

3. Loaders & Linkers30

Object program corresponding to above program (cont.)

Page 31: Chapter III: Loaders and Linkers

3. Loaders & Linkers31

External symbol table (ESTAB)

Page 32: Chapter III: Loaders and Linkers

3. Loaders & Linkers32

Relocation an linking operations performed on REF4 from PROGA

Page 33: Chapter III: Loaders and Linkers

3. Loaders & Linkers33

Program from above program after linking and loading

Page 34: Chapter III: Loaders and Linkers

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.

Page 35: Chapter III: Loaders and Linkers

3. Loaders & Linkers35

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

Page 36: Chapter III: Loaders and Linkers

3. Loaders & Linkers36

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

Page 37: Chapter III: Loaders and Linkers

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.

Page 38: Chapter III: Loaders and Linkers

3. Loaders & Linkers38

Enhancing the object program (cont.)

Page 39: Chapter III: Loaders and Linkers

3. Loaders & Linkers39

Enhancing the object program (cont.)

Page 40: Chapter III: Loaders and Linkers

3. Loaders & Linkers40

Enhancing the object program (cont.)

Page 41: Chapter III: Loaders and Linkers

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.

Page 42: Chapter III: Loaders and Linkers

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

Page 43: Chapter III: Loaders and Linkers

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.

Page 44: Chapter III: Loaders and Linkers

3. Loaders & Linkers44

Loader design options – Linkage Editors (cont.)

Page 45: Chapter III: Loaders and Linkers

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.

Page 46: Chapter III: Loaders and Linkers

3. Loaders & Linkers46

Loader design options – Dynamic linking (cont.)

Page 47: Chapter III: Loaders and Linkers

3. Loaders & Linkers47

Loader design options – Dynamic linking (cont.)