Noteslinker and Loader
Noteslinker and Loader
2. Dynamic Linking
Dynamic linking is performed during execution of a binary program.
The linker is invoked when an unresolved external reference and resumes execution
of the program.
This arrangement has several benefits concerning use, sharing and updating
of library modules.
If the module referenced by a program has already been linked to another program
that is in execution, a copy of the module would exist in memory. The same copy of
the module could be lined to his program as well, thus saving memory.
To facilitate dynamic linking, each program is first processed by the static linker.
1
Relocation
The compiler would be unable to take advantage of shorter or more efficient instructions,
as in the final output, it does not have the information of the object on the layout. For
instance, an offset or absolute address from the current location can be addressed by a
jump instruction, and on the basis of the distance to the target, the offset could be
expressed with different lengths. It is also known as automatic jump-sizing in order to
jump optimizations.
The addresses are reassigned by the linker relaxation pass, which helps to more potential
relaxations. Typically, instruction relaxation occurs when the linking is performed, but at
compile-time, inner-module relaxation has the ability to take place as part of the
optimizing process. Moreover, relaxation can also occur in some cases at the load-time.
In the execution of the program, the linker and loader (two utility programs) play an
important role. Before executing the program, its code passes through the compiler,
assembler, linker, loader. Below is a table that contains the major difference between the
linker and loader. The linker is a program in a system, also known as link editor and
binder, which combines object modules into a single object file, whereas the loader is a
special program that loads the executable module of a program that is generated by the
linker and prepares this code for execution by a computer.
3
LOADER
Loader is utility program which takes object code as input prepares it for execution and
loads the executable code in to 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.
Types of loader
1. Compile and go to loader
2. General loader
3. absolute loader
4. direct linking loader (DLL)
Compile-and-Go Loaders
4
Assembler is loaded in one part of memory and assembled program directly
into their assigned memory location.
After the loading process is complete, the assembler transfers the control to
the starting instruction of the loaded program.
Advantages
The user need not be concerned with the separate steps of compilation,
assembling, linking, loading, and executing.
Execution speed is generally much superior to interpreted systems.
They are simple and easier to implement.
Disadvantages
There is wastage in memory space due to the presence of the assembler.
The code must be reprocessed every time it is run.
5
component called loader does the job.
Note that the loader program is comparatively much smaller than the
assembler, hence making more space available to the user for their programs.
Absolute Loaders
An absolute loader loads a binary program in memory for execution.
The binary program is stored in a file contains the following:
o A Header record showing the load origin, length and load
time execution start address of the program.
6
o A sequence of binary image records containing the program’s code.
Each binary image record contains a part of the program’s code
in the form of a sequence of bytes, the load address of the first
byte of this code and a count of the number of bytes of code.
The absolute loader notes the load origin and the length of the program
mentioned in the header record.
It then enters a loop that reads a binary image record and moves the code
contained in it to the memory area starting on the address mentioned in the
binary image record.
At the end, it transfers control to the execution start address of the program.
7
flexible intersegment referencing and accessing ability ,while at the same time
allowing independent translation of programs.
The translator must give the loader the following information with each procedure
or data segment.
1. The length of segment
2. A list of all symbols in the segment that may be referenced by other segment
and their relative location with in 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 address
assigned. There are four sections to the object desk
1. External symbol directory cards(ESD)
2. Instructions and data cards called text of a program(TXT)
3. Relocation and linkage directory cards (RLD)
4. End card(END)
The ESD cards contain the information necessary to build the external directory or
symbol table. External symbols are symbols that can be referred beyond the
subroutine level.