Você está na página 1de 9

Loader Design Options

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

z Linkage editors often allow the user to specify that


external references are not to be resolved by automatic
library search.
• For example, 100 FORTRAN programs use FNTIO. It
means 100 copies of FNTIO would be stored.
• By using the command to specify no library search be
performed during linkage editor, only the external
references between user-written routines would be resolved.
• A linking loader could then be used to combine the linked
user routines with FTNIO.

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

Dynamic linking application


z In an object-oriented system, dynamic
linking is often used for references to
software object.
• This allows the implementation of the object
and its method to be determined at the time
the program is run. (e.g., C++)
z The implementation can be changed at
any time, without affecting the program
that makes use of the object.

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

Dynamic linking implementation


z One possible way to implement dynamic
linking.
• A subroutine that is to be dynamically loaded must be
called via an operating system service request.
• This method can also be thought of as a request to a
part of the loader that is kept in memory during
execution of the program
• Instead of executing a JSUB instruction to an external
symbol, the program makes a load-and-call service
request to the OS.
• The parameter of this request is the symbolic name of
the routine to be called.
14

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

Dynamic linking implementation


z However, often this is not done
immediately. If the subroutine is retained
in memory, it can be used by later calls
to the same subroutine without loading
the same subroutine multiple times.
z Control can simply pass from the
dynamic loader to the called routine
directly.

16

8
Example

Load the called


Issue a load-and-call subroutine into
service request memory

17

Control is returned The called subroutine


Control is passed
to the loader and
to the loaded this time is already loaded.
later returned to
subroutine.
the user program

Você também pode gostar