Loaders and Linkers · Overview[3] •The execution of program can be done with the help of...

57
Loaders and Linkers

Transcript of Loaders and Linkers · Overview[3] •The execution of program can be done with the help of...

Page 1: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Loaders and Linkers

Page 2: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overview[1]

• Loader is a system program that performs the loading function.

• Thus, loader is actually responsible for initiating the execution process.

• To execute an object program:

• Relocation, which modifies the object program so that it can be loaded at an address different from the location originally

specified: Allows loading at different locations

• Linking, which combines two or more separate object programs and supplies the information needed to allow references between

them

• Loading and Allocation, which allocates memory location and brings the object program into memory for execution

2M.Bhagavathi Priya/AP/ECE

Page 3: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overview[2]

Role of Loader

Role of Loader with Assembler

Role of Loader and Linker with Assembler

3M.Bhagavathi Priya/AP/ECE

Page 4: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overview[3]

• The execution of program can be done with the help of following

steps

1. Translation of the program (done by assembler or compiler)

2. Linking of the program with all other programs which are needed for

execution. This also involves preparation of a program called load

module.

3. Loading of the load module prepared by linker to some specified

memory location.

4M.Bhagavathi Priya/AP/ECE

Page 5: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overview[4]

5M.Bhagavathi Priya/AP/ECE

Page 6: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overview[5]

• Type of loaders

• Assemble-and-go loader

• Absolute loader (bootstrap loader)

• Relocating loader (relative loader)

• Direct linking loader

• Design options

• Linkage editors

• Dynamic linking

• Bootstrap loaders

6M.Bhagavathi Priya/AP/ECE

Page 7: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Basic Loader Functions

• Allocation: allocate space in memory for the programs

• Linking: Resolve symbolic references between object files

• combines two or more separate object programs

• supplies the information needed to allow references between them

• Relocation: Adjust all address dependent locations, such as address constants, tocorrespond to the allocated space

• modifies the object program so that it can be loaded at an address different from the location originally specified

• Loading: Physically place the machine instructions and data into memory

7M.Bhagavathi Priya/AP/ECE

Page 8: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Types of Loaders

• Based on the various functionalities of loader, there are various

types of loaders:

• “Compile/Assemble-and-Go” loader

• General Loader

• Absolute Loader

8M.Bhagavathi Priya/AP/ECE

Page 9: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

“Compile/Assemble-and-Go” loader[1]

• The assembler run in one part of memory

• Place the assembled machine instructions and data, as they are assembled,

directly into their assigned memory locations

• The instruction is read line by line, its machine code is obtained and it is

directly put in the main memory at some known address.

• That means the assembler runs in one part of memory and the assembled machine instructions

and data is directly put into their assigned memory locations.

9M.Bhagavathi Priya/AP/ECE

Page 10: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

“Compile/Assemble-and-Go” loader[2]

10M.Bhagavathi Priya/AP/ECE

Page 11: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

“Compile/Assemble-and-Go” loader[3]

• After completion of assembly process, assign starting address of the

program to the location counter.

• The typical example is WATFOR-77, it’s a FORTRAN compiler which uses such “load and go”

scheme.

• Characteristic

• The object code is produced directly in memory for immediate execution after assembly

• Advantage

• Simple, useful for program development and testing

11M.Bhagavathi Priya/AP/ECE

Page 12: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

“Compile/Assemble-and-Go” loader[4]

• Disadvantages

• Memory wastage (portion of the memory is occupied byassembler)

• Whenever the assembly program is to be executed, it has to be assembled again (There

is no production of .obj file) More execution time

• Programs have to be coded in the same language (can’t handle multiple source program

written in different languages)

• Difficult to make an orderly modulator program

12M.Bhagavathi Priya/AP/ECE

Page 13: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

General Loader[1]

• The source program is converted to object program by some translator

(assembler).

• The loader accepts these object modules and puts machine instruction and

data in an executable form at their assigned memory.

• The loader occupies some portion of main memory.

