You are on page 1of 41

Linkers and Loader

• Loader is program which accepts the object program


and prepares it for executions (Loads into Memory)

• Function of Loader
1. Allocation  Allocates space in Memory for Program
2. Linking  Resolves symbolic references between objects
codes
3. Relocation  Adjust all the address dependent locations
4. Loading  Physically place M/C instructions and data into
memory
Linkers and Loaders

Loading Schemes to be discussed

 Compile / Assemble and go loader


 Absolute Loader
 Relocating Loaders
 Direct- Linking Loaders
Assemble and Go Loader

• Assembler runs in memory and loaded assembled


M/C instructions and data as they are assembled.
• Directly placed into memory at assigned location.
• At end, assembler executes transfer instruction to
transfer control of executions at first line of M/C
code.
Assemble and Go Loader

• Advantages
– Simple to design
– Only one transfer instruction as a part of loader

• Disadvantages
– Memory wasted for holding assembler
– Necessary to re-translate code every time
– Source program need to be in one language only.
Assemble and Go Loader
General Loader Scheme

• Object program is already created


• Object code can be loaded whenever it is to be executed.
• System program known as loader must be there in the
memory
• It accepts all object programs and places them in
memory for execution.
• Loader is smaller than assembler in size.
General Loader Scheme
General Loader Scheme

• Advantages
– No need of re-assembling of program at every execution
– Assembler need not be in memory
– Subroutines can be written in several languages
Absolute Loader

• Simplest type of General Loader Scheme


• The assembled code is stored on Secondary storage
• The absolute loader simply accepts the object code
and places it in the main memory at the location pre-
described by assembler.
• More memory is available to user as assembler is
not in memory
Absolute Loader

• Advantage
– Simple to implement

• Dis-advantage
– Programmer has to specify the physical address to
assembler where object code is to be loaded.
– Programmer should remember address of each subroutine
– Programmer should use those addresses explicitly to call
those functions.
– Programmer should take care of non-conflicting subroutine
address.
Absolute Loader
Absolute Loader
Absolute Loader

• Four loader function accomplished by


– Allocation  programmer
– Linking  Programmer
– Relocation  Assembler
– Loading  :Loader
Subroutine Linkages

• Main program A wants to transfer control to


subroutine B.
• Assembler does not understand call to B as B is not
defined in program A.

• To resolve such linking problems (symbolic


references) pseudo opcodes EXTRN and ENTRY
are used Relocating / DLLs loaders.
Subroutine Linkages

• EXTRN indicates assembler that these symbols are


referenced in this program but defined in some other
program.

EXTRN list of symbols

• ENTRY informs the assembler that these symbols


are defined here but may be referenced in other
programs.

ENTRY list of symbols


Subroutine Linkages

• Example:
MAIN START
EXTRN SUBROUT
----------
----------
L 15, =A(SUBROUT)
BALR 14, 15
-----------
END
Subroutine Linkages

SUBROUT START
USING *,15
----------
BR 14
END
Subroutine Linkages

• Example ENTRY

A START
ENTRY B1, B2, B3,….Bn
(entry points in subroutine)
-----------
B1 -------
B2 -------
END
Relocating Loaders
• Purpose:
– To reduce efforts of programmer to allocate and link the
object codes.
– To avoid re-assembling of all subroutines even if one is
modified.
• Assembler assembles every routine independently.
• Assembler has to provide object code and other
information to the loader to support the loader
functionalities.
• Binary Symbolic Subroutine is simple example of
relocating loader.
• It is used with system having fixed-length direct
address instruction
• BSS allows many procedure segments and one data
segment.
Relocating Loaders
Relocating Loaders
Relocating Loaders

• The Relocating assembler has to provide object


