0% found this document useful (0 votes)
191 views67 pages

SPCC - Module - 4 - Loaders and Linkers (NEW)

The document discusses loaders and linkers. It describes the functions of loaders as loading programs into memory, relocating programs so they can be loaded at different addresses, and linking separate programs together. Linkers combine object files into executable files and replace symbolic addresses with real addresses. The document outlines different types of loading schemes, including relocating loaders and direct linking loaders. It provides details on how relocating loaders work, including using relocation bits to indicate which half words need relocating.

Uploaded by

Priyen Dsouza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views67 pages

SPCC - Module - 4 - Loaders and Linkers (NEW)

The document discusses loaders and linkers. It describes the functions of loaders as loading programs into memory, relocating programs so they can be loaded at different addresses, and linking separate programs together. Linkers combine object files into executable files and replace symbolic addresses with real addresses. The document outlines different types of loading schemes, including relocating loaders and direct linking loaders. It provides details on how relocating loaders work, including using relocation bits to indicate which half words need relocating.

Uploaded by

Priyen Dsouza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

System Programming and Compiler

Construction
CSC 601

Subject Incharge
Varsha Shrivastava
Assistant Professor
email: [email protected]
Room No: 407

1
CSC 601 System Programming and
Compiler Construction
Module 4
Loaders and Linker

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 2
Contents as per syllabus

 Introduction
 Functions of loaders
 Relocation and Linking concept
 Different loading schemes
 Relocating loader
 Direct Linking Loader
 Dynamic linking and loading.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 3
Introduction

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 4
Linkers

• Linker is a computer program, which merges the object files


produced by separate compilation or assembly and creates
an executable file
• Takes input the object files (from assembler), combines them
together, and gives a single executable file as output.
• In addition to combining modules, a linker also replaces
symbolic addresses with real addresses. Therefore, you may
need to link a program even if it contains only one module.
• Links libraries with object files.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 5
Linker undergoes three task :
1. Searches the program to find library routines used by
program, e.g. printf(),sqrt(),strcat() etc.
2. Determines the memory locations that code from each
module will occupy and relocates its instructions by
adjusting absolute references. Relocation, which
modifies the object program so that it can be
loaded at an address different from the location
originally specified.
3. It combines two or more separate object programs and
supplies the information needed to allow references
between them

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 6
Linkers

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 7
Linkers

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 8
Loaders

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 9
Loaders

• Loader is a part of operating system and is


responsible for loading executable files into
memory and execute them.

• Takes input object program decks and prepares


them for execution.

• It initializes various registers to initiate execution.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 10
Loaders

C Program Building Process

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 11
Fundamental process (Function) of Loaders

• Loading – brings 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, which combines two or more separate object
programs and supplies the necessary information.
• Allocation - The space for program is allocated in the main
memory, by calculating the size of the program.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 12
Fundamental process (Function) of Loaders

• If a software does only Loading  Absolute Loader


• Loading + Relocation  Relocating Loader/ Relative
Loader
• Loading + Relocation + Linking  Linking Loader

• And if a software does only the task of Linking then


the software is called Linker

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 13
Types of Loader
• Compile and Go Loader
• General Loader Scheme
• Absolute Loader
• Relocating Loaders
• Direct linking Loaders
• Dynamic linking and loading.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 14
Types of Loader
• Example of Absolute Loader Program
Any Object Program contains 3 types of record
• Header Record (H Record)
• TEXT Record (T Record)
• END Record (E Record)

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 15
Loader-Relocating Loader

• Introduced to avoid reassembling of all subroutines


when a single subroutine is changed.

• Performs tasks of allocation and linking for


programmer.

• Each procedure is assembled independently and


the text and information for relocation and
intersegment references is passed on to the
loader.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 16
Loader-Relocating Loader

• Example – Binary Symbolic Subroutine (BSS) used in


IBM 7094, IBM 1130, GE 635 and UNIVAC 1108.

• Output of relocating loader using BSS scheme is


object program and information about all other
programs it references.

• Additionally, Information regarding change of


location in the program is present if it is to be loaded
arbitrarily in core i.e the location which are
independent on core allocation

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 17
Loader-Relocating Loader