13M.Bhagavathi Priya/AP/ECE

Page 14: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

General Loader[2]

14M.Bhagavathi Priya/AP/ECE

Page 15: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

General Loader[3]

• Advantages:

• The program need not be retranslated each time while running it. This is because

initially when source program gets executed an object program gets generated.

• There is no wastage of memory, because assembler is not placed in the memory, instead

of it, loader occupies some portion of the memory.

• It is possible to write source program with multiple programs and multiple languages,

because the source programs are first converted to object programs always, and loader

accepts these object modules to convert it to executable form.

15M.Bhagavathi Priya/AP/ECE

Page 16: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Absolute Loader[1]

• Absolute loader is a kind of loader in which relocated object files are created,

loader accepts these files and places them at specified locations in the

memory.

• This type of loader is called absolute because no relocation information is

needed; rather it is obtained from the programmer or assembler.

• Assembler should have knowledge of memory management.

16M.Bhagavathi Priya/AP/ECE

Page 17: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Absolute Loader[2]

17M.Bhagavathi Priya/AP/ECE

Page 18: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Absolute Loader[3]

• Absolute loader only performs loading function

• Does not need to perform linking and program relocation.

• All functions are accomplished in a single pass.

• Absolute Loader

• Advantage

• Simple (implementation and loading) and efficient (process of execution)

• This scheme allows multiple programs or the source programs written different languages.

• Disadvantage

• Actual load address must be specified

• The need for programmer to specify the actual address at which it will be loaded into memory (memory mgt.)

• Difficult to use subroutine libraries efficiently

18M.Bhagavathi Priya/AP/ECE

Page 19: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Absolute Loader[4], Algorithm

19M.Bhagavathi Priya/AP/ECE

Page 20: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Absolute Loader[5], Object Code

Representation

• In algorithm of Absolute loader

• Each byte of assembled code is given using its hexadecimal representation in character form

• Easy to read by human beings

• In general

• Each byte of object code is stored as a single byte

• Most machine store object programs in a binary form

• We must be sure that our file and device conventions do not cause some of the program bytes to be interpreted as control characters

20M.Bhagavathi Priya/AP/ECE

Page 21: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Machine Dependent Loader Features

• Drawback of absolute loaders

• Programmer needs to specify the actual address at which it will be loaded into memory.

• Difficult to run several programs concurrently, sharing memory between them.

• Difficult to use subroutine libraries.

• Solution: a more complex loader that provides

• Program relocation

• Program linking

21M.Bhagavathi Priya/AP/ECE

Page 22: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Relocation[1]

• 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 (Fig. 3.4, 3.5)

• relocation bit (Fig. 3.6, 3.7)

• each instruction is associated with one relocation bit

• these relocation bits in a Text record is gathered into bit masks

22M.Bhagavathi Priya/AP/ECE

Page 23: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Relocation[2]

• A Modification record is used to describe each part of the object code that

must be changed when the program is relocated.

• For complex machines

• Also called RLD specification

• Relocation and Linkage Directory

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

23M.Bhagavathi Priya/AP/ECE

Page 24: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Relocation[3]

24M.Bhagavathi Priya/AP/ECE

Page 25: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Relocation[4]

• For simple machines

• Relocation bit

• 0: no modification is necessary

• 1: modification is needed

• 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

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

25M.Bhagavathi Priya/AP/ECE

Page 26: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Linking[1]

• Necessary for separate CSECTS

• 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

26M.Bhagavathi Priya/AP/ECE

Page 27: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Linking[2], Example

Program A Program B Program C

Label Expression LISTA, ENDA LISTB, ENDB LISTC, ENDC

REF1 LISTA 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) local, A local, A external

REF8 LISTB-LISTA local, R local, R external

27M.Bhagavathi Priya/AP/ECE

Page 28: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Program Linking[3], Example

• Load address for control sections

• PROGA 004000 63

• PROGB 004063 7F

• PROGC 0040E2 51

• Load address for symbols

