Presentation on theme: "3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking."— Presentation transcript:
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking Overview: r Design of an absolute loader r The Bootstrap loader r Relocation r Program linking r Algorithm for a linking loader r Other loader design options
3. Loaders & Linkers2 r Loading m Bring the object program into memory for execution. r Relocation m Modifies the object program so that it can be loaded at an address different from the location originally specified. r Linking m Combines two or more separate object programs and supplies the information needed to allow references between them. Introduction
3. Loaders & Linkers3 r Loader is a system program that performs the loading function. r Linker perform the linking operations. r P.s. 1. Many loader also support relocation and linking. r 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 & Linkers4 r No need to perform functions as linking and program relocation. r The operation is very simple. r All functions are accomplished in a single pass. Basic loader functions – The absolute loader
3. Loaders & Linkers5 The Object code for the program in @2.1
3. Loaders & Linkers6 The Object code for the program in @2.1 (cont.)
3. Loaders & Linkers7 The Object code for the program in @2.1 (cont.)
3. Loaders & Linkers8 The object program for the program in @2.1
3. Loaders & Linkers9 Loading of an absolute program
3. Loaders & Linkers10 Algorithm for an absolute loader
3. Loaders & Linkers11 Basic loader functions – Bootstrap loader r When a computer is first turned on or restarted, a special type of absolute loader, called a bootstrap loader, is executed. r The bootstrap loader itself begins at address 0 in the memory of the machine. r It loads the operating system (or some other program) starting at address 80.
3. Loaders & Linkers12 Bootstrap loader for SIC/XE
3. Loaders & Linkers13 Bootstrap loader for SIC/XE (cont.)
3. Loaders & Linkers14 Machine-dependent loader features r The advantages and disadvantages for absolute loader m Advantage: Simple and efficient. m 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. r So we need --- the capability of program relocation.
3. Loaders & Linkers15 Machine-dependent loader features --- Relocation r Loaders that allow for program relocation are called relocating loaders or relative loaders. r The relocating loaders need to take care of the modification record which must be changed when the program is relocated.
3. Loaders & Linkers16 Example of a SIC/XE program
3. Loaders & Linkers17 Example of a SIC/XE program (cont.)
3. Loaders & Linkers18 Example of a SIC/XE program (cont.)
3. Loaders & Linkers19 Object program with relocation by modification records.
3. Loaders & Linkers20 Relocation (cont.) r 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. r Since the SIC machine does not support the PC relative mode, so lots of the instructions need to be relocated. r The SIC machine use bit mask to indicate, whether the relocation is needed or not. r E.g., bit mask FFC (=1111 1111 1100) means the first 10 words need to be relocated.
3. Loaders & Linkers21 Relocatable program for a standard SIC machine
3. Loaders & Linkers22 Relocatable program for a standard SIC machine (cont.)
3. Loaders & Linkers23 Relocatable program for a standard SIC machine (cont.)
3. Loaders & Linkers24 Object program with relocation by bit mask.
3. Loaders & Linkers28 Object program corresponding to above program
3. Loaders & Linkers29 Object program corresponding to above program (cont.)
3. Loaders & Linkers30 Object program corresponding to above program (cont.)
3. Loaders & Linkers31 External symbol table (ESTAB)
3. Loaders & Linkers32 Relocation an linking operations performed on REF4 from PROGA
3. Loaders & Linkers33 Program from above program after linking and loading
3. Loaders & Linkers34 Algorithm and Data structure for a Linking Loader r Two passes of a linking loader m Pass1 Assigns addresses to all external symbols m Pass2 Performs the actual loading, relocation, and linking.
3. Loaders & Linkers35 Algorithm and Data structure for a Linking Loader (cont.)
3. Loaders & Linkers36 Algorithm and Data structure for a Linking Loader (cont.)
3. Loaders & Linkers37 Enhancing the object program r Reference number m To indicated each external symbol referred to in a control section. m Reference number 01 is corresponding to the control section name.
3. Loaders & Linkers38 Enhancing the object program (cont.)
3. Loaders & Linkers39 Enhancing the object program (cont.)
3. Loaders & Linkers40 Enhancing the object program (cont.)
3. Loaders & Linkers41 Machine-independent loader features – Automatic library search r Automatic library call (library search) m Libraries such as mathematical or statistical routines. m The subroutines called by the program being loaded are automatically fetched from the library, linked with the main program, and loaded. m The programmer does not need to take any action beyond mentioning the subroutines names as external references in the source program.
3. Loaders & Linkers42 Machine-independent loader features – Loader options r A special command language that is used to specify options. r E.g., m INCLUDE program-name(library-name) m DELETE csect-name m CHANGE name1,name2 m INCLUDE READ(UTLIB) m INCLUDE WRITE(UTLIB) m DELETE RDREC, WRREC m CHANGE RDREC, READ m CHANGE WRREC, WRITE
3. Loaders & Linkers43 Loader design options – Linkage Editors r A linking loader performs all linking and relocation operations, and loads the linked program directly into memory for execution. r 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 & Linkers45 Loader design options – Dynamic linking r The linkage editors perform linking operations before the program is loaded for execution. r 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.