0% found this document useful (0 votes)
192 views50 pages

Ch. 3 Loaders and Linkers: SP - Loader 1

The document discusses loaders and linkers. It describes different types of loaders including absolute, relocatable, and linking loaders. Absolute loaders only perform loading, while relocatable and linking loaders also perform allocation, linking, and relocation. Linking involves integrating program modules by resolving external references and assigning a single starting address. The two-pass algorithm of a linking loader is described, with the first pass defining section addresses and symbols, and the second performing loading and relocation.

Uploaded by

Pradeep Bhatt
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views50 pages

Ch. 3 Loaders and Linkers: SP - Loader 1

The document discusses loaders and linkers. It describes different types of loaders including absolute, relocatable, and linking loaders. Absolute loaders only perform loading, while relocatable and linking loaders also perform allocation, linking, and relocation. Linking involves integrating program modules by resolving external references and assigning a single starting address. The two-pass algorithm of a linking loader is described, with the first pass defining section addresses and symbols, and the second performing loading and relocation.

Uploaded by

Pradeep Bhatt
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

Ch.

3 Loaders and Linkers

3.1 Introduction

SP - Loader 1
Functions of loader
1. Allocate space in memory for the program (allocation).
2. Resolve symbolic references between object programs
(linking).
3. Adjust all address dependent locations, such as address
constraints, to correspond to the allocated space
(relocation).
4. Physically place the machine instruction and data into
memory(loading) for execution.
• Loader: System program that performs the loading
function.
• Linker (or linkage editor): System program that
performs the linking operations(i.e. linking and
relocation).

SP - Loader 2
Kinds of Loader
• Absolute loader: perform loading only.
• Relocatable loader: perform allocation, relocation, an
d loading.
• Linkage editor: performing linking only.
• Linking loader: perform allocation, linking, reloc
ation, and loading.
• Fig. 3.13

SP - Loader 3
SP - Loader 4
3.2 Absolute loader and Bootstrap
Loader

SP - Loader 5
Absolute loader
• Object program contains:
– H card (or record)
– T cards (or record)
– E card (or record)
• Check the starting address and memory size required
(i.e. specified in H record), load Text records into
memory sequentially, and then jump to the starting
address specified by End record.
• Algorithm: Fig. 3.2

SP - Loader 6
Algorithm for absolute loader
begin
read Header record
verify program name and length
read first Text record
while record type ≠ 'E' do
begin
{if object code is in character form, convert into
internal representation}
move object code to specified location in memory
read next object program record
end
jump to address specified in End record
end
 
Figure 3.2 Algorithm for an absolute loader.

SP - Loader 7
Bootstrap loader
• First program to be executed (i.e. to load the operating
system) by the CPU.
• A special absolute loader with no header record and End
record.
– Load the program starting at fixed address.
– After finishing the loading, jump to the fixed address
to begin the execution.
• Sample program: Read the object program from device
F1 and store it into memory starting at address 128.
• Now, Read-Only Memory (ROM) is available. Kernel
Part of OS can be stored in ROM. The absolute loader (a
routine in Kernel), triggered by a specified power/reset
key, will load the OS into memory from a specified area
of disk.
SP - Loader 8
BOOT START 0 BOOTSTRAP LOADER For SIC/XE
.
. THIS BOOTSTRAP READS OBJECT CODE FROM DEVICE F1 AND ENTERS IT
. INTO MEMORY STARTING AT ADDRESS 80 (HEXADECIMAL). AFTER ALL OF
. THE CODE FROM DEVF1 HAS BEEN SEEN ENTERED INTO MEMORY, THE
. BOOTSTRAP EXECUTES A JUMP TO ADDRESS 80 TO BEGIN EXECUTION OF
. THE PROGRAM JUST LOADED. REGISTER X CONTAINS THE NEXT ADDRESS
. TO BE LOADED
.
CLEAR A CLEAR REGISTER A TO ZERO
LDX #128 INITIALIZE REGISTER X TO HEX 80
LOOP JSUB GETC READ HEX DIGIT FROM PROGRAM BEING LOADED
RMD A,S SAVE IN REGISTER S
SHIFTL S,4 MOVE TO HIGH-ORDER 4 BITS OF BYTE
JSUB GETC GET NEXT HEX DIGIT
ADDR S,A COMBINE DIGITS TO FORM ONE BYTE
STCH 0,X STORE AT ADDRESS IN REGISTER X
TIXR X,X ADD 1 TO MEMORY ADDRESS BEING LOADED
J LOOP LOOP UNTIL END OF INPUT IS REACHED
.