• LISTA: PROGA+0040=4040

• LISTB: PROGB+0060=40C3

• LISTC: PROGC+0030=4112

• REF4 in PROGA

• ENDA-LISTA+LISTC=14+4112=4126

• T0000540F000014FFFFF600003F000014FFFFC0

• M00005406+LISTC

28M.Bhagavathi Priya/AP/ECE

Page 29: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Data Structures

• External Symbol Table (ESTAB)

• Stores the name and address of each external symbol in the set of programs

being

loaded.

• Indicates in which program the symbol is defined.

• A hash table is generally used.

• Program Load Address (PROGADDR)

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

• supplied by the O/S

29M.Bhagavathi Priya/AP/ECE

Page 30: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

More Databases

• Control Section Address (CSADDR)

• starting address assigned to the CS currently being scanned by the loader

• Its value is added to all relative addresses within the control section to convert them to

actual addresses

30M.Bhagavathi Priya/AP/ECE

Page 31: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overlay Structures & Dynamic

Loading[1]

• Sometimes a program may require more storage space than the available one

• Execution of such program can be possible if all the segments are not

required simultaneously to be present in the main memory.

• In such situations only those segments are resident in the memory that are

actually needed at the time of execution.

• The inter dependency of the segments can be specified by a tree like

structure called static overlay structures.

31M.Bhagavathi Priya/AP/ECE

Page 32: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Overlay Structures & Dynamic

Loading[2]

• The inter dependency of the segments can be specified by a tree like structure called static

overlay structures.

• The overlay structure contain multiple root/nodes and edges. Each node represents the

segment.

• The specification of required amount of memory is also essential in this structure.

32M.Bhagavathi Priya/AP/ECE

Page 33: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Two pass Direct Linking Loader

• Two-pass process (similar to the Assembler):

• Pass 1:

• Allocate and assigns addresses to all external symbols

• Provides a load map (info. in symbol table)

• Pass 2

• Actual loading,

• Relocation, and

• Linking(resolve external references)

33M.Bhagavathi Priya/AP/ECE

Page 34: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Pass 1 Program Logic

rom OS

• Pass 1:

• Assign addresses to all external symbols

• Variables

• PROGADDR (program load address) f

• CSADDR (control section address)

• CSLTH (control section length)

• ESTAB

34M.Bhagavathi Priya/AP/ECE

Page 35: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Pass 2 Program Logic

Pass 2:

» perform the actual loading,

relocation, and linking

Modification record

» lookup the symbol in ESTAB

End record for a main program

» transfer address

35M.Bhagavathi Priya/AP/ECE

Page 36: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Improve Efficiency[1]

• Use local searching instead of multiple searches of ESTAB for the same

symbol

• assign a reference number to each external symbol

• the reference number is used in Modification records

• Implementation

• 01: control section name

• other: external reference symbols

36M.Bhagavathi Priya/AP/ECE

Page 37: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Improve Efficiency[2], Example

PROGA

PROGB PROGC

R e f N o . Symbol A d d r e s s

1 PROGA 4 0 0 0

2 L I S T B 4 0 C 3

3 E N D B 4 0 D 3

4 L I S T C 4 1 1 2

5 E N D C 4 1 2 4

R e f N o . Sy mb o l Ad d r e s s

1 P R O G B 4 0 6 3

2 L I S T A 4 0 4 0

3 E N D A 4 0 5 4

4 L I S T C 4 1 1 2

5 E N D C 4 1 2 4

R e f N o . Symbol A d d r e s s

1 PROGC 4 0 6 3

2 LISTA 4 0 4 0

3 ENDA 4 0 5 4

4 LISTB 4 0 C 3

5 ENDB 4 0 D 3

37M.Bhagavathi Priya/AP/ECE

Page 38: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Machine-Independent Loader Features

• Automatic Library Search

• Many linking loaders can automatically incorporate routines from a

subprogram library into the program being loaded

• A standard library

• Other libraries may be specified by control statements or by parameters to the

