LINKER:-
Linker is a program in a system which helps to link a object modules of program into a single object file. It performs the process of linking. Linker are also called link editors. Linking is process of collecting and maintaining piece of code and data into a single file. Linker also link a particular module into system library. It takes object modules from assembler as input and forms an executable file as output for loader.
Linking is performed at both compile time, when the source code is translated into machine code and load time, when the program is loaded into memory by the loader. Linking is performed at the last step in compiling a program.
Linking is of two types:
1. Static Linking :–
It is performed during the compilation of source program. Linking is performed before execution in static linking. It takes collection of relocatable object file and command-line argument and generate fully linked object file that can be loaded and run.
Static linker perform two major task:
- Symbol resolution – It associates each symbol reference with exactly one symbol definition .Every symbol have predefined task.
- Relocation – It relocate code and data section and modify symbol references to the relocated memory location.
The linker copy all library routines used in the program into executable image. As a result, it require more memory space. As it does not require the presence of library on the system when it is run . so, it is faster and more portable. No failure chance and less error chance.
2. Dynamic linking :–
Dynamic linking is performed during the run time. This linking is accomplished by placing the name of a shareable library in the executable image. There is more chances of error and failure chances. It require less memory space as multiple program can share a single copy of the library.
Here we can perform code sharing. it means we are using a same object a number of times in the program. Instead of linking same object again and again into the library, each module share information of a object with other module having same object. The shared library needed in the linking is stored in virtual memory to save RAM. In this linking we can also relocate the code for the smooth running of code but all the code is not relocatable.It fixes the address at run time.
RELOCATION AND LINKING CONCEPT:-
Relocation is the process of assigning load addresses for position-dependent code and data of a program and adjusting the code and data to reflect the assigned addresses. Prior to the advent of multiprocess systems, and still in many embedded systems, the addresses for objects were absolute starting at a known location, often zero. Since multiprocessing systems dynamically link and switch between programs it became necessary to be able to relocate objects using position-independent code. A linker usually performs relocation in conjunction with symbol resolution, the process of searching files and libraries to replace symbolic references or names of libraries with actual usable addresses in memory before running a program.
Relocation is typically done by the linker at link time, but it can also be done at load time by a relocating loader, or at run time by the running program itself. Some architectures avoid relocation entirely by deferring address assignment to run time; this is known as zero address arithmetic.
PROGRAM LINKING:-
A whole program usually is not written in a single file. Apart from code and data definitions in multiple files, a user code often makes references to code and data defined in some "libraries". Linking is the process in which references to "externally" defined objects (code and data) are processed so as to make them operational. Traditionally linking used to be performed as a task after basic translation of the user program files, and the output of this stage is a single executable program file. This is known as static linking. A more versatile technique is more commonly used these days which is called - dynamic linking. object modules of user files LINKING + --------------------> Executable program existing library modules Two important aspects in linking are - locating the individual object modules in the combined executable program image, and adjusting the addresses used for external references in the various places in the program.
LOADERS:-
The loader is a component of an operating system that carries out the task of preparing a program or application for execution by the OS. It does this by reading the contents of the executable file and then storing these instructions into the RAM, as well as any library elements that are required to be in memory for the program to execute. This is the reason a splash screen appears right before most programs start, often showing what is happening in the background, which is what the loader is currently loading into the memory. When all of that is done, the program is ready to execute. For small programs, this process is almost instantaneous, but for large and complex applications with large libraries required for execution, such as games as well as 3D and CAD software, this could take longer. The loading speed is also dependent on the speed of the CPU and RAM.
Not all code and libraries are loaded at program startup, only the ones required for actually running the program. Other libraries are loaded as the program runs, or only as required. This is especially true for applications such as games that only need assets loaded for the current level or location that the player is in.
Though loaders in different operating systems might have their own nuances and specialized functions native to that particular operating system, they still serve basically the same function. The following are the responsibilities of a loader:
- Validate the program for memory requirements, permissions, etc.
- Copy necessary files, such as the program image or required libraries, from the disk into the memory
- Copy required command-line arguments into the stack
- Link the starting point of the program and link any other required library
- Initialize the registers
- Jump to the program starting point in memory
VARIOUS TYPES OF LINKING AND LOADER SCHEME:-
The loader scheme are:-
1. Absolute Loader- The task of an absolute loader is virtually trivial. The simply accepts machine language code and places it into main memory specified by assembler.
2. Relocating Loader:- The task of relocating loader is to avoid reassembling of all subroutine when a subroutine is changed and to perform task of allocation and linking for programmer.
3. Dynamic loading:- In order to overlay structure to work it is necessary for the module loader to load the various procedures as they are needed. There are many binders capable of processing and allocating overlay structure. The portion of the loader that actually intercepts calls and loads necessary procedure is called overlay supervisor of simplify flipper. this overall scheme is called dynamic loading or load on call.
4. Dynamic linking:- This is mechanism by which loading and linking of external references are postponed until execution time. This was made to sort out disadvantage of previous loading scheme like subroutine is referenced and never executed.
Post a Comment