System Software Unit 3
System Software Unit 3
in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 1 Page 2 of 2
Loading which brings the object program into memory for execution.
Relocation which modifies the object program so that it can be loaded at an address different
from the location originally specified.
.in
Linking which combines two or more separate object programs and supplies the information
needed to allow references between them.
be
A loader is a system program that performs the loading function. Many loaders also support
relocation and linking.
Some systems have a linker (or linkage editor) to perform the linking operations and a separate
loader to handle relocation and loading.
tu
Basic loader functions
The fundamental functions of a loader is bringing an object program into memory and starting its
se
execution.
Absolute loader
.c
It is very simple.
All operations are accomplished in a single pass.
An object program is loaded at the address specified on the START directive.
w
begin
end
1
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 1 Page 2 of 2
.in
be
tu
se
.c
This scheme needs the programmer to specify the actual address at which it will be loaded into
w
memory.
This scheme make it difficult to use subroutine libraries efficiently.
The subroutines must be pre-assigned absolute addresses.
w
w
2
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 2 Page 2 of 2
Bootstrap loader
When a computer is turned on or restarted, a special type of absolute loader, called bootstrap loader,
is executed.
The bootstrap loader loads the first program to be run by the computer usually an operating system,
from the boot disk (e.g., a hard disk or a floppy disk)
.in
Bootstrap loader for SIC/XE
be
tu
se
.c
w
w
w
3
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 2 Page 2 of 2
On x86 systems, when the CPU is powered on or reset, it sets its registers to a known state and
jumps to the starting address of boot ROM.
The boot ROM code reads the first block of the floppy or the hard disk into memory location zero
and then jumps to location zero.
The program in the first block in turn loads a slightly larger operating system boot program from a
.in
known place on the disk into memory, and it jumps to that program.
The just loaded program loads in the operating system and starts it.
There can be even more steps such as a boot manager that decides from which disk partition to read
the operating system boot program.
be
tu
se
.c
w
w
w
4
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 3 Page 2 of 2
Relocation
Loaders that allow for program relocation are called relocating loaders or relative loaders.
The need for program relocation is a consequence of the change to larger and more powerful computers.
o We would like to run several programs on a more advanced machine.
.in
Schemes for relocation
Modification record
be
A modification record is used to describe each part of the object code that must be changed when
the program is relocated.
Relocation bit
A relocation bit associated with each word of object code is used to indicate whether or not this
tu
word should be changed when the program is relocated.
Hardware relocation
Some computers provide a hardware relocation capability that eliminates some of the need for the
loader to perform program relocation.
se
Modification record
In the object program, there is one Modification record for each value that must be changed during
.c
relocation.
Each modification record specifies the starting address and length of the field
whose value is to be altered.
w
Col. 1 M
Starting location of the address field to be modified,
w
5
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 3 Page 2 of 2
.in
be
tu
Example of a SIC/XE program
se
.c
w
w
w
6
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 3 Page 2 of 2
.in
Relocation bit
be
tu
On a machine that
o primarily uses direct addressing and has a fixed instruction format,
it is often more efficient to specify relocation using the technique of the relocation
se
bit.
A relocation bit associated with each word of object code is used to indicate
whether or not this word should be changed when the program is relocated.
o If the relocation bit corresponding to a word of object code is set to 1, the
programs starting address is to be added to this word when the program is
.c
relocated.
o A bit value of 0 indicates that no modification is necessary.
o The bits corresponding to unused words are set to 0.
w
7
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 4 Page 2of2
Program linking
The assembler evaluate as mush of an expression as it can. The remaining terms are
passed on to the linking loader via Modification records.
.in
be
tu
se
.c
w
w
8
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 5 Page 2 of 2
Two passes
o Pass 1 assigns address to all external symbols.
o Pass 2 performs the actual loading, relocating, and linking.
Main data structure for a linking loader
.in
o It is used to store the name and address of each external symbol in the set of
control section being loaded.
o A hash organization is often used for ESTAB.
A variable, program load address, PROGADDR
be
o It is the beginning address in memory where the linked program is to be
loaded.
o Its value is supplied by the operating system.
A variable, control section address, CSADDR
o It contains the starting address assigned to the control section currently being
tu
scanned by the loader.
o This value is added to all relative addresses within the control section to
convert them to actual addresses.
se
.c
w
w
w
9
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 6 Page 2 of 2
.in
if record type == D {
// for first control section
for each symbol in record {
while not end of input do { search ESTAB for symbol
name
be
read next input
if found {
// head record for control section
set CSLTH to control section set error flag
tu
length
search ESTAB for control // duplicate external symbol
section name
} else {
se
}
}
add CSLTH to CSADDR
w
10
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 6 Page 2 of 2
set CSADDR to PROGADDR set EXECADDR to PROGADDR while not end of input {
read next input record // head record set CSLTH to control section length while record type
!= E {
.in
if object code is in character form, convert into internal representation move object code
from record to location (CSADDR + specified address)
be
search ESTAB for modifying symbol name if found {
program
w
w
w
11
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 7 Page 2 of 2
.in
The subroutines called by the program 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
subroutine names as external references in the source program
be
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.
At the end of pass 1, the symbols in ESTAB that remain undefined represent
tu
unresolved external references.
The loader searches the library for routines that contain the definitions of
these symbols, and processes the subroutines found by this search process
exactly as if they had been part of the primary input stream.
se
The subroutines fetched from a library in this way may themselves contain
external references. It is necessary to repeat the library search process until
all references are resolved.
If unresolved references remain after the library search is completed, they
.c
Search in library
w
Search libraries
an inefficient method
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period:8 Page 2 of 2
Loader options
Many loaders allow the user to specify options that modify the standard
processing.
Many loaders have a special command language that is used to specify
options.
.in
For example:
Include program-name (library name)
Direct the loader to read the designated object program from a
be
library
Delete csect-name
Instruct the loader to delete the named control sections from the
set of programs being loaded
Change name1, name2
tu
Cause the external symbol name1 to be changed to name2
wherever it appears in the program
se
In the COPY program, two subroutines RDREC and WRREC are designed
to perform read records and write records.
.c
program use READ instead of RDREC and WRITE rather than WRREC
without modifying the source
w
13
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period:8 Page 2 of 2
For example,
LIBRARY MYLIB
Such user- specified libraries are normally searched before the standard
system libraries.
.in
Loaders that perform automatic library search to satisfy external references
often allow the user to specify that some references not be resolved in this
way.
be
For example,
This avoids the overhead of loading and linking the unneeded routines,
and saves the memory space that would otherwise be required.
14
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 9 Page 2 of 2
Linkage editors
Linking loader
Performs all linking and relocation operations, including automatic library search,
.in
and loads the linked program into memory for execution.
Linkage editor
be
Produces a linked version of the program, which is normally written to a file or
library for later execution.
o A simple relocating loader (one pass) can be used to load the program into
memory for execution.
tu
o The linkage editor performs relocation of all control sections relative to the
start of the linked program.
o The only object code modification necessary is the addition of an actual load
address to relative values within the program
se
Linking loader
.c
Linkage editor
w
15
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 9 Page 2 of 2
.in
be
tu
se
.c
w
w
For example:
INCLUDE PLANNER(PROGLIB)
DELETE PROJECT {DELETE from existing PLANNER}
INCLUDE PROJECT(NEWLIB) {INCLUDE new version}
REPLACE PLANNER(PROGLIB)
There are a large number of cross-references between these subroutines due to their closely related
functions.
16
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 9 Page 2 of 2
INCLUDE READR(FTNLIB)
INCLUDE WRITER(FTNLIB)
SAVE FTNIO(SUBLIB)
.in
Specification of external references not to be resolved by automatic library search
o Can avoid multiple storage of common libraries in programs.
o Need a linking loader to combine the common libraries at execution time
be
tu
se
.c
w
w
w
17
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 10 Page 2 of 2
Dynamic Linking
Comparison
o Linkage editors perform linking operations before the program is loaded for
execution
o Linking loaders perform linking operations at load time
o Dynamic linking (dynamic loading, load on call) perform linking at execution
.in
time
Delayed Binding
o Avoid the necessity of loading the entire library for each execution, i.e. load
be
the routines only when they are needed
o Allow several executing programs to share one copy of a subroutine or library
(Dynamic Link Library, DLL)
tu
O.S. services request of dynamic linking
o Dynamic loader is one part of the OS
o Instead of executing a JSUB instruction that refers to an external symbol,
se
the program makes a load-and-call service request to the OS
(b and c)
o When the called routine completes it processing, it returns to the caller (O.S.) (d)
o When call a routine and the routine is still in memory, O.S. simply passes the control
w
18
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 10 Page 2 of 2
.in
be
tu
se
.c
w
w
w
19
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period:11 Page 2 of 2
Bootstrap Loaders
.in
o Copy absolute loader in ROM into RAM for execution (optional)
o Read a fixed-length record from some device into memory at a fixed location. After
be
the read operation, control is automatically transferred to the address in memory
tu
se
.c
w
w
w
20
www.csetube.in
www.csetube.in
Lecture plan
Code & Name of subject: CS2304 System Software R/TP/01
Unit number & Name: UNIT III LOADERS AND LINKERS ISSUE: C REV: 00
Period: 12 Page 2 of 2
Implementation examples
Header information
o Header record
.in
o Object code
o Text record
Relocation information
o Modification record
Symbols
be
o Define record
o Refer record
Debugging information
End record
tu
MS-DOS Linker
se
Record
types Descripti
on SIC/XE
.c
LIDATA
GRPDEF
FIXUPP Relocation and linking information Modification record
MODEND End of object module End record
MS-DOS object module
.in
o Find a suitable area of memory.
o Create a PSP.
o Read in the program code immediately after the PSP.
be
o Set the stack point and segment registers.
o Jump to CS:100 to start the program.
DOS EXE Files: relocation
fixups.
tu
The DOS EXE files contain relocation entries, often called
Loading an EXE file is only slightly more complicated than
se
loading a COM file, requiring the following steps.
Read in the header and check the magic number for validity.
Find a suitable area of memory.
Create a PSP.
.c
22
www.csetube.in