loader

• Also called automatic library call in some systems

• Loader Options (Parameters)

38M.Bhagavathi Priya/AP/ECE

Page 39: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Automatic Library Search[1]

• Library routines are external references

• Users can include routines to override library routines

• Library search is a search of the directory that contains addresses of the

routines.

• Linking loaders 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

39M.Bhagavathi Priya/AP/ECE

Page 40: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Automatic Library Search[2]

• At the end of Pass 1, the symbols in ESTAB that remain undefined represented unresolved external references

• Then, the loader searches the library or libraries specified for routines that contain the definitions of these symbols

• Note that the subroutines fetched from a library in this way may themselves contain external references.

• It is therefore necessary to repeat the library search process until all reference are resolved.

40M.Bhagavathi Priya/AP/ECE

Page 41: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Automatic Library Search[3]

• The process allows the programmer to override the standard subroutines in

the library by supplying his or her own routines

• The libraries to be searched by the loader ordinarily contain assembled or compiled versions

of the subroutines (i.e., object programs)

• For efficient searching

• Directory

• Some operating systems can keep the directory for commonly used libraries permanently in

memory

• The same technique applies equally well to the resolution of external references todata

items

41M.Bhagavathi Priya/AP/ECE

Page 42: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Loader Options[1]

• Many loaders allow the user to specify options that modify the standard

processing

• Many loaders have a special command language

• A separate input file to loader

• Embedded in the primary input stream

• In source program

42M.Bhagavathi Priya/AP/ECE

Page 43: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Loader Options[2]

• Examples of command language

1. INCLUDE program-name(library-name)

Direct the loader to read the designated object program from a library and treatit as if it were part of the primary loader input

2. DELETE csdect-name

Instruct the loader to delete the named control section(s) from the set of programs being loaded

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

43M.Bhagavathi Priya/AP/ECE

Page 44: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Loader Options[3]

• Examples of commandlanguage

4. LIBRARY MYLIB

• Specify alternative libraries to be searched.

• These are searched before system libraries, allowing user versions to replace system versions.

5. NOCALL STDDEV, PLOT, CORREL

• To instruct the loader that these external references are to remain unsolved

• Specify that library routines not be included. If, for example, statistics were normally done, but not done in this run.

6. Others

• Output from the load, e.g., the map which includes control section names and adddresses

• The ability to specify the location at which execution is to begin

• Control whether or not the loader should attempt to execute the program if errors are detected during the load

44M.Bhagavathi Priya/AP/ECE

Page 45: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Loader Design Options

1. Linking Loaders

• All linking and relocation at runtime

2. Linkage Editor

• Perform linking prior to load time

3. Dynamic linking

• Linking function is performed at execution time

4. Bootstrap loader

• Be used to run stand-alone programs independent of the operating system or the system loader

45M.Bhagavathi Priya/AP/ECE

Page 46: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[1]

• A linking loaders performs

• All linking and relocation operations

• Automatic library search

• Loads the linked program directly into memory for execution

• A linkage editor

• Produces a linked version of program (often called a load module or an executable image), which is written to a file or library for later execution

• A simple relocating loader can be used to load the linked version of program into memory

• The loading can be accomplished in one pass with no external symbol table required

46M.Bhagavathi Priya/AP/ECE

Page 47: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[2]

• The essential difference between a linkage editor and a linking loader

47M.Bhagavathi Priya/AP/ECE

Page 48: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[3]

• A linkage editor

• Resolution of external references and library searching are only performed once

• In the linked version of programs

• All external references are resolved, and relocation is indicated by some mechanism such as

modification records or a bit mask

• External references is often retained in the linked program

• To allow subsequent relinking of the program to replace control sections, modify external

references, etc.

48M.Bhagavathi Priya/AP/ECE

Page 49: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[4]

• Linkage editors can perform many useful functions besides simply

preparing an object program for execution

1. The linkage editor can be used to replace the subroutines in the linked version

INCLUDE

DELETE

INCLUDE

