Loaders and Linkers
Introduction: In this chapter we will understand the concept of linking and loading. As discussed earlier the source program is converted to object program by assembler. The loader is a program which takes this object program, prepares it for execution, and loads this executable code of the source into memory for execution. Definition of Loader: Loader is utility program which takes object code as input prepares it for execution and loads the executable code into the memory. Thus loader is actually responsible for initiating the execution process. Functions of Loader: The loader is responsible for the activities such as allocation, linking, relocation and loading 1) It allocates the space for program in the memory, by calculating the size of the program. This activity is called allocation. 2) It resolves the symbolic references (code/data) between the object modules by assigning all the user subroutine and library subroutine addresses. This activity is called linking. 3) There are some address dependent locations in the program, such address constants must be adjusted according to allocated space, such activity done by loader is called relocation. 4) Finally it places all the machine instructions and data of corresponding programs and subroutines into the memory. Thus program now becomes ready for execution, this activity is called loading. Loader Schemes: Based on the various functionalities of loader, there are various types of loaders: 1) “compile and go” loader: in this type of loader, the instruction is read line by line, its machine code is obtained and it is directly put in the main memory at some known address. That means the assembler runs in one part of memory and the assembled machine instructions and data is 1 ﺻﻔﺤﺔ Dr.Shaimaa H.Shaker
directly put into their assigned memory locations. After completion of assembly process, assign starting address of the program to the location counter. The typical example is WATFOR-77, it’s a FORTRAN compiler which uses such “load and go” scheme. This loading scheme is also called as “assemble and go”. Advantages: • This scheme is simple to implement. Because assembler is placed at one part of the memory and loader simply loads assembled machine instructions into the memory. Disadvantages: • In this scheme some portion of memory is occupied by assembler which is simply a wastage of memory. As this scheme is combination of assembler and loader activities, this combination program occupies large block of memory. • There is no production of .obj file, the source code is directly converted to executable form. Hence even though there is no modification in the source program it needs to be assembled and executed each time, which then becomes a time consuming activity. • It cannot handle multiple source programs or multiple programs written in different languages. This is because assembler can translate one source language to other target language. • For a programmer it is very difficult to make an orderly modulator program and also it becomes difficult to maintain such program, and the “compile and go” loader cannot handle such programs. • The execution time will be more in this scheme as every time program is assembled and then executed.
2) General Loader Scheme: in this loader scheme, the source program is converted to object program by some translator (assembler). The loader accepts these object modules and puts machine instruction and data in an executable form at their assigned memory. The loader occupies some portion of main memory. Advantages: • The program need not be retranslated each time while running it. This is because initially when source program gets executed an object program gets generated. Of program is not modified, then loader can make use of this object program to convert it to executable form. • There is no wastage of memory, because assembler is not placed in the memory,...