0% found this document useful (0 votes)
47 views28 pages

Understanding Loaders and Linking Concepts

The document discusses different types of loaders and their functions. It describes absolute loaders, relocating loaders, and dynamic linking loaders. It also explains the differences between linkers and loaders, as well as the concept of bootstrapping.

Uploaded by

Sakshi Pawar
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)
47 views28 pages

Understanding Loaders and Linking Concepts

The document discusses different types of loaders and their functions. It describes absolute loaders, relocating loaders, and dynamic linking loaders. It also explains the differences between linkers and loaders, as well as the concept of bootstrapping.

Uploaded by

Sakshi Pawar
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

[ 4.

Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

In the previous chapter, the user’s source program decks are usually
converted to object program decks ( machine language) by assemblers
and compilers.

The loader is a program which accepts the object program decks,


prepares these programs for execution by the computers, and
initiates the execution.

The loader must perform four functions :

1. Allocate space in memory for the object programs . (allocation).

2. It combines two or more separate object programs and resolve


symbolic references between object decks. (linking).

3. Adjust all address dependent locations, such as address


constants, to correspond to the allocated space. (relocation).

4. Physically place the machine instructions and data into memory.


(loading).

Most of the examples are based on IBM System/370 assembler and


loader. For simplicity of presentation, we assume card deck inputs –

1
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

these of course may actually be card images on tape or any secondary


storage.

LINKER :

A “LINKER” or link editor is a program that takes a collection of object


modules (created by compilers or assemblers) and combines them
into a single executable program. A Loader places the linked program
in main memory.

Difference between Linker and Loader.

Linker Loader
It’s a computer program, that takes
one or more object files generated by It’s a program that loads
a compiler and combines them into a machine codes of a program
single executable file, library file, or into the system memory.
another object file.
Loader is a part of an
Linker is a part of a library files.
operating system.
It loads the program for
It performs the linking operations.
execution.
Loading a program involves
It also links the user defined functions
loading the contents of
to the user defined libraries.
executable file into memory

TYPES OF LOADERS :

These loaders primarily differ in the manner in which the four basic
functions are accomplished.

1. Compile-and-Go Loader :

The assembler run in one part of memory and place the assembled
machine instructions and data, as they are assembled, directly into
their assigned memory locations.

2
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

When the assembly is completed, the assembler causes a transfer to


the starting instruction of the program. This is a simple solution,
involving no extra procedures.

Such a loading scheme is commonly called “compile-and-go” or


“assembler-and-go”. It is relatively easy to implement.

The assembler simply places the code into core, and the “loader”
consists of one instruction that transfers to the starting instruction of
the newly assembled program.

Advantage:

1. Simple to implement.
2. No extra procedures involved.

However there are several apparent disadvantages.

1. A portion of memory is wasted. [because the core occupied by


the assembler is unavailable to the object program].

2. It is necessary to retranslate (assemble) the user’s program deck


every time it is run.

3
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

3. It is very difficult to handle multiple segments, especially if the


source programs are in different languages (e.g., one subroutine
in assembly language and another subroutine in FORTRAN or
PL/I).

2. General Loader Scheme :

The problem of wasting core for the assembler, can be removed if an


output can be saved and loaded whenever the code is to be executed.
The assembled programs could be loaded into the same area in core
that the assembler occupied. ( as the translation has been completed).
This output form, may be a coded form of the instructions, called an
object deck.

The use of an object deck as intermediate data to avoid one


disadvantage of the preceding “compile-and-go” scheme requires the
addition of a new program to the system, a loader.

The loader accepts the assembled machine instructions, data, and


other information present in the object format, and places machine
instructions and data in core in an executable computer form.

4
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

The loader is assumed to be smaller than the assembler, so that more


memory is available to the user.

A further advantage is that, re-assembly is no longer necessary to run


the program at a later date.

3. Absolute Loaders :

In this scheme the assembler outputs the machine language


translation of the source program in almost the same form as in the
“assemble-and-go” scheme, except that the data is punched on cards
(object deck) instead of being placed directly in memory. The Loader
in turn simply accepts the machine language text and places it onto
core at the location prescribed by the assembler. This scheme makes
more core available to the user since the assembler is not in memory
at load time.

Absolute loaders are simple to implement but they do have several


disadvantages.

1. The programmer must specify to the assembler the address in


core where the program is to be loaded. Furthermore, if there are
multiple subroutines, the programmer must remember the address of
each and use that absolute address explicitly in his other subroutines
to perform subroutine linkage.

The below figure illustrates the operation of an absolute assembler


and an absolute loader. The programmer must be careful not to
assign two subroutines to the same or overlapping locations.

5
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

The MAIN program is assigned to locations 100-247 and the SQRT


subroutine is assigned locations 400-477. 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 by changing
its START pseudo-op card and reassembling it. Furthermore, it would
also be necessary to modify all other subroutines that referred to the
address of SQRT. In situations where dozens of subroutines are being
used his manual “shuffling” can get very complex, tedious, and
wasteful of core.

In an absolute loading scheme, the four loader functions are


accomplished as follows :

1. Allocation - by programmer.

2. Linking - by programmer.

3. Relocation - by assembler.

4. Loading - by loader.

Bootstrap Loader:

6
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

It is an absolute loader. When the computer is first powered on, it


does not have an operating system in memory. The computer cannot
load a program from the disk. This is done by Bootstrap Loader. Its
job is to load software for the operating system to start. The name
comes from the image of pulling one oneself up by ones bootstraps.

A bootstrap loader is a program that resides in the computer EPROM,


ROM or other non-volatile memory that automatically executed by
the processor when turning on the computer. The bootstrap loader
reads the hard drives boot sector to continue the process of loading
the computers operating system. The term bootstrap comes from the
old phrase “Pull yourself up by your bootstraps.” It is also known as
bootstrapping or boot loader.

The basic functions of bootstrap loader are as following:

- It helps to select an operating system for starting.


- It loads the operating system files from the boot partition.
- It controls the operating system selection and hardware
detection prior to the kernel initialization.

In computing, bootstrapping is a technique by which a simple


computer program activates a more complicated system of programs.

Bootstrapping :

Action taken when a computer is first powered on.

- The hardware logic reads a program from address 0 from ROM.


. ROM is installed by the manufacturer.
ROM contains bootstrapping program and some other routines
that controls hardware. (eg. BIOS).

Bootstrapping in a loader :

Loads operating system from disk into memory and makes it run.

The location of OS on disk usually starts at the first sector.

7
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

Starting address in memory is usually fixed to 0.

( no need to relocation).

Relocating loader :
It is used to avoid reassembling of all subroutines when a subroutine
is changed and to execute tasks of allocation and linking for
programmer. It adjust addresses of the executable code to
compensate for variations in the address at which loading starts. The
computers which need relocating loaders are those in which pointers
are absolute addresses rather than offset from the programs base
address. Binary Symbolic Subroutine (BSS) loader is an example of
Relocating Loader. BSS performs all the four functions of the loader.

- Allocation : done by the program length and the information.


- Linking : done by transfer vector.
- Relocation : done with the help of relocation bits.
- Loading : done by loader.

[ the transfer vector is used only for transfers and not used for loading
or storing of external data. The size of the object program in the
memory is increased due to transfer vector. ]

6. Direct Linking Loaders :


It is a general relocatable loader, and is perhaps the most popular
loading scheme presently used.

The Direct-linking loader has the advantage of allowing the


programmer multiple procedure segments and multiple data
segments and of giving him complete freedom in referencing data or
instructions contained in other segments. This provides flexible

8
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

intersegment referencing and accessing ability, while at the same time


allowing independent translations of programs.

The assembler (translator) must give the loader the following


information with each procedure or data segment:

1. The length of segment.


2. A list of all the symbols in the segment that may be referenced
by other segments and their relative location within the
segment.
3. A list of all symbols not defined in the segment but referenced in
the segment.
4. Information as to where address constants are located in the
segment and a description of how to revise their values.
5. The machine code translation of the source program and the
relative addresses assigned.

DESIGN OF DIRECT LINKING LOADER :

The original source program nor the assembler symbol table is


available to the loader. Therefore the object deck must contain all
information needed for relocation and linking.

There are four sections to the object deck ( four card formats):

1. External Symbol Dictionary (ESD).


2. Instructions and data cards, called “text” of program (TXT).
3. Relocation and Linkage Directory (RLD).
4. End card (END).

There are three types of external symbols.

1. Segment Definition (SD) – name of START or CSECT card.


2. Local Definition (LD) – specified on entry card. There must be a
label in same program with same name.

9
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

3. External reference (ER) – specified on EXTRN card. There must


be a corresponding ENTRY, START or CSECT card in another
program with same name.

Each SD and ER symbol is assigned a unique number (e.g. 1,2,3,…..) by


the assembler. This number is called symbols identifier, or ID, and is
used in conjunction with the RLD cards.

The TXT cards contain blocks of data and the relative address at which
the data is to be placed. Once the loader has decided where to load
the program, it merely adds the Program Load Address (PLA) to the
relative address and moves the data into the resulting location. The
data on the TXT card may be instructions, non-relocated data, or
initial values of address constants.

The RLD card contain the following information.

1. The location and length of each address constant that needs to


be changed for relocation or linking.
2. The external symbol by which the address constant should be
modified ( added or subtracted).
3. The operation to be performed ( add or subtract).

The END card specifies the end of the object deck. If the assembler
END card has a symbol in the operand field, it specifies a start of
execution point to the entire program (all subroutines). This address
is recorded on the END card.

There is final card required to specify the end of a collection of object


decks. The 360 loaders usually use either a loader terminate (LDT) or
End of File (EOF) card.

Refer the simple programs PG1 and PG2 in the below figure:

It illustrate a wide range of relocation and linking situations. The table


displays the ESD, TXT and RLD cards (records) produced by the
assembler for PG1 and PG2.

10
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

Procedure PG1 :

PG1ENT1 and PG1ENT2 are symbols internal to PG1. They have to be


specified on ENTRY card. These should be used as labels in same
program with same name.

PG2ENT1 and PG2 are symbols external to PG1. There must be a


corresponding ENTRY, START or CSECT card in another program with
same name.

11
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

Procedure PG2 :

PG2ENT1 symbol is internal to PG1. They have to be specified on


ENTRY card. These should be used as labels in same program with
same name.

PG1ENT1 and PG1ENT2 are symbols external to PG2. There must be a


corresponding ENTRY, START or CSECT card in another program with
same name.

12
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

13
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

14
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

Figure shows the main storage after the programs have been
allocated space, relocated, linked, and loaded.

A few specific points in these examples should be noted. Both PG1


and PG2 contain an address constant of the form A(PG1ENT2 –
PG1ENT1 - 3).

It should be reassuring to note in figure 5.15 that both instances of


this address constant (location 152, 200) has the same value – 7.
Since both PG1ENT2 and PG1ENT1 are symbols internal to PG1, the
assembler, processing PG1, can compute the entire expression and
determine the value of 7. We see in fig. 5.13, that the TXT card for
location 48-51 contains the 7 and there are no associated RLD cards
for this address constant.

On the other hand these symbols are external to PG2; thus, the
assembler, while processing PG2, has no means for evaluating the
address constant. This is illustrated in fig. 5.14. the TXT card for
relative locations 32-35 contains a -3, the only part of the address
constant that can be calculated by the assembler. The last two RLD
cards tell the loader to add the value of ID 03, which is PG1ENT2, to
location 32 – 35 and then subtract the value of id 02, which is
PG1ENT1. When processed by the loader, this address constant in
PG2 will indeed have the same value as the one in PG1.

Since the direct-linking loader may encounter external references in


an object deck which cannot be evaluated until a later object deck is
processed, this type of loader requires two passes.

Their functions are very similar to those of the two passes of an


assembler. The major function of pass 1 of a direct-linking loader is to
allocate and assign each program a location in core and create a
symbol table filling in the values of the external symbols.

15
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

The major function of pass 2 is to load the actual program text and
perform the relocation modification of any address constants needing
to be altered.

The first pass allocates and assigns storage locations to all segments
and stores the values of all external symbols in a symbol table. These
external symbols appear as local definitions on the ESD cards of
another assembled program. For every external reference symbol
there must be a corresponding internal symbol in some other
program. The loader inserts the absolute address of all of these
external symbols in the symbol table.

In the second pass, the loader places the text into the assigned
locations and performs the relocation task, modifying re-locatable
constants. Figure 5.16 depicts the interplay between the passes of a
loader in a direct linking loading scheme.

Specification of Data Structures:

Pass 1 data bases:

1. Input object decks.

2. The Initial Program Load Address (IPLA) supplied by the


programmer or the OS, that specifies the address to load the first
segment.

3. A Program Load Address (PLA) counter, used to keep track of


each segments assigned location.

4. The Global External Symbol Table (GEST), that is used to store


each external symbol and its corresponding assigned core address.

5. Output of pass 1 is used as input for pass 2. These may be


stored on magnetic tape, disk or drum.

16
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

6. A printed listing, the load map, that specifies each external


symbol and its assigned value.

Pass 2 Data bases :

1. Output of pass 1 is used as input for pass 2.

2. The Initial Program Load Address parameter (IPLA) from pass 1.

3. Program Load Address counter prepared by pass 1.

4. The Global External Symbol Table (GEST) prepared by pass1,


containing each external symbol and its corresponding absolute
address value.

5. An array, the Local External Symbol Table Array (LESA), which is


used to establish a correspondence between the ESD ID numbers,
used on ESD and RLD cards, and the corresponding external symbols
absolute address value.

GLOBAL EXTERNAL SYMBOL TABLE :

The Blobal External Symbol Table (GEST) is used to store the external
symbols defined by means of a Segment Definition (SD) or Local
Definition (LD) entry on an External Symbol Dictionary (ESD) card.
When these symbols are encountered during pass 1, they are assigned
an absolute core address; this address is stored, onloing with the
symbol, in the GEST. ( in figure 5.22).

LOCAL EXTERNAL SYMBOL ARRAY :

The external symbol to be used for relocation or linking is identified


on the RLD cards by means of an ID number rather than the symbols
name. The ID number must match an SD or ER entry on the ESD
cards. This technique both saves space on the RLD cards and speeds

17
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

processing by eliminating many searches of the Global External


Symbol Table.

It is necessary to create a separate LESA for each segment, but since


the LESA are only produced one at a time, the same array can be
reused for each segment. Figure 5.23 depicts the format of the Local
External Symbol Array (LESA).

ALGORITHM :

PASS 1 : Allolcate segments and define symbols.

The purpose of the first pass is to assign a location to each segment,


and thus to define the values of all external symbols.

It is necessary for the loader to know where it can load the first
segment. This address, the Initial Program Load Address (IPLA), is
normally determined by the operating system.

In some systems the programmer may specify the IPLA; in either case
we will assume that the IPLA is a parameter supplied to the loader.

Initially, the Program Load Address (PLA) is set to the Initial Program
Load Address (IPLA).

An object card is then read and a copy written for use by pass 2.

The card can be one of five types, ESD, TXT, RLD, END, or LDT/EOF.

If it is a TXT or RLD card, there is no processing required during pass 1


so the next card is read.

An ESD card is processed in different ways depending upon the type


of external symbol, SD, LD or ER.

If a segment definition ESD card is read, the length field, LENGTH,


from the card is temporarily saved in the variable, SLENGTH. The

18
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

value, VALUE, to be assigned to this symbol is set to the current value


of the PLA.

The symbol and its assigned value are then stored in the GEST; if the
symbol already existed in the GEST, there must have been a previous
SD or LD ESD with the same name – this is an error.

The symbol and its value are printed as part of the load map.

A similar process is used for LD symbols; the value to be assigned is


set to the current PLA plus the relative address, ADDR, indicated on
the ESD card.

The ER symbols do not require any processing during pass 1.

When an END card is encountered, the program load address is


incremented by the length of the segment and saved in SLENGTH,
becoming the PLA for the next segment.

When the LDT or EOF card is finally read, pass 1 is completed and
control transfers to pass 2.

PASS 2 : load text and relocate/link address constants.

After all the segments have been assigned locations and the external
symbols have been assigned locations and the external symbols have
been defined by pass 1, it is possible to complete the loading by
loading the text and adjusting (relocation or linking) address
constants.

At the end of pass 2, the loader will transfer control to the loaded
program.

The following simple rule is often used to determine where to


commence execution :

1. If an address is specified on the END card, that address is used as

19
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

the execution start address.


2. Otherwise, execution will commence at the beginning of the first
segment.

At the beginning of pass 2 the program load address is initialized as in


pass 1, and the execution start address (EXADDR) is set to IPLA. The
cards are read one by one from the object deck file left by pass 1.
Each of the five types of cards is processed differently, as follows :

ESD CARD : Each of the ESD card type is processed differently.

SD – type ESD : The LENGTH of the segment is temporarily saved in


the variable SLENGTH. The appropriate entry in the local external
symbol array, LESA(ID), is set to the current value of the Program Load
Address.

LD – type ESD : it does not require any processing during pass 2.

ER – type ESD : The Global External Symbol Table (GEST) is searched


for a match with the ER symbol. If it is not found, the corresponding
segment or entry must be missing – this is an error. If the symbol is
found in the GEST, its value is extracted and the corresponding Local
External Symbol Array entry LESA(ID), is set equal to it.

TXT CARD : When a TXT card is read, the text is copied from the card
to the appropriate relocate core location (PLA + ADDR).

RLD CARD : the value to be used for relocation and linking is extracted
from the local external symbol array as specified by the ID field, i.e.,
LESA(ID). Depending upon the flag setting ( plus or minus) the value is
either added to or subtracted from the address constant. The actual
relocated address of the address constant is computed as the sum of
the PLA and the ADDR field specified on the RLD card.

20
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

END CARD : if an execution start address is specified on the END card,


it is saved in the variable EXADDR after being 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 /EOF CARD : The loader transfers control to the loaded program
at the address specified by current contents of the execution address
variable (EXADDR).

21
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

22
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

23
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

24
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

25
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

Dynamic Loading Loader :

If all the subroutines are loaded simultaneously into the core, there
may be a chance that the core available might be insufficient for the
subroutines, which might lead to complication. Execution of such
program is possible, if all the segments are not required
simultaneously to be present in the memory. So the segments
needed are kept in memory, which is required at the time of
execution.

What will happen, if the segment required, is not in memory?


Naturally the execution will be delayed, until the required segment
gets loaded in memory.

Overlay structure is used to specify the inter dependency between all


the segments. It consists of nodes and edges and segment is
represented by the nodes. If the two are on the same path they can
lie in the main memory. For solving such problems techniques like
segmentation and paging is used. In these the subroiutines are loaded
into core at a different time because the subroutines in a program are
needed at different times.

Overlay structure is used to :

Keep the instructions and data in memory, that are needed at any
given time.

Overlay structure is needed when process is larger than the amount of


memory allocated to it.

Implemented by user, no special support needed from operating


system.

The flipper or overlay supervisor is the portion of the loader that


actually intercepts the “calls” and loads the necessary procedure.

26
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

PROG2 and PROG4 are never in use at the same.

Advatage :

No wastage of memory.

A system can be dynamically loaded,


whenever it is required.

Dynamic Linking Loader :

It’s a special part of operating system that loads external shared


libraries into a running process and then binds those shared libraries
dynamically to the running process. This approach is called as
dynamic linking or late linking.

It retrieves the address of function and variables contained in the


library, execute those functions or access those variables, and unload
the library from memory.

It is often used to allow several executing programs to share one copy


of a subroutine or library.

It provides the ability to load the routines only when they are needed,
so lot of time and memory is saved if subroutines are large with lots of
external references.

27
[ 4. Introduction, functions of loaders, Relocation and Linking concept, Different loading schemes : Relocating loader, Direct
Linking Loader, Dynamic Linking and loading. [ Hr - 8 ]

It helps in not loading the entire library for execution.

In dynamic linking, the loader is used to load the main program.

Implementation : - Dynamic Link Library or DLL, is Microsoft’s


implementation of the shared library concept in Microsoft Windows.

Difference :

Dynamic Loading Dynamic Linking


It refers to mapping an executable It refers to associating their
or library into a process’s memory names with addresses or offset –
after it has started. at compile time.
It is similar to plugin (exe) that can
The linker while creating the exe
actually execute before thedoes minimal work. For that, it
dynamic loading happens. has to load the libraries.
It is concerned with loading the It is concerned with linking library
subroutines of a program as and routines at run-time, instead of
when required during run-time, combining them with the
instead of loading all the executable program code before
subroutines before the execution the program execution starts. To
starts. achieve this, a small code called
“stub” is used, to find the routine,
if it is not in main memory.
Efficient use of memory. Efficient use of memory.
It does not require special support It requires special support from
from operating system; it is the operating system, the routine
responsibility of the programmer. loaded through dynamic linking
can be shared across various
processes.

28

You might also like