• Example – Binary Symbolic Subroutine (BSS) used in


IBM 7094, IBM 1130, GE 635 and UNIVAC 1108.
• This loader allows many procedure or code segment but
only one data segment.
• Text , subroutines, variable  code segment
• Object files created along with its location  data segment
• Assembler assembles each procedure segment
independently and passes on to the loader the text and
the information and intersegment references. So output
of the assembler is object program and info about all
other programs it referenced.
• BSS loaders scheme is used on computers with fixed
length ‘Direct address instruction’.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 18
Loader-Relocating Loader

• For each source program, the assembler gives


output which contains text, prefixed by a transfer
vector.

• Transfer vector consists of addresses containing


names of subroutines referenced by source
program.

• Assembler also provides loader with length of the


program and length of the transfer vector position.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 19
Loader-Relocating Loader

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 20
Loader-Relocating Loader

Relocation Meaning
bits
01 Half word is relocated relative to the
procedure segment

10 Half word is relocated relative to the


address of the single common data
segment
00 or 11 Half word is not relocated

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 21
Loader-Relocating Loader

Note:
• For each external symbol the assembler generates
a four byte full word at the beginning of the
program, Containing EBCDIC characters for the
symbol
• But, for simplicity we assume symbols are not more
than 4 character long. These extra words are called
transfer vector
“Every reference to an external symbol is assigned
address of the corresponding transfer vector word”

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 22
Loader-Relocating Loader

Absolute Relative
Address Address
. .
. .
. .
400 0 BC 15,448
404 4 BC 15,526
408 8 ST 14,436
412 12 L 1,440
416 16 BAL 14,400
420 20 C 1,444
424 24 BC 7,404 Length = 48 bytes
428 28 L 4,436
432 32 BCR 15,14
436 36 (Temp Loc)
440 40 9
444 44 3
.
.
. SQRT Length = 78 bytes
.
526 ERR
.
.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 23
Loader-Relocating Loader

Pros:
Relocation bits are used to solve the problem of
relocation , transfer vector is used to solve the problem
of linking & program length info to solve allocation.
Cons:
Not suited for loading external data.
Transfer vector increases the size
Does not facilitate access to data segments that can
be shared

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 24
Loader-Direct Linking Loader

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 25
Loader-Direct Linking Loader
• External Symbol Directory(ESD) cards contain
information about all symbols that are defined in the
present program, but they may be referenced
somewhere.
• It contains
• Reference No.
• Symbol Name
• TYPE
• Relative Location
• Length

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 26
Loader-Direct Linking Loader
• External Symbol Directory(ESD) cards contain
information about all symbols that are defined in the
present program, but they may be referenced
somewhere.
• It contains
TYPE
• Reference No. SD- Segment Definition
• Symbol Name LD- Local Definition
ER-External Reference
• TYPE
• Relative Location
• Length

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 27
Loader-Direct Linking Loader
• The Text Cars(TXT) cards contains the actual object
code translated version of source program.
• The Relocation and linkage Directory (RLD) card
contains information about those locations in the
program whose contents depends on the address at
which program is placed.
• The RLD Cards contains the following information:-
• The location of each constants that needs to be changed
due to relocation
• By What it has to be changed
• The operation to be performed

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 28
Loader-Direct Linking Loader
• Format of RLD

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 29
Loader-Direct Linking Loader
• It is a general relocating loader and most popular
loading scheme.

• Allows programmer multiple procedure segments


and multiple data segments and giving complete
freedom in referencing data or instructions in other
segments.

• This provides flexible intersegment referencing and


accessing ability while allowing independent
translations of programs.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 30
Loader-Direct Linking Loader

• With each procedure or data segment, the


