0% found this document useful (0 votes)
10 views

Chapter 4 Loader and Linker

rf ggwtr g
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Chapter 4 Loader and Linker

rf ggwtr g
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Chapter 4

Loaders
Loaders
• A loader is a system program that performs the
loading function.
– many also support relocation & linking
– others have a separate linker and loader
• Basic Functions
– bringing an object program into memory
– starting its execution
Input
• Object program:
– contains translated instructions and data from the
source program.
– specifies addresses in memory where these items
are to be loaded.
Basic 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
Basic Functions
• Relocation: Adjust all address dependent
locations, such as address constants, to
correspond 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
Basic Functions
Figure- Role of Linker and Loader
Loader Schemes
Segment is a unit of information treated as an entity.
It can be a program or data.
1. Compile and Go
– 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
– When the assembly is completed, the assembler
causes a transfer to the starting instruction of the
program
• Advantage
– simple
• Disadvantage
– Portion of memory wasted
– whenever the assembly program is to be
executed, it has to be assembled again
– Difficult to handle multiple segments
– programs have to be coded in the same
language
2. General Loader Scheme
- The loader accepts assembled machine
instructions, data & other information present in
object format
- Places machine instructions, data in core in an
executable form.
Advantage
- Saves memory in core.
- No need of retranslation
3. Absolute Loader
• The operation of absolute loader is very simple.
• The object code is loaded to specified locations
in the memory.
• At the end the loader jumps to the specified
address to begin execution of the loaded program.
Absolute Loader
Disadvantages
• If changes were made to MAIN that increased
its length to more than 300 bytes
– the end of MAIN (at 100 + 300 = 400) would
overlap the start of SQRT (at 400)
– It would then be necessary to assign SQRT to a
new location
• changing its START and re-assembling it?!
• Furthermore, it would also be necessarily to
modify all other subroutines that referred to
the address of SQRT.
Disadvantages of Absolute Loaders
• Actual load address must be specified
• The programmer must be careful not to assign
two subroutines to the same or overlapping
locations
• Difficult to use subroutine libraries (scientific
and mathematical) efficiently
– important to be able to select and load exactly
those routines that are needed
Loader functions are accomplished as follows
in the absolute loader
• Allocation - by programmer
• Linking - by programmer
• Relocation - by assembler
• Loading - by loader
4. Subroutine Linkages
• The main program A wishes to transfer to
subprogram B.
• The programmer, in program A, could write a
transfer instruction (e g, BAL 14,B) to
subprogram B.
• The assembler does not know the value of this
symbol reference and will declare it as an
error.
Externals and Entries
• The assembler pseudo-op EXTRN followed by
a list of symbols indicates that the symbols are
defined in other programs but referenced in the
present program
• If a symbol is defined in one program and
referenced in others,
– insert it into a symbol list following the pseudo-op
ENTRY.
5. Relocating Loaders
Relocating loaders or relative loaders:
– loaders that allow for program relocation.
– 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 as part of the
object program:

• 1. A Modification record
– describe each part of the object code that must be
changed when the program is relocated
• 2. Bit mask: A relocation bit/byte associated with
each word of object code
– S for Absolute: does not need modification
– R for Relative: needs relocation
– X for external
Design of Absolute Loader

Two types of information is passed in object deck


From assembler to loader
1. Machine instructions that assembler has created
along with the assigned core location.
2. The entry point of the program.(where to transfer
control when all instructions are loaded)
Text cards(for instructions and data)
Card Column Contents
1 card type=0(for text card
identifier)
2 Count of number of bytes(a
byte per column) of
information on card

3-5 Address at which data on card


is to be put
6-7 Empty(could be used for
validity checking)
8-72 Instructions and data to be
loaded
73-80 Card sequence number
Transfer cards(to hold entry point to program)
Card Column Contents

1 card type=1(for transfer card


identifier)

2 Count=0

3-5 Address of entry point

6-72 Empty

73-80 Card Sequence number