REPLACE

PLANNER(PROGLIB)

PROJECT

PROJECT(NEWLIB)

PLANNER(PROGLIB)

49M.Bhagavathi Priya/AP/ECE

Page 50: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[5]

2. Linkage editors can also be used to build packages of subroutines or othercontrol

sections that are generally used together

It could be used to combine the appropriate subroutines into a package with a command

sequence READR(FTNLIB)

WRITER(FTNLIB)

BLOCK(FTNLIB)

DEBLOCK(FTNLIB)

ENCODE(FTNLIB)

DECODE(FTNLIB)

INCLUDE

INCLUDE

INCLUDE

INCLUDE

INCLUDE

INCLUDE

.

.

.

SAVE FTNIO(SUBLIB)

50M.Bhagavathi Priya/AP/ECE

Page 51: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Linkage Editors[6]

3. Linkage editors often allow the user to specify that external references are not to be

resolved by automatic library search

Only the external references between user-written routines would be resolved

51M.Bhagavathi Priya/AP/ECE

Page 52: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Dynamic Linking[1]

• Postpone the linking function until execution time

• A subroutine is loaded and linked to the rest of the program when it is first called

• Dynamic linking, dynamic loading, or load on call

• Allow several executing programs to share one copy of a subroutine or library

• In object-oriented system, it allows the implementation of the object and its methods to be determined at the time the program is run

• Dynamic linking provides the ability to load the routines only when they are needed

52M.Bhagavathi Priya/AP/ECE

Page 53: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

called via an• Dynamically loaded must beoperating system service request

• Load-and-call service

a) OS examines its inernal tables to determine whether or not the routine is already loaded

b) Routine is loaded from library

c) Control is passed from OS to the calledsubroutine

d) Subroutine is finished

e) Calling to a subroutine which is already in memory

• Binding of the name to an actuall address is delayed from load time until execution time

Dynamic Linking[2]

53M.Bhagavathi Priya/AP/ECE

Page 54: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Dynamic Linking[3]

• Advantages

• The overhead on the loader is reduced.

• The required subroutine will be load in the main memory only at the time of

execution.

• The system can be dynamically reconfigured.

• Disadvantages

• The linking and loading need to be postponed until the execution.

• During the execution if at all any subroutine is needed then the process of execution

needs to be suspended until the required subroutine gets loaded in the main memory.

54M.Bhagavathi Priya/AP/ECE

Page 55: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Bootstrap Loader[1]

• Bootstrap Loader

• A special absolute loader

• Typically single pass

• 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 address0

• It loads the OS starting address 0x80

• No header record or control information, the object code is consecutive bytes of memory

55M.Bhagavathi Priya/AP/ECE

Page 56: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Bootstrap Loader[2]

SIC Bootstrap Loader Logic1. Begin2. X=0x80 (the address of the next memory location to be loaded

3. LoopAGETC (and convert it from the ASCII character code to the value of the hexadecimal digit)4.

5.6.7.8.

save the value in the high-order 4 bits of S AGETCcombine the value to form one byte A (A+S) store the value (in A) to the address in register X

9. XX+110. End

0~9 : 48A~F : 65

GETC Aread one character

if A=0x04 then jump to0x80

if A<48 then GETC

A A-48 (0x30)

if A<10 then return

A A-7(48+7=55)

return

56M.Bhagavathi Priya/AP/ECE

Page 57: Loaders and Linkers · Overview[3] •The execution of program can be done with the help of following steps 1. Translation of the program (done by assembler orcompiler) 2. Linking

Bootstrap Loader[3]

• Given an idle computer with no program in memory, how do we get things

started?

• With the machine empty and idle, there is no need for program relocation

• Some early computers required the operator to enter into memory the object code for an

absolute loader, using switches on the computer console

• One some computer, an absolute loader program is permanently resident in a ROM

• A built-in hardware function that reads a fixed-length record form some device into memory

at a fixed location

57M.Bhagavathi Priya/AP/ECE