SP - Loader 9
. SUBROUTINE TO READ ONE CHARACTER FROM INPUT DEVICE AND
. CONVERT IT FROM ASCII CODE TO HEXADECIMAL DIGIT VALUE. THE
. CONVERTED DIGIT VALUE IS RETURNED IN REGISTER A. WHEN AN
. END-OF-FILE IS READ, CONTROL IS TRANSFERRED TO THE STARTING
. ADDRESS (HEX 80).
.
GETC TD INPUT TEST INPUT DEVICE
JEQ GETC LOOP UNTIL READY
RD INPUT READ CHARACTER
COMP #4 IF CHARACTER IS HEX 04 (END OF FILE),
JEQ 80 JUMP TO START OF PROGRAM JUST LOADED
COMP #48 COMPARE TO HEX 30 (CHARACTER '0')
JLT GETC SKIP CHARACTERS LESS THAN '0'
SUB #48 SUBTRACT HEX 30 FROM ASCII CODE
COMP #10 IF RESULT IS LESS THAN 10, CONVERSION IS
JLT RETURN COMPLETE. OTHERWISE, SUBTRACT 7 MORE
SUB #7 (FOR HEX DIGITS 'A' THROUGH 'F')
RETURN RSUB RETURN TO CALLER
INPUT BYTE X'F1' CODE FOR INPUT DEVICE
END LOOP

Figure 3.3 Bootstrap loader for SIC/XE.


SP - Loader 10
3.3 Linking Loader

SP - Loader 11
Relocation issue of object program
• Modification record: Used to describe the starting
address and length of code to be modified.
• SIC computer: Most instructions use direct addressing.
 Too many modification records are needed.
• Another approach: use relocation bit to indicate that the
word should be modified or not.
• Example: Fig 3.6 and 3.7

SP - Loader 12
Line Loc Source statement Object code
5 0000 COPY START 0
10 0000 FIRST STL RETADR 140033
15 0003 CLOOP JSUB RDREC 481939
20 0006 LDA LENGTH 000036
25 0009 COMP ZERO 280030
30 000C JEQ ENDFIL 300015
35 000F JSUB WRREC 481061
40 0012 J CLOOP 3C0003
45 0015 ENDFIL LDA EOF 00002A
50 0018 STA BUFFER 0C0039
55 OO1B LDA THREE 00002D
60 OO1E STA LENGTH 0C0036
65 0021 JSUB WRREC 481061
70 0024 LDL RETADR 080033
75 0027 RSUB 4C0000
80 002A EOF BYTE C'EOF' 454F46
85 002D THREE WORD 3 000003
90 0030 ZERO WORD 0 000000
95 0033 RETADR RESW 1
100 0036 LENGTH RESW 1
105 0039 BUFFER RESB 4096
110 . SP - Loader 13
115 . SUSROUTINE TO READ RECORD INTO BUFFER
120 .
125 1039 RDREC LDX ZERO 040030
130 103C LDA ZERO 000030
135 103F RLOOP TD INPUT E0l05D
140 1042 JEQ RLOOP 30103F
145 1045 RD INPUT D8105D
150 1048 COMP ZERO 280030
155 104B JEQ EXIT 301057
160 104E STCH BUFFER,X 548039
165 1051 TIX MAXLEM 2C105E
170 1054 JLT RLOOP 38103F
175 1057 EXIT STX LENGTH 100036
180 105A RSUB 4C0000
185 l05D INPUT BYTE X'F1' F1
190 l05E MAXLENWORD 4096 001000

SP - Loader 14
195 .
200 . SUBROUTINE TO WRITE RECORD FROM BUFFER
205 .
210 1061 WRREC LDX ZERO 040030
215 1064 WLOOP TD OUTPUT E01079
220 1067 JEQ WLOOP 301064
225 106A LDCH BUFFER,X 508039
230 106D WD OUTPUT DC1079
235 1070 TIX LENGTH 2C0036
240 1073 JLT LOOP 381064
245 1076 RSUB 4C0000
250 1079 OUTPUT BYTE X'05' 05
255 END FIRST