code and relocating and linking information to the
Loader.
– Length of program for Allocation.
– Transfer vector for Linking
– Relocation Bits for Relocation
– Object codes for Loading.
• Allocation:
– Program Length, Transfer Vector length is determined by
Assembler.
– All subroutines referenced in program must be allocated
space in memory.
Relocating Loaders
• Linking:
– Transfer vector is part of object code generated by
assembler.
– It contains symbolic name/references to all subroutines
referenced in the program.
• How linking is done?
– Call to function becomes a transfer instruction that passes
control to Transfer vector.
– Transfer vector contains actual address of subroutine and
control is transferred to that physical memory location.
• For eg.- SQRT function is called in MAIN
Relocating Loaders
• Relocation:
– It is done with the help of RELOCATION BITS.
– If the relocations bit = 1 then instruction or part of instruction
need to be relocated.
– Relocation bits included as a part of object code for every
instruction.
– In example for every half word the relocation bit is present.
• Check that EXTRN says that SQRT and ERR are
external symbols and for every external symbol
transfer vector entry is generated.
Relocating Loaders

• Advantages:
– All four functions are performed by Loader.

• Disadvantages:
– Transfer Vector can be used only for linking not for storage
of external data.
– Transfer vector increases the size of object code.
– Common data segment so every subroutine has to access it
in synchronization.
Direct Linking Loader

• A general relocatable loader.


• Multiple procedure and data segments. Every
segment can be accessed by other segment.
• Independent translation of program.
• We are studying hypothetical loader supporting IBM
370 Model
Direct Linking Loader
• Following information assembler must
provide to the loader for every segment:
– Length of segment.
– List of symbols in segment referenced by other
segments.
– A list of all symbols not defined in segment but
referenced in segment.
– Information about address dependent values: their
location, and how to revise their addresses.
– Translated code for every segment and their
relative addresses.
Direct Linking Loader
Direct Linking Loader
• Some Observations:
– POINTER contains value 28 ie relative address of TABLE.
– ASUM = A(SUM). SUM is not defined in segment so
absolute address of ASUM can not be mentioned
immediately.
– JOHN, RESULT may be referenced by other procedures so
must be informed to the loader.
Direct Linking Loader

• In this scheme assembler produces four


types of cards as object deck (input to the
direct-linking loader) :
– ESD (External Symbol Dictionary)
– TXT (Object code for every segment)
– RLD (Relocation and Linkage Directory)
– END (Specifies end of object code)
Direct Linking Loader -ESD

• ESD stores all symbols defined in program may be


referenced somewhere else and all symbols
referenced in program but defined elsewhere.
• Types of symbols:
– SD: Segment Definition.
– LD: Local Definition.
– ER: External Reference. ER symbols are used in
conjunction with RLD cards for resolving symbolic
references
Direct Linking Loader -ESD
Direct Linking Loader - TXT
Direct Linking Loader - RLD

• RLD is Relocation and Linkage Directory.


• Contains information about contents that depends on
address in core. (Relocation and linking).
• RLD contains following information:
– Location of each constant that needs to be changed due to
relocation. (relative address of that instruction)
– By what value it has to be changed.(segment symbol)
– The operation to be performed ( add/subtract)
• Adjusting address constants of internal symbol is
relocation.
• Adjusting address constants of external symbol is
Linking.
Direct Linking Loader - RLD
Other Loading Schemes – Dynamic Loading
Design of Absolute Loader
• Allocation, Linking and Relocation performed by
Programmer and Assembler.
• Absolute Loader has to read object card and load it
into the memory.
• Assembler conveys through two cards:
– Object deck for where to load and what to load in memory.
– Entry point for execution of code.
• Card types are:
– Text card (type = 0) for instruction and data
– Transfer card ( type = 1) to hold entry point to program.
Design of Absolute Loader
• Text Card:
Card column Contents
1 Card type = 0
2 No. Of bytes of information.
3-5 Address at which data on card to put.
6-7 Empty
8-72 Instruction and data to be loaded.
73-80 Card sequence number
• Transfer Card:
Card column Contents
1 Card type = 1
2 Count = 0
3-5 Address of entry point
6-72 Empty
73-80 Card sequence number
Design of Absolute Loader
THANK YOU!!

You might also like