Unit-4 Linker Loader
Unit-4 Linker Loader
1. Linker :
A linker is special program that combines the object files, generated by
compiler/assembler, and other pieces of codes to originate an executable file
have. exe extension. In the object file, linker searches and append all libraries
needed for execution of file. It regulates the memory space that will hold the
code from each module. It also merges two or more separate object programs
and establishes link among them. Generally, linkers are of two types :
1. Linkage Editor
2. Dynamic Linker
2. Loader :
The loader is special program that takes input of executable files from linker,
loads it to main memory, and prepares this code for execution by computer.
Loader allocates memory space to program. Even it settles down symbolic
reference between objects. It is in charge of loading programs and libraries in
operating system. The embedded computer systems don’t have loaders. In
them, code is executed through ROM. There are following various loading
schemes:
1. Absolute Loaders
2. Relocating Loaders
3. Direct Linking Loaders
4. Bootstrap Loaders
Difference Between Linker and Loader:
Relocation Processing
After the runtime linker has loaded all the dependencies required by an application,
the linker processes each object and performs all necessary relocations.
During the link-editing of an object, any relocation information supplied with the
input relocatable objects is applied to the output file. However, when creating a
dynamic executable or shared object, many of the relocations cannot be completed at
link-edit time because they require logical addresses that are known only when the
objects are loaded into memory. In these cases the link-editor generates new
relocation records as part of the output file image. The runtime linker must then
process these new relocation records.
For a more detailed description of the many relocation types, see Relocation Types
(Processor-Specific). There are two basic types of relocations:
Non-symbolic relocations
Symbolic relocations
The relocation records for an object can be displayed by using dump(1). In the
following example, the file libbar.so.1 contains two relocation records that indicate
that the global offset table (the .got section) must be updated.
Symbol Lookup
When an object requires a symbol, the runtime linker searches for that symbol based
upon the requesting object's symbol search scope, and the symbol visibility offered
by each object within the process. These attributes are applied as defaults to an object
at the time the object is loaded, as specific modes to dlopen(3DL), and in some cases
can be recorded within the object at the time it is built.
Absolute Loader
The absolute loader is a kind of loader in which relocated object files are created, loader accepts
these files and places them at a specified location in the memory.
This type of loader is called absolute loader because no relocating information is needed, rather it
is obtained from the programmer or assembler.
The starting address of every module is known to the programmer, this corresponding starting
address is stored in the object file then the task of loader becomes very simple that is to simply
place the executable form of the machine instructions at the locations mentioned in the object
file.
In this scheme, the programmer or assembler should have knowledge of memory management.
The programmer should take care of two things:
Specification of starting address of each module to be used. If some modification is done in
some module then the length of that module may vary. This causes a change in the starting
address of
espective modules.
While branching from one segment to another the absolute starting address of respective
module is to be known by the programmer so that such address can be specified at respective
JMP instruction.
Advantages:
1. It is simple to implement.
2. This scheme allows multiple programs or the source programs written in different languages. If
there are multiple programs written in different languages then the respective language assembler
will convert it to the language and common object file can be prepared with all the ad resolution.
3. The task of loader becomes simpler as it simply obeys the instruction regarding where to place
the object code to the main memory.
4. The process of execution is efficient.
Disadvantages:
1. In this scheme, it's the programmer's duty to adjust all the inter-segment addresses and manually
do the linking activity. For that, it is necessary for a programmer to know the memory
management.
2. If at all any modification is done to some segment the starting address of immediate next
segments may get changed the programmer has to take care of this issue and he/she needs to
update the corresponding starting address on any modification in the source.
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 directly put into their assigned
memory locations. After completion, the assembly process assigns the starting address of the
program to the location counter. The typical example ie WATFUR-77, a FORTRAN compiler which
uses such "load and go" scheme. This loading scheme is also called as "assemble and go".
.
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 a
memory. As this scheme is a combination of assembler and loader activities this combination
program occupies a 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 become a time-consuming activity.
It cannot handle multiple source program or multiple programs written in different languages.
This is because assembler can translate one source language to another target language.
The execution time will be more in this scheme as every time program is assembled and then
executed.
Advantages:
1. The program need not be retranslated each time while running it. Thus us because initially
when source program gets executed and object program gets generated. If a program is not
modified, then the loader can make use of this object program to convert it to executable
form.
2. There is no wastage of memory because the assembler is not placed in the memory instead of
it, loader occupies some portion of the memory. And the size of the loader is smaller than
assembler so more memory is available to the user.
3. It is possible to write source program with multiple programs and multiple languages
because the source program is first converted to an object program always and loader accepts
these object modules to convert it to an executable format.