33
CHAPTER-4 Linkers and Loaders

Ch 4 linker loader

Embed Size (px)

Citation preview

Page 1: Ch 4 linker loader

CHAPTER-4

Linkers and Loaders

Page 2: Ch 4 linker loader
Page 3: Ch 4 linker loader

IntroductionLinker• A System Software that Combines two or more separate

object programs and supplies the information needed to allow references between them .

• Two Types – Dynamic Linking– Static Linking

• Static Linking:– Static linkers takes input a collection of relocatable object files and

command line arguments and generate as output a fully linked executable object file that can be loaded and run.

• Dynamic Linking:– The addresses of called procedures aren’t bound until the first call. – Programs can bind to libraries as the programs are running, loading

libraries in the middle of program execution.– This provides a powerful and high-performance way to extend the

function of programs– MS Windows extensively uses DLL (Dynamic Linked Libraries)

Page 4: Ch 4 linker loader

Introduction (Contd..)Loader• The loader, which accepts the program form, produced

by a translator & certain other program forms from a library to produce one ready – to – execute machine language program.

• A unit of input to the loader is known as an object program or an object module.

• The process of merging many object modules to from a single machine language program is known as linking.

Page 5: Ch 4 linker loader

Difference between Linker and Loader

• Linker is a program that takes one or more objects generated by a compiler and combines them into a single executable program.

• Loader is the part of an operating system that is responsible for loading programs from executables (i.e., executable files) into memory, preparing them for execution and then executing them.

Page 6: Ch 4 linker loader

LOADER• The loader is program, which accepts the object program , prepares

this program for execution by the computer and initializes the execution. • Loader loads the referred resource or file after being Linked to referrer

via a Linker during the execution of program.• In particular the loader must perform four functions: 1. Allocate space in memory for the program (allocation). 2. Resolve symbolic references between objects 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).

Page 7: Ch 4 linker loader

Important Terms• Translation time address: Translation time address is used at

the translation time. This address is assigned by translator• Linked time address: Link time address is used at the link

time. This address is assigned by linker• Load time address: Load time address is used at the load

time. This address is assigned by loader• Translated origin: Address of origin assumed by the translator• Linked origin: Address of origin assumed by the linker while

producing a binary program• Load origin: Address of origin assumed by the loader

while loading the program for execution.

Page 8: Ch 4 linker loader

Relocation of Linking Concept• Program relocation is the process of modifying the addresses

used in the address sensitive instruction of a program such that the program can execute correctly from the designated area of memory.

• If linked origin≠ translated origin, relocation must be performed by the linker.

• If load origin≠ linked origin, relocation must be performed by the loader.

Page 9: Ch 4 linker loader

Relocation of Linking Concept(Contd..)• Let AA be the set of absolute address - instruction or data addresses

used in the instruction of a program P.• AA≠ ф implies that program P assumes its instructions and data to

occupy memory words with specific addresses.• Such a program – called an address sensitive program – contains one

or more of the following: -An address sensitive instruction: an instruction which uses an address a∈AA. -An address constant: a data word which contains an address a∈AA.• An address sensitive program P can execute correctly only if the start

address of the memory area allocated to it is the same as its translated origin.

• To execute correctly from any other memory area, the address used in each address sensitive instruction of P must be ‘corrected’.

Page 10: Ch 4 linker loader

Relocation of Linking Concept(Contd..)• Performing Relocation::

Page 11: Ch 4 linker loader

Relocation of Linking Concept(Contd..)• Performing Linking::

Page 12: Ch 4 linker loader

OBJECT FILES

SHARED LIBRARIES

NORMAL LIBRARIESCONTROL

FILES

DEBUG SYMBOL

FILE EXECUTABLE FILE

LINK/LOAD MAP

LINKER

COMMANDLINE

LINKING PROCESS

Page 13: Ch 4 linker loader
Page 14: Ch 4 linker loader

Self Relocating Programs

Page 15: Ch 4 linker loader

Design of a linker

Page 16: Ch 4 linker loader

Design of a linker (Contd..)

Page 17: Ch 4 linker loader

Design of a linker (Contd..)

Page 18: Ch 4 linker loader

MS-DOS Linker

Page 19: Ch 4 linker loader

MS-DOS Linker (Contd..)

Page 20: Ch 4 linker loader

MS-DOS Linker (Contd..)

Page 21: Ch 4 linker loader
Page 22: Ch 4 linker loader

MS-DOS Linker (Contd..)

Page 23: Ch 4 linker loader

Linking of Overlay Structured Programs

Page 24: Ch 4 linker loader

Linking of Overlay Structured Programs

Page 25: Ch 4 linker loader

Dynamic Linking

Page 26: Ch 4 linker loader

Different Loading Schemes

Page 27: Ch 4 linker loader

Different Loading Schemes(Contd..)

Page 28: Ch 4 linker loader

Different Loading Schemes(Contd..)

Page 29: Ch 4 linker loader

Different Loading Schemes(Contd..)

Page 30: Ch 4 linker loader

Different Loading Schemes(Contd..)

Page 31: Ch 4 linker loader

Linking Loaders

A linking loaders performs» All linking and relocation operations» Automatic library search» Loads the linked program directly into memory for execution

A linkage editor» Produces a linked version of program (often called a load module or an executable image which is written to a file or module or an executable image), which is written to a file or library for later execution» A simple relocating loader can be used to load the linked version of program into memory version of program into memory– The loading can be accomplished in one pass with no external symbol table required

Page 32: Ch 4 linker loader

Linking Loaders

Page 33: Ch 4 linker loader

End of Chapter…..