Figure 3.6 Relocatable program for a standard SIC machine.

SP - Loader 15
SP - Loader 16
Program linking issue
• Program: How to integrate all program modules together
as a program.
– The starting address of each program module is 0.
– Each module has EXTDEF symbols, EXTREF
symbols, and M-records.
• Example: Fig. 3.8 and 3.9
• Two-pass is needed to load the program
– Pass 1: Define the staring address of each section and
use a table to store the name and address of each
defined symbol.
– Pass 2: perform loading and relocation
• Fig. 3.10
• Algorithm of linking loader: Fig. 3.11

SP - Loader 17
SP - Loader 18
SP - Loader 19
SP - Loader 20
SP - Loader 21
SP - Loader 22
SP - Loader 23
SP - Loader 24
SP - Loader 25
Pass 1:
begin
get PROGADDR from operating system
set CSADDR to PROGADDR {for first control section}
while not end of input do
begin
read next input record {Header record for control section}
set CSLTH to control section length
search ESTAB for control section name
if found then
set error flag {duplicate external symbol}
else
enter control section name into ESTAB with value CSADDR
Figure 3.11(a) Algorithm for Pass 1 of a linking loader.

SP - Loader 26
while record type ≠ 'E' do
begin
read next input record
if record type = 'D' then
for each symbol in the record do
begin
search ESTAB for symbol name
if found then
set error flag (duplicate external symbol)
else
enter symbol into ESTAB with value
(CSADDR + indicated address)
end {for}
end {while ≠ 'E'}
add CSLTH to CSADDR {starting address for next control section
end {while not EOF}
end {Pass 1}
 

SP - Loader 27
Pass 2:
begin
set CSADDR to PROGADDR
set EXECADDR to PROGADDR
while not end of input do
begin
read next input record {Header record}
set CSLTH to control section length
while record type ≠'E' do
begin
read next input record
if record type = 'T' then
begin
{if object code is in character form, convert
into internal representation}
move object code from record to location
(CSADDR + specified address)
end {if 'T'}

SP - Loader 28
else if record type = 'M' then
begin
search ESTAB for modifying symbol name
if found then
add or subtract symbol value at location
(CSADDR + specified address)
else
set error flag (undefined external symbol)
end {if 'M'}
end{while ≠'E'}
if an address is specified {in End record} then
set EXECADDR to (CSADDR + specified address)
add CSLTH to CSADDR
end {while not EOF}
jump to location given by EXECADDR {to start execution of loaded program}
end {Pass 2}

Figure 3.11(b) Algorithm for Pass 2 of a linking loader.

SP - Loader 29
Program linking issue - continue
• To increase the search speed, we introduce the R-record
and M-record is modified as Fig. 3.12.
• If more than one control section have specified the
execution address, only last one is valid.
• If no execution address is specified in any control
section card, the loader will transfer to the starting
address of loading.

SP - Loader 30
SP - Loader 31
3.4 Additional loader Features

SP - Loader 32
System Library
• Example: SIN, COS etc. of FORTRAN library.
• Consist of Set of subroutines.
• User treats these subroutines as language features and
will use them in the program. At the end of pass 1 of
linking loader, some unsolved external references may
be found.
• Loader should search the system library automatically
and link the routines called in the program.
• Library
– Lots of assembled or compiled routines.
– One routine may call another routine, these routines
should be linked first, otherwise it will search the
library repeatedly. Linkage editor concept.
SP - Loader 33
System Library - continue
• To improve the searching speed, a directory which
contains the routine name and its address within the file
is created. If a subroutine is to be called by more than
one name, all these names are entered in the library.
• The library search involves searching directory, followed
by reading the object program called.
• To improve speed of searching and execution, the
directory and code of the library may be resident in the
memory permanently for some systems.
• User may create his library. And system may have more
than one system libraries.

SP - Loader 34
System Library - continue
• To load the library routines into memory:
– LOAD object programs/LIBRARY name1, …
– LOAD object programs/INCLUDE program-nam
e[library name], ...
• When unsolved reference variables are found in the pas
s 1, the linking loader will search the user library speci
fied, system library specified and defaulted system libr
ary sequentially. If found, go to pass 2.
• Other optional loader commands:
– DELETE csect-name
Delete external symbols or entire control sections.
– CHANGE name1, name2
External symbol name1 is changed to name2.

SP - Loader 35
System Library - continue
– Example:
INCLUDE READ(UTLIB)
INCLUDE WRITE (UTLIB)
DELETE RDREC, WRREC
CHANGE RDREC, READ
CHANGE WRECK, WRITE
– NOCALL STDDEV, PLOT
Some routines(STDDEV, PILOT) appeared in the
program will not be used in a particular execution,
these routines may not be resident in the memory
to save memory needed. External references are
still unsolved, but force the program to execute.

SP - Loader 36
Output of linking loader
• Specified as the option of command language.
• load map:
– Control section name, address
– External symbol addresses
– References to each external symbols

SP - Loader 37
3.5 Loader design options

SP - Loader 38
Linkage Editor
• Produce a linked version of the program ( called load
module, executable image, or image program).
• Solve external reference and library search, and perform
relocation of all sections relative to the start of the linked
program.
• Although all linking has been performed, information
concerning external reference is retained in the linked
program for further re-linking if necessary.

SP - Loader 39
Linkage Editor - continue
• Linkage editor commands:
– Example 1: new version of library routine
INCLUDE PLANNER(PROGLIB)
DELETE PROJECT
INCLUDE PROJECT (NEWLY)
REPLACE PLANNER (PROGLIB)
– Example 2: combine subroutines into a package
INCLUDE READR(FINLIB)
INCLUDE WRITER(FIN LIB)
INCLUDE BLOCK(FINLIB)
.................
SAVE FINIO(SUBLIB)
 The linked module name FINIO could be indexed
in the directory of SUBLIB under the same name as
the original subroutines.
SP - Loader 40
Dynamic Linking
• Linkage editor performs linking operation before the pro
gram is loaded for execution. Linking loader perform lin
king operation at load time.
• Dynamic linking (or dynamic binding, load on call) perf
orm linking operation until execution.
– When a subroutine call is encountered and the subrout
ine is not resident in memory, load the subroutine into
memory, perform linking, and finally jump to the subr
outine.
– Advantages: Load the routines when they are needed,
the memory space will be saved.

SP - Loader 41
Implementation of Dynamic Linking
• Need the help of operating system.
– OS should provide load-and call system call.
– OS has an internal table to keep the names the entry
points and the use condition of the routines in memo
ry.
• File system should keep all control section names in fil
e directory.
• "JSUB name" is converted as load-and-call name" syst
em service .
• Processing procedures of " load-and-call name“
1. Pass control to OS
2. OS check the routine in memory or not.If in memor
y, pass control to the routine. If not, load the routine
and pass control to the routine.
SP - Loader 42
Implementation of Dynamic Linking - continue
• Return from subroutine is converted to another system
call.
– When the called subroutine completes its processing,
return to the OS via system call and OS pass control
the caller.
– The memory space of this subroutine can then be
released. However, this action may not be done
immediately.

SP - Loader 43
SP - Loader 44
SP - Loader 45
3.6 MS-DOS linker

SP - Loader 46
SP - Loader 47
Types of records
• THEADR
Name of object module
• TYEDEF
List of external data type names
• PUBDEF
List of external symbols defined
• EXTDEF
List of external symbols referenced
• LNAMES
List of all segment and class named used
• SEGDEF
Name, length and alignment of a segment
• GPRDEF
How these segments areSPcombined
- Loader
into group 48
Types of records - continue
• LEDATA
– Translated instructions and data
• LIDATA
– Translated instructions and data that occur in
repeated pattern
• FIXUPP
– Address Modification information
• MODEND
– End of object module

SP - Loader 49
Function of linker
• Pass 1
– Compute the starting address of each segment.
– Construct a symbol table that associates an address
with each segment (using LNAMES, SEGDEF, and
GPRDEF records) and each external symbol ( using
EXTDEF and PUBDEF records).
• Pass 2
– Extract the translated instructions and data (using
LEDATA and LIDATA and FIXUPP records) from
object modules and build an image of the executable
program in memory.

SP - Loader 50

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy