COP 3402 Systems Programming
Dr. Ali Orooji
School of EECSUniversity of Central Florida
S3 - 2
Chapter 3 - LOADERS AND LINKERSobject 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
S3 - 3
Absolute Loader
- no relocation - no linking
Relocation (Program Relocation)
two methods
- modification records - bit mask (relocation bit) (if direct addressing and fixed instruction format)
S3 - 4
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
S3 - 5
PROGB…
LISTB EQU * …
ENDB EQU * …
PROGC…
LISTC EQU * …
ENDC EQU * …
S3 - 6
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
S3 - 7
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
S3 - 8
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
S3 - 9
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
S3 - 10
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
S3 - 11
Linkage EditorsFigure 3.13 on page 153 of text
object program
linking and relocating loader
Memory
object program
linkage editor
Linked program
relocating loader
Memory
S3 - 12
Advantage avoids repeated linking
Disadvantage requires extra writing to disk
S3 - 13
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 textdynamicloader
userprogram
S3 - 14
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