Figure. Absolute Loader
Source Program
DLL encounters external references in an object deck
which can not be evaluated until a later object deck is
processed. Therefore DLL requires two passes.
• Pass 1
– Allocate and assign each program location in
core.
– Create a symbol table filling in the values of the
external symbols.
• Pass 2
– Load the actual program text.
– Perform the relocation modification of any
address constants needing to be altered.
– Resolve external references. (linking)
Data Structures
Pass 1:
1. Input object decks.
2. Initial Program Load address(IPLA) supplied by
programmer or operating system,specifies the address
to load the first segment.
3. A Program Load Address(PLA) count,used to keep
track of each segment’s assigned location.
4. The Global External Symbol Table(GEST),used to
store each external symbol & it’s assigned core
address.
5. A copy of input to be used later by pass 2.
6. A printed list.ing, the Load map, specifies each
external symbol and it’s value.
Data Structures
Pass 2:
1. Copy of object programs inputted to pass 1.
2. Initial Program Load address(IPLA).
3. A Program Load Address(PLA).
4. The Global External Symbol Table(GEST), prepared
by pass 1,containing each external symbol & its
corresponding absolute address value.
5. An array, the Local External Symbol
Array(LESA),which is used to establish a
correspondence between the ESD ID numbers, used
on ESD & RLD cards & the corresponding external
symbol’s absolute address value
Format of Data Bases
• Global External Symbol Table
The Global External Symbol Table(GEST),used
to store the external symbols defined by means
of Segment Definition(SD) or Local Definition
(LD) entry on ESD card.
ESD card Format
TXT format
RLD Format
END card Format
LESA Format
PASS 1
• It is used to minimize the amount of core storage
required for the total program.
• Assign each segment to next available location after
the preceding segment.
• The Program Load Address is set as Initial Program
Load Address(IPLA).
PASS 2
Design of Direct Linking Loader
Algorithm
• Pass 1
– Allocate Segments
• Initial Program Load Address (IPLA)
• Assign each segment the next table location after the
preceding segment.
– Define Symbols
• SD
• LD
• ER?!
Pass 2: load text and relocate/link
• ESD record types is processed differently.
– SD The LENGTH of the segment is temporarily
saved in the variable SLENGTH.
– LD does not require any processing during pass 2.
– ER The Global External Symbol Table (GEST) is
searched for match with the ER symbol
– If found in the GEST, its value is extracted and
corresponding LESA(ID) is set equal to it
– If it is not found  error
Pass 2
• TXT: the text is copied from the record to the
relocated core location (PLA + ADDR).
• RLD: The value to be used for relocation and
linking is extracted from the LESA(ID)
– If Flag is Plus the value is added, if Flag is minus
the value is subtracted from the address constant
• The relocated address of the address constant
is the sum of the PLA and the ADDR field
specified on the RLD record.
Pass 2
• END: The execution start address is relocated
by the PLA
– The Program Load Address is incremented by the
length of the segment and saved in SLENGTH,
becoming the PLA for the next segment.
• LDT/E0F record
– The loader transfers control to the loaded
program at the address specified by current
contents of the execution, address variable
(EXADDR)
Disadvantages of Direct Linking
• It is necessary to allocate, relocate, link, and
load all of the subroutines each time in order
to execute a program
– loading process can be extremely time consuming.
• Though smaller than the assembler, the loader
absorbs a considerable amount of space
– Dividing the loading process into two separate
programs a binder and a module loader can solve
these problems.
Binder
• A binder is a program that performs the same
functions as the direct linking loader
– allocation, relocation, and linking
• Outputs the text in a file rather than memory
– called a load module.
• The module loader merely has to physically
load the module into memory.
Binder Classes
• Core image builder:
– Produces a load module that looks very much like
a "snapshot" or "image" of a section of core,
– Called Core image module.
• Link editor, can keep track of the relocation
Information
– The load module can be further relocated
– The module loader must perform allocation and
relocation as well as loading
– No linking.
Disadvantage
• If a subroutine is referenced but never
executed
– if the programmer had placed a call statement in
the program but was never executed because of a
condition that branched around it
– the loader would still incur the overhead or
linking the subroutine.
• All of these schemes require the programmer
to explicitly name all procedures that might be
called.
Dynamic Loading
• If the total amount of memory required by all
subroutines exceeds the amount available
• The module loader loads the only the
procedures as they are needed.
– Allocating an overlay structure
• The Flipper or overlay supervisor is the
portion of the loader that actually intercepts
the "calls" and loads the necessary procedure.
Example
• Suppose a program consisting of five
subprograms (A{20k},B{20k}, C{30k}, D{10k},
and E{20k}) that require 100K bytes of core.
– Subprogram A only calls B, D and E;
– subprogram B only calls C and E;
– subprogram D only calls E
– subprogram C and E do not call any other routines
• Note that procedures B and D are never in
used the same time; neither are C and E.
Longest Path Overlay Structure
100k vs 70k needed

A B C
20K 20K 30K

D E
10K 20K
Dynamic Linking
• The loading and linking of external references
are postponed until execution time.
• The loader loads only the main program
• If the main program should
– execute a branch to an external address,
– reference an external variable
• The loader is called
– Only then has the segment containing the external
reference loaded.

You might also like