Loader Design Options
Loader Design Options
Loader Design Options
1. Linkage Editors
2. Dynamic Linking
Linking Loader
• Performs all linking and relocation operations, including automatic library search
if specified, and loads the linked program into memory for execution.
• Suitable in the following situations:
(i) if a program is reassembled for nearly every execution; i.e., in a program
development or testing environment.
(ii) when a program is used so infrequently that it is not worth while to store
the assembled version in a library.
• Disadvantage:
Searches libraries and resolves external references every time the program is
executed.
Linkage editor
• The source program is first assembled and object program is produced.
• This object program is fed as input to the Linkage editor.
• Then it produces a linked program (often called a load module or an executable
image), which is written to a file or library for later execution.
• This load module is in a form suitable for processing by a relocating loader.
• All external references are resolved, and relocation is indicated by Modification
records or a bit mask.
• A simple relocating loader can be used to load the program into main memory for
execution.
• The only object code modification necessary is the addition of an actual load
address to relative values within the program.
• It performs relocation of all control sections relative to the start of the linked
program.
• Requires only one pass and no external symbol table is needed.
• Advantages:
(i) If a program is to be executed many times without being reassembled, the
use of a linkage editor substantially reduces the overhead required.
(ii) Resolution of external references and library searching are performed
only once.
Additional functions of Linkage editors
• Replacement of subroutines in the linked program.
• Build packages of subroutines that are generally used together.
• To specify external references that are not to be resolved by automatic
library search.
Linking Time
• Linkage editors : Before load time
• Linking loaders : At load time
• Dynamic linking : After load time
Dynamic Linking
• A scheme that postpones the linking function until execution time.
• A subroutine is loaded and linked to the rest of the program when it is first called.
• Other names: dynamic loading, load on call
• Advantages:
(i) allows several executing programs to share one copy of a subroutine or
library.
(ii) allows the implementation of the shared object and its methods to be
determined at execution time in an object- oriented system.
(iii) provides the ability to load the routines only when they are needed.
thereby resulting in saving both load time and memory space)
(iv) avoids the use of loading the entire library for each execution.
• Subroutines to be dynamically loaded must be called via an operating system
service request, e.g., load- and- call, instead of executing a JSUB instruction.
• The service request will be handled by a part of the OS, called the dynamic loader,
which is kept in memory during execution of the program.
Implementation Example
• Most MS- DOS assemblers produce object modules with file name extension .OBJ
• Each object module contains a binary image of the translated instructions and data
of the program.
• Also describes the structure of the program (e.g., the grouping of segments and the
use of external references in the program)
• MS- DOS LINK is a linkage editor that combines one or more object modules to
produce a complete executable program with file name extension .EXE
• A typical MS- DOS object module is given below.
• THEADR record specifies the name of the object module and MODEND record
marks the end of the module. These two correspond to the Header and End records
in SIC/XE.
• PUBDEF and EXTDEF corresponds to Define and Refer records in SIC/XE.
These are defined in the TYPEDEF record.
• LEDATA records are similar to SIC/XE Text records.
• FIXUPP records are similar to SIC/XE Modification records.
• LINK performs two passes.
Pass 1
- computes a starting address for each segment in the program.
- constructs a symbol table that associates an address with each segment and each
external symbol (performs library search also).
Pass 2
- LINK extracts the translated instructions and data from the object modules, and
builds an image of the executable program in memory.
- Processes each LEDATA and LIDATA record along with FIXUPP records
• After the memory image is complete, LINK writes it to the executable (.EXE) file.