Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Linkage editor
z The difference between a linkage editor and a
linking loader:
• A linking loader performs all linking and relocation
operations, including automatic library search, and
loads the linked program into memory for execution.
• A linkage editor produces a linked version of the
program, called a load module or an executable image,
which is normally written to a file for later execution.
1
OnOnWindows
WindowsororUNIX
UNIX
operating
operatingsystems,
systems,we weuseuseaa
linkage
linkageeditor
editor(e.g.,
(e.g.,link
linkand
andld)
ld)
totogenerate
generateananexecutable
executable
program.
program.
Linkage editor
z When the user is ready to run the linked program,
a simple relocating loader can be used to load the
program into memory.
z The only object code modification necessary is
the addition of an actual address to relative values
within the program.
z The linkage editor performs relocation of all
control sections relative to the start of the linked
program.
• All items that need to be modified at load time have
values that are relative to the start of the linked program.
• This means that the loading can be accomplished in one
pass with no external symbol table required.
4
2
Linkage editor
z If a program is to be executed many
times without being reassembled, the
use of a linkage editor can substantially
reduces the overhead required.
• Resolution of external references and library
searching are only performed once.
Linkage editor
z Even though all linking has been
performed, information concerning
external references is often retained in
the linked program.
• This allows subsequent relinking of the
program to replace control sections, modify
external references, etc.
• If this information is not retained, the linked
program cannot be reprocessed by the
linkage editor; it can only be loaded and
executed.
6
3
Linkage editor
z For example, replace a new version of a
subroutine without using the original
versions of all of the other subroutines.
• INCLUDE PLANNER(PROGLIB)
• DELETE PROJECT
• INCLUDE PROJECT(NEWLIB)
• REPLACE PLANNER(PROGLIB)
Linkage editor
z Linkage editors can be used to build packages of subroutines or
other control sections that are generally used together.
• If the program often uses a set of subroutines (e.g. formatted I/O in
FORTRAN) that have a large number of cross-references among
them, exactly the same set of cross-references would need to be
processed for almost every program linked.
• This represents a substantial amount of overhead.
• The linkage editor could be used to combine the appropriate
subroutines into a package with a command sequence like
following:
INLCUDE READR(FTNLIB)
INCLUDE WRITER(FNTLIB)
INCLUDE BLOCK(FNTLIB)
INCLUDE ENCODE(FNTLIB)
INCLUDE DECODE(FNTLIB)
...
SAVE FNTIO(SUBLIB)
4
Linkage editor
Dynamic linking
z Linkage editors perform linking before
the program is loaded for execution.
z Linking loaders perform these same
operations at load time.
z Dynamic linking postpones the linking
function until execution time.
• A subroutine is loaded and linked to the test
of the program when it is first called.
10
5
Dynamic linking application
z Dynamic linking is often used to allow several
executing programs to share one copy of a
subroutine or library.
z For example, a single copy of the standard C
library can be loaded into memory.
z All C programs currently in execution can be
linked to this one copy, instead of linking a
separate copy into each object program.
11
12
6
Dynamic linking advantage
z Some subroutines such as those that diagnose
errors may never need to be called at all can
be loaded only when they are needed.
• Without using dynamic linking, these subroutines must
be loaded and linked every time the program is run.
z Using dynamic linking can save both space for
storing the object program on disk and in
memory, and time for loading the bigger object
program.
13
7
Dynamic linking implementation
z The OS examines its internal tables to determine whether
the subroutine is already loaded.
z If needed, the subroutine is loaded from the library.
z Then control is passed from the OS to the subroutine
being called.
z When the called subroutine completes its processing, it
returns to its caller (operating system).
z The OS then returns control to the program that issues
the request.
z After the subroutine is completed, the memory that was
allocated to it may be released.
15
16
8
Example
17