MODULE 3 Loading, linking and relocating Loader schemes- Binders, linking loaders, overlays, dynamic binders Dynamic loading and dynamic linking – Relocatability of prog
LOADING It is a special program that takes the input of executable files from the linker , loads it to the main memory, and prepares this code for execution by a computer. In a computer operating system , a loader is a component that locates a given program in offline storage (such as a hard disk ), loads it into main storage, and gives that program control of the computer. A loader is a major component of an operating system that ensures all necessary programs and libraries are loaded, which is essential during the startup phase of running a program.
LINKING The job of the linker is to combine these object files and, in the process, to resolve all of the unresolved symbols. The output of the linker is a new object file that contains all of the code and data from the input object files and is in the same object file format. If the same symbol is declared in more than one object file, the linker is unable to proceed. It will likely complain to the programmer (by displaying an error message) and exit. if a symbol reference remains unresolved after the entire object files have been merged, the linker will try to resolve the reference on its own.
RELOCATING A relocating loader load a program in a designated area of memory, relocates it so that it can execute correctly in that area of memory and passes control to it for execution. The binary program is stored in a file contains the following: A Header record showing the load origin, length and load time execution start address of the program. 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. A table analogous to RELOCTAB table giving linked addresses of address sensitive instructions in the program.
Relocating Linking Loaders Relocating linking loader combines together the relocating capabilities of relocating loaders and the advanced linking features of linking loaders and presents a more robust loading scheme. This necessarily eliminates the need to use two separate programs for linking and loading respectively. Moreover, these loaders can perform relocation and be linking both. Similarly, these loaders can work efficiently with support from the operating system and utilize the memory and other resources efficiently.
LOADER SCHEMES Compile-and-Go Loaders 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 reprocess every time it runs.
General Loader Schemes The general loading scheme improves the compile/assemble-and-go scheme by allowing different source programs (or modules of the same program) to be translated separately into their respective object programs. Moreover, the object code (modules) stored in the secondary storage area; and then, they are loaded. Similarly, The loader usually combines the object codes and executes them by loading them into the memory. The loader program is comparatively much smaller than the assembler, hence making more space available to the user for their programs.
Advantages of the general loading scheme: Saves memory and makes it available for the user program as loaders are smaller in size than assemblers. The loader replaces the assembler. Similarly, Reassembly of the program no more needed for later execution of the program. The object file/deck available and can load and executed directly at the desired location. This scheme allows the use of subroutines in several different languages because the object files processed by the loader utility will all be in machine language. Disadvantages of the general loading scheme: Moreover, the loader more complicated and needs to manage multiple object files. Secondary storage required to store object files, and they cannot directly place into the memory by assemblers.
3) Absolute Loader: Absolute loader is a kind of loader in which relocated object files are created, loader accepts these files and places them at specified locations in the memory. This type of loader is called absolute because no relocation information is needed; rather it is obtained from the programmer or assembler.
Thus the absolute loader is simple to implement in this scheme Allocation is done by either programmer or assembler Linking is done by the programmer or assembler Relocation is done by assembler Simply loading is done by the loader Advantages: 1. It is simple to implement 2. This scheme allows multiple programs or the source programs written different languages. 3. The task of loader becomes simpler as it simply obeys the instruction regarding where to place the object code in the main memory. 4. The process of execution is efficient.
Disadvantages: In this scheme it is 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.
LINKING LOADERS Special system program called linking loader gathers various object modules, links them together to produce single executable binary program and loads them into the memory. This category of loaders leads to a popular class of loaders called direct-linking loaders . Moreover, The loaders used in these situations are usually called linking loaders , which link the necessary library functions and symbolic references. Essentially, linking loaders accept and link together a set of object programs and a single file to load them into the core. Similarly, Linking loaders additionally perform relocation and overcome disadvantages of other loading schemes.
BINDERS In file management, a binder is a software utility that combines two or more files into a single file. The program which performs allocation, relocation and linking is called binder. The binder performs relocation, creates linked executable text and stores this text in a file in some systematic manner. Such kind of module prepared by the binder execution is called load module . This load module can then be actually loaded in the main memory by the loader. This loader is also called as module loader .
If the binder can produce the exact replica of executable code in the load module then the module loader simply loads this file into the main memory which ultimately reduces the overall time complexity. But in this process the binder should knew the current positions of the main memory. The binder which performs the linking function and produces adequate information about allocation and relocation and writes this information along with the program code in the file is called linkage editor .
The module loader then accepts this file as input, reads the information stored in and based on this information about allocation and relocation it performs the task of loading in the main memory. Even though the program is repeatedly executed the linking is done only once. Moreover, the flexibility of allocation and relocation helps efficient utilization of the main memory.
DYNAMIC BINDERS A binding is dynamic if it occurs during execution or can change during execution of the program. A binding is static if it occurs before run time and remains unchanged throughout program execution. Dynamic binding also called dynamic dispatch, is the process of linking procedure call to a specific sequence of code (method) at run-time. It means that the code to be executed for a specific procedure call is not known until run-time. Dynamic binding is also known as late binding or run-time binding .
DYNAMIC LOADING Dynamic loading refers to the process of loading a program into the main memory on demand. In Dynamic Loading, a routine is not loaded until it is called. Better memory-space utilization ; unused routine is never loaded. Useful when large amounts of code are needed to handle infrequently occurring cases. No special support from the operating system is required implemented through program design. When dynamic loading is used, dynamic linking is used as well. The processing speed of dynamic loading is slower because the files are uploaded at processing time.
DYNAMIC LINKING The process of linking external libraries and references at runtime, when the program is loaded or executed. Linkage editors perform linking operations before the program is loaded for execution. Dynamic linking is often used to allow several executing programs to share one copy of a subroutine or library. With a program that allows its user to interactively call any of the subroutines of a large mathematical and statistical library, all of the library subroutines could potentially be needed, but only a few will actually be used in any one execution. Dynamic linking can avoid the necessity of loading the entire library for each execution except those necessary subroutines.
Dynamically linked shared libraries are easier to create than static linked shared libraries. Dynamically linked shared libraries are easier to update than static linked shared libraries. Slightly slower program startup due to the additional linking process, but overall performance impact is minimal.
OVERLAYS In memory management, overlays refer to a technique used to manage memory efficiently by overlaying a portion of memory with another program or data. In a general computing sense, overlaying means "the process of transferring a block of program code or other data into internal memory, replacing what is already stored". Overlaying is a programming method that allows programs to be larger than the computer's main memory. Overlays keep in memory only those instructions and data that are needed at any given time.It needed when process is larger than amount of memory allocated to it. This is implemented by user, no special support needed from operating system, programming design of overlay structure is complex.
RELOCATABILITY OF PROGRAMS. A relocatable program is one that can be read into memory at any address and executed without modification. It can be loaded at-most anywhere in the memory This mainly means using relative offsets for data accesses and jump instructions. If this is easy/possible is based on the type of architecture, the size of the address space and the size of the program.
A Relocatable program form is one which consists of a program and relevant information for its relocation. Using this information it is possible to relocate the program to execute from a storage area then the one designated for it at the time of its coding or translation. A Non Relocatable program is one which cannot be made to execute in any area of storage other than the one designated for it at the time of its coding or translation.