510 likes | 869 Views
Chapter goal: To realize how a source program be loaded into memory Loading Relocation Linking. Overview: Design of an absolute loader The Bootstrap loader Relocation Program linking Algorithm for a linking loader Other loader design options. Chapter III: Loaders and Linkers. Loading
E N D
Chapter goal: To realize how a source program be loaded into memory Loading Relocation Linking Overview: Design of an absolute loader The Bootstrap loader Relocation Program linking Algorithm for a linking loader Other loader design options Chapter III: Loaders and Linkers 3. Loaders & Linkers
Loading Bring the object program into memory for execution. Relocation Modifies the object program so that it can be loaded at an address different from the location originally specified. Linking Combines two or more separate object programs and supplies the information needed to allow references between them. Introduction 3. Loaders & Linkers
Loader is a system program that performs the loading function. Linker perform the linking operations. P.s. 1. Many loader also support relocation and linking. P.s. 2. Some system have a linker to perform the linking operations and a separate loader to handle relocation and loading. Introduction (cont.) 3. Loaders & Linkers
No need to perform functions as linking and program relocation. The operation is very simple. All functions are accomplished in a single pass. Basic loader functions – The absolute loader 3. Loaders & Linkers
The Object code for the program in @2.1 3. Loaders & Linkers
The Object code for the program in @2.1 (cont.) 3. Loaders & Linkers
The Object code for the program in @2.1 (cont.) 3. Loaders & Linkers
The object program for the program in @2.1 3. Loaders & Linkers
Loading of an absolute program 3. Loaders & Linkers
Algorithm for an absolute loader 3. Loaders & Linkers
Basic loader functions – Bootstrap loader • When a computer is first turned on or restarted, a special type of absolute loader, called a bootstrap loader, is executed. • The bootstrap loader itself begins at address 0 in the memory of the machine. • It loads the operating system (or some other program) starting at address 80. 3. Loaders & Linkers
Bootstrap loader for SIC/XE 3. Loaders & Linkers
Bootstrap loader for SIC/XE (cont.) 3. Loaders & Linkers
Machine-dependent loader features • The advantages and disadvantages for absolute loader • Advantage: Simple and efficient. • Disadvantage: Need the programmer to specify the actual address at which it will be loaded into memory. It is difficult to use subroutine libraries efficiently. • So we need --- the capability of program relocation. 3. Loaders & Linkers
Machine-dependent loader features --- Relocation • Loaders that allow for program relocation are called relocating loadersorrelative loaders. • The relocating loaders need to take care of the modification record which must be changed when the program is relocated. 3. Loaders & Linkers
Example of a SIC/XE program 3. Loaders & Linkers
Example of a SIC/XE program (cont.) 3. Loaders & Linkers
Example of a SIC/XE program (cont.) 3. Loaders & Linkers
Object program with relocation by modification records. 3. Loaders & Linkers
Relocation (cont.) • In SIC/XE machine, most of the code is not need to relocation (e.g., PC relative addressing or immediate addressing). Only the Format 4 (e.g, +SUB…) needed. • Since the SIC machine does not support the PC relative mode, so lots of the instructions need to be relocated. • The SIC machine use bit mask to indicate, whether the relocation is needed or not. • E.g., bit mask FFC (=1111 1111 1100) means the first 10 words need to be relocated. 3. Loaders & Linkers
Relocatable program for a standard SIC machine 3. Loaders & Linkers
Relocatable program for a standard SIC machine (cont.) 3. Loaders & Linkers
Relocatable program for a standard SIC machine (cont.) 3. Loaders & Linkers
Object program with relocation by bit mask. 3. Loaders & Linkers
Program Linking 3. Loaders & Linkers
Program Linking (cont.) 3. Loaders & Linkers
Program Linking (cont.) 3. Loaders & Linkers
Object program corresponding to above program 3. Loaders & Linkers
Object program corresponding to above program(cont.) 3. Loaders & Linkers
Object program corresponding to above program(cont.) 3. Loaders & Linkers
External symbol table (ESTAB) 3. Loaders & Linkers
Relocation an linking operations performed on REF4 from PROGA 3. Loaders & Linkers
Program from above program after linking and loading 3. Loaders & Linkers
Algorithm and Data structure for a Linking Loader • Two passes of a linking loader • Pass1 Assigns addresses to all external symbols • Pass2 Performs the actual loading, relocation, and linking. 3. Loaders & Linkers
Algorithm and Data structure for a Linking Loader (cont.) 3. Loaders & Linkers
Algorithm and Data structure for a Linking Loader (cont.) 3. Loaders & Linkers
Enhancing the object program • Reference number • To indicated each external symbol referred to in a control section. • Reference number 01 is corresponding to the control section name. 3. Loaders & Linkers
Enhancing the object program (cont.) 3. Loaders & Linkers
Enhancing the object program (cont.) 3. Loaders & Linkers
Enhancing the object program (cont.) 3. Loaders & Linkers
Machine-independent loader features – Automatic library search • Automatic library call (library search) • Libraries such as mathematical or statistical routines. • The subroutines called by the program being loaded are automatically fetched from the library, linked with the main program, and loaded. • The programmer does not need to take any action beyond mentioning the subroutines names as external references in the source program. 3. Loaders & Linkers
Machine-independent loader features – Loader options • A special command language that is used to specify options. • E.g., • INCLUDE program-name(library-name) • DELETE csect-name • CHANGE name1,name2 • INCLUDE READ(UTLIB) • INCLUDE WRITE(UTLIB) • DELETE RDREC, WRREC • CHANGE RDREC, READ • CHANGE WRREC, WRITE 3. Loaders & Linkers
Loader design options – Linkage Editors • A linking loader performs all linking and relocation operations, and loads the linked program directly into memory for execution. • A linkage editor produces a linked version of the program (loader module or executable image) which is written to a file or library for later execution. 3. Loaders & Linkers
Loader design options – Linkage Editors (cont.) 3. Loaders & Linkers
Loader design options – Dynamic linking • The linkage editors perform linking operations before the program is loaded for execution. • The dynamic linking(dynamic loading or load on call) load a subroutine and linked to the rest of the program when it is first called. 3. Loaders & Linkers
Loader design options – Dynamic linking (cont.) 3. Loaders & Linkers
Loader design options – Dynamic linking (cont.) 3. Loaders & Linkers