Professional Documents
Culture Documents
Loader 3
Loader 3
Loader 3
1 4
Design of an Absolute
Introduction
Loader
Object program: • Refer to Section 2.1&2.1.1 and Figure 3.1
– contains translated instructions and data from • Its operation is very simple
the source program,
– specifies addresses in memory where these – no linking or relocation
items are to be loaded. • Single pass operation
Loading: brings the object program into memory – check H record to verify that correct program
for execution has been presented for loading
Relocation: modifies the object program so that it – read each T record, and move object code into
can be loaded at an address different from the the indicated address in memory
location originally specified
– at E record, jump to the specified address to
Linking: combines two or more separate object begin execution of the loaded program.
programs and supplies the information needed to
allow references between them.
3 6
1
• Figure 3.2 • A more complex loader
– suitable for SIC/XE and is typical of those
found on most modern computers
• Each byte of assembled code is given using
– supports relocation and linking
Hex representation in character form
• Section 3.2.1 – hardware dependencies
• As the instruction is loaded for execution,
the operation code must be stored in a • Section 3.2.2 – program linking from the
single byte w/Hex value. loader’s point of view
– not as machine dependent as relocation
• Section 3.3 – data structures and
• May prefer to store object code in binary
processing logic
form for obtaining more efficiency!
7 10
MACHINE-DEPENDENT LOADER
FEATURES Second method
• Disadvantages of absolute loader 2. Modification record scheme is not well suited
– actual load address must be specified for use with a machine like SIC
• OK for SIC - SIC does not use relative addresses
• problematic for an advanced machine where almost all instructions (except RSUB) must
several independent programs run together be modified when the program is relocated.
and share memory No Modification records
– relocation is needed for efficient execution
A relocation bit associated with each word of
– difficult to use subroutine libraries object code and they form a bit mask
(scientific and mathematical) efficiently T00106119FE0040030E01079301064508039DC10792C00363810644C000005
• important to be able to select and load + + + + + + +
exactly those routines that are needed 111111100000
9 12
2
Third method
3. Hardware relocation capability is • REF3 – immediate operand whose value is
provided by some computers to be the difference between ENDA and
- eliminates some of the need for the LISTA
loader to perform relocation – PROGA – knows all info
- They keep all memory references to – PROGB/C – values of labels are unknown
be relative to the user’s assigned area • must be assembled as an external reference
of memory w/two modification records
- Conversion takes place during
execution.
13 16
3
Algorithm and Data Structures
for a Linking (Relocating) Loader
• More complicated than the absolute loader • Pass 2:
• We use Modification records for relocation – does actual loading, relocation, and linking
– so that linking and relocating functions are – As each Text record is read, the object code is
performed using the same mechanism moved to the specified address
• (plus the current value of CSADDR)
• Input: a set of object programs (control
– When a Modification record is encountered, the
sections) that are to be linked together mentioned symbol’s value is added or
– A CS may make an external ref. to a symbol subtracted from the indicated location in
whose def does not appear until later in this memory
input stream until later CS is read.
• Last step: transfer control to loaded program to
– Two passes over input: begin execution.
• Pass 1: assigns addresses to all external symbols
• Pass 2: performs the actual loading, relocation, and
– indicated in the End record
linking. Remark: Algorithm can be made more efficient
19
by changing the object code but this concerns the22
implementors only!
MACHINE-INDEPENDENT
Main Data Structures LOADER FEATURES
• External Symbol Table (ESTAB) • Loading and linking are often thought
– ~Symbol Table
– stores the name and address of each external symbol in as O/S service functions.
the set of control sections being loaded.
– also often indicates in which CS the symbol is defined.
– The programmer’s connection with such
– A hashed organization is typically used. services is not as direct as it is with
• Program Load Address (PROGADDR) assemblers.
– beginning address inmemory where the linked program is
to be loaded.
– Most loaders include fewer different
– supplied by the O/S features than are found in a typical
• Control Section Address (CSADDR) assembler.
– starting address asigned to the CS currently being
scanned by the loader • Automatic library search process for
– Its value is added to all relative addresses within the
control section to convert them to actual addresses
handling external references
20 23
21 24
4
Implementation of Search LOADER DESIGN OPTIONS
• linking loader must keep track of external • Linking loaders
symbols that are referred to, but not – perform all linking and relocation at load time
defined. • Linkage editors
– enter symbol from each Refer record – perform linking prior to load time, and writes
into the external symbol table (ESTAB) linked program (executable image) into file
–> at the end of Pass 1, the symbol in table that instead of being immediately loading into
remain undefined represent unresolved memory.
external references – found on most systems in addition to linking
– the loader searches the library or loaders
libraries specified for routines that • Dynamic linking
contain the definitions of these symbols – linking function is performed at execution time
• Subroutines fetched from a library in this – uses facilities of the O/S to load and link
may may themselves contain external subprograms at the tie they are first called
references. 25 28
Linkage Editors
• The process allows the programmer to • A linking loader performs all linking and
override the standard subroutines in the relocation, including automatic library search, and
loads the linked program directly into memory for
library by supplying his or her own routines. execution.
• The libraries to be searched by the loader • A linkage editor produces a linked version of
ordinarily contain assembled or compiled the program (load module or executable image) which is
versions of subroutines (i.e., object written to a file or library for later execution
– a simple relocating loader can be used later to
programs) load the program into memory
– In most cases, a special directory is used for – linkage editor performs relocation of all CSs
the libraries. relative to the start of the linked program
– Directory entry points to the address of the – loading can be accomplished in one pass w/no
subroutine within the file. external symbol table required.
26 29
Loader Options
• Many loaders allow the user to • A linked program is generally in a form
suitable for processing by a relocating
specify options that modify the loader
standard processing described above – all external references are resolved
– a special command language (job control – relocating is indicated by some mechanism, such
language) is used for this purpose as Modification record or bit mask
– Even though all linking has been performed,
• Examples: information concerning external references is
– Most loaders allow the user to specify often retained in the linked program
– This allows subsequent re-linking of the
alternative libraries to be searched program to replace control sections, modify
• LIBRARY MYLIB external references, etc.
• if this info is not retained, then what
happens?
27 30
5
Suitable Work Environments Using packages
• In an environment where program is • If all of the cross-refs between library
to be executed many times w/o being routines would have to be processed
reassembled individually – same set of cross-refs would
need to be processed for almost every
– use of a linkage editor -> reduces FORTRAN program linked
overhead
• A linkage editor can be used to combine
• resolution of external refs and library
searching are performed only once the appropriate subroutines into a package
(Compare to a linking loader!) • Since package already has all of the cross-
refs between subroutines resolved, these
• In a development and testing linkages would not be processed when each
environment user’s program is linked
– a linking loader is more efficient.
31 34
32 35
6
Bootstrap Loaders
• Advantages over other types of linking: • How is the loader itself loaded into
– provides the ability to load the routines only memory?
when (and if) they are needed
• saves time and memory space
– OS may load it in
• Ex: a program contains correction and diagnostic • Then how is the O/S loaded into
routines that may not be used al all during most
executions of the program memory?
– avoids loading of the entire libraries for each
execution
• Ex: a user can interactively call any of the “Given an idle computer w/no program
subroutines of a large mathematical and statistical
library in memory, how do we get things started?”
37 40
3- Mechanisms to accomplish the actual • With the machine empty and idle, there is no
loading and linking of a called subroutine need for program relocation
– Fig.3.14 – we can simply specify the absolute address for
– routines that are to be dynamically loaded must whatever program is first loaded, usually the O/S.
be called via an O/S service request • we need some means of accomplishing the functions of an absolute
loader
• instead of executing a JSUB, the program makes a • Operator may enter object code of absolute loader into memory
load-and-call service request to the O/S.
• absolute loader program may be permanently resident on ROM and
• O/S loads the routine if not already loaded activated by a hardware signal
• Control is passed from O/S to the routine being • A built-in hardware function reads a fixed-length record (called
called bootstrap loader) from some device into memory at a fixed
• When done, control returns to O/S and then to the location – this record may contain the machine instructions to load
user’s calling program the absolute program in
– O/S may free memory, or wait for a while if some other • Control is transferred to there
call may come soon • If the loading process requires more instructions that can be read
in a single record, this first record causes the reading of others,
and these in turn can read still more records , hence the term
38 bootstrap 41
SunOS Linkers
• When dynamic linking is used, the • Two different linkers:
association of an actual address with – link editor
the symbolic name of the called – run-time linker
routine is not made until the call • Link editor
statement is executed: – invoked in the process of compiling a
– in other words, binding of the name to an program
actual address is delayed from load time – takes one or more object modules
until execution time (delayed binding) produced by assemblers and compilers
and produces a single output module:
39 42
7
Lazy Binding
Output module can be: • After it locates and includes the necessary
– a relocatable object module – suitable shared objects, the linker performs
for further link-editing relocation and linking operations toprepare
the program for execution.
– a static executable – w/all symbolic
– During link-editing, calls to globally defined
references bound and ready to run procedures are converted to references to a
– a dynamic executable – in which some procedure linkage table
symbolic references may need to be – When a procedure is called for the first time,
bound at run time control is passes via this table to the run-time
linker.
– a shared object – which provides
– The linker looks up the actual address of the
services that can be bound at run time called procedure and inserts it into the linkage
to one or more dynamic executables table
• subsequent calls directly go to the called procedure
43 46