140 likes | 250 Views
COP 3402 Systems Programming. Dr. Ali Orooji School of EECS University of Central Florida. Chapter 3 - LOADERS AND LINKERS object program contains translated instructions and data values from the source program, and specifies addresses in memory where these items are to be loaded.
E N D
COP 3402 Systems Programming Dr. Ali Orooji School of EECSUniversity of Central Florida
Chapter 3 - LOADERS AND LINKERS object program contains translated instructions and data values from the source program, and specifies addresses in memory where these items are to be loaded Three Functions Loading brings the object program into memory for execution Relocation modifies the object program when the program is loaded at an address different from the location originally specified Linking combines two or more separate object programs
Absolute Loader - no relocation - no linking Relocation (Program Relocation) two methods - modification records - bit mask (relocation bit) (if direct addressing and fixed instruction format)
Linking (Program Linking) Figure 3.8 on pages 136-137 of text PROGA ... REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA ... LISTA EQU * ... ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA
PROGB … LISTB EQU * … ENDB EQU * … PROGC … LISTC EQU * … ENDC EQU * …
Linking and Relocating Loader Let's assume control section 1 has external references to control section 2. Control section 2 comes after control section 1; so when loading control section 1 we don't know the addresses for variables in control section 2 - two passes Pass 1 assigns addresses to all external symbols Pass 2 performs loading, relocation, and linking
Loader Data Structures external symbol table (ESTAB - ESTBL) name and address of each external symbol; and in which control section the symbol is defined program load address (PROGADDR) beginning address in memory where the linked program is to be loaded control section address (CSADDR) starting address assigned to the control section currently being scanned by the loader; starting address of the control section currently being loaded
Loader Logic Pass 1 - Page 143 of text Pass 2 - Page 144 of text Figure 3.11(a) Algorithm for Pass 1 of a linking loader Figure 3.11(b) Algorithm for Pass 2 of a linking loader
Section 3.3: Machine-Independent Loader Features Automatic Library Search standard system library other libraries - put external references in ESTBL - after processing the primary input to loader if unresolved external references search the libraries for the routines
Section 3.4: Loader Design Options Linking (and Relocating) Loaders perform all linking and relocation at load time Linkage Editors perform linking prior to load time Dynamic Linking linking is performed at execution time Bootstrap Loaders - used to load the operating system or the loader itself into memory - used to run stand-alone programs independent of the operating system or the system loader
object program object program linkage editor linking and relocating loader Linked program Memory relocating loader Memory Linkage Editors Figure 3.13 on page 153 of text
Advantage avoids repeated linking Disadvantage requires extra writing to disk
dynamic loader user program Dynamic Linking postpones the linking function until execution time: a subroutine is loaded and linked to the rest of the program when it is first called Advantage avoids unnecessary linking Figure 3.14 on page 157 of text
Bootstrap Loaders How do we get the first program into memory? - operator enters into memory the object code for an absolute loader, using switches on the computer console - have absolute loader program in a read-only memory (ROM); when the operator presses "system start" button, the machine begins to execute this program - when pressing a button, a record is read from some device into memory at a fixed location; this record contains instructions for an absolute loader