assembler must give the loader the following info –
• Length of the segment
• List of all the symbols and their relative location
• List of all the symbols not defined in the segment but
referenced in the segment
• Info as to where address constants are located in the
segment and description of how to revise their values
• Machine code translation of the source program and the
relative addresses assigned

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 31
Loader-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 32
Loader-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 33
Loader-Direct Linking Loader
• External Symbol Directory(ESD) cards contain
information about all symbols that are defined in the
present program, but they may be referenced
somewhere.It contains
• Reference No.
• Symbol Name
• TYPE
• Relative Location
• Length

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 34
Loader-Direct Linking Loader
• External Symbol Directory(ESD) cards contain
information about all symbols that are defined in the
present program, but they may be referenced
somewhere.
• It contains
TYPE
• Reference No. SD- Segment Definition
• Symbol Name LD- Local Definition
ER-External Reference
• TYPE
• Relative Location
• Length

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 35
Loader-Direct Linking Loader
• The Text Cars(TXT) cards contains the actual object
code translated version of source program.
• The Relocation and linkage Directory (RLD) card
contains information about those locations in the
program whose contents depends on the address at
which program is placed.
• The RLD Cards contains the following information:-
• The location of each constants that needs to be changed
due to relocation
• By What it has to be changed
• The operation to be performed

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 36
Loader-Direct Linking Loader
• Format of RLD

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 37
Loader-Direct Linking Loader
• It is a general relocating loader and most popular
loading scheme.

• Allows programmer multiple procedure segments


and multiple data segments thus giving complete
freedom in referencing data or instructions in other
segments.

• This provides flexible intersegment referencing and


accessing ability while allowing independent
translations of programs.

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 38
Loader-Direct Linking Loader

• With each procedure or data segment, the


assembler must give the loader the following info –
• Length of the segment
• List of all the symbols and their relative location
• List of all the symbols not defined in the segment but
referenced in the segment
• Info as to where address constants are located in the
segment and description of how to revise their values
• Machine code translation of the source program and the
relative addresses assigned

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 39
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 40
Example-Direct Linking Loader

Note :-
• Every instruction is of 4 bytes.
• PG1 occupies 59 bytes of memory
• PG2 occupies 36 bytes of memory

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 41
Example-Direct Linking Loader

ENTRY indicates internal variable,


PG1X, PG1Y
EXTERN indicates external variable
PG2X,PG2Y

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 42
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 43
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 44
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 45
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 46
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 47
Example-Direct Linking Loader
Same way for PG2 Procedure

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 48
Example-Direct Linking Loader
HOW PG1 and PG2 get loaded in Main Memory

• LENGTH OF PG1 is
104+60=164
• LENGTH OF PG2 is
168+36
• Card 6 to 10 will be
loaded in Main
memory

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 49
Example-Direct Linking Loader
HOW PG1 and PG2 get loaded in Main Memory

104+20 =124
(104+30)+15 =149
(104+30)-(104+20)-3 =7
PG2= 168
(168+16)+168-(104+20)+4 =232

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 50
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 51
Example-Direct Linking Loader

St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 52
Example-Direct Linking Loader

LESA the contents of PG1


St. Francis Institute of Technology 09 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 53
Loader- Dynamic Loading

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 54
Loader- Dynamic Loading

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 55
Loader- Dynamic Loading

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 56
Loader- Dynamic Loading

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 57
Loader- Dynamic Loading

Subroutine calls between the procedure

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 58
Loader- Dynamic Loading

Possible storage assignment of each procedure

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 59
Loader- Dynamic Linking

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 60
Loader- Dynamic Loading & Linking

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 61
How does loader gets loaded
?

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 62
Answer: Bootstrap Loader

A bootstrap loader is a computer program that


loads the main operating system or runtime
environment for the computer after completion of
self-tests.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 63
Bootstrap Loader
• Also known as bootstrapping, boot loader or boot
program.

• Program that resides in non-volatile memory.

• Resides in the MBR (master boot record).

• Automatically executed by processor when switching on


the system after basic BIOS checks.

• It reads the boot sector to load OS.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 64
Bootstrap Loader

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 65
University Questions

Q.1 Explain various functions of Loader.


Q.2 Explain the working of Direct Linking Loader in
detail
Q.3. With reference to design of Direct Linking Loader
explain the following cards with suitable examples.
(i) ESD (ii) RLD (iii) TXT (iv) END
Q.4 Explain the relocation and linking concept and
enlist various Loading Schemes
Q.5 Write a short note on Dynamic Linking and
Loading.

St. Francis Institute of Technology 5 Apr 2022 CSC 601:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 66
THE
END!
Have a nice
day!

You might also like