How HP Link Editor/XL Works [ HP Link Editor/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Link Editor/XL Reference Manual
How HP Link Editor/XL Works
HP Link Editor/XL (the "link editor") processes object code produced by
high-level language compilers, such as HP COBOL II. Object code is saved
in relocatable object files. The link editor links relocatable object
files for execution by assigning memory locations to them and any
external routines that they use.
In addition to creating executable program files, you can use HP Link
Editor/XL to create and maintain relocatable and executable libraries.
The next three sections discuss the tasks of creating executable program
files, and using relocatable and executable libraries in more detail.
Creating Executable Program Files
Source files can contain one or more programs, procedures or subprograms.
If you compile the program using the RLFILE option, each program,
procedure or subprogram in the source file is a separate compilation unit
and produces a separate relocatable object module in a relocatable
library. If you compile without using the RLFILE option, the source file
(no matter how many programs, procedures or subprograms it contains) is
one compilation unit and produces one relocatable object module. After
compilation, HP Link Editor/XL transforms the relocatable object file or
modules into an executable program file. Figure 1-1 depicts this
process.
Figure 1-1. Creating an Executable Program File
When the link editor links separately compiled relocatable object files
or relocatable modules from a relocatable library, it must be able to
find procedure and variable name references ( symbols) used in the
modules. Since compilers process only one compilation unit at a time,
they cannot resolve references outside the compilation unit. The
unresolved references are called external references. Compilers generate
a symbol table in each relocatable object module which allows the link
editor to resolve external references. The symbol table lists all
subroutine and variable names that are defined (or exported) by that
object module. It also lists all subroutine and variable names that are
referenced ( imported) but not defined by that module. The compiler then
assigns relative (relocatable) addresses to the exported symbols in the
module.
HP Link Editor/XL begins by merging relocatable object modules so that
the executable program contains all the code and data in the input files.
Figure 1-2 shows how an executable program file is created from three
relocatable object files.
Figure 1-2. Creating an Executable Program File from Three Relocatable Object Files
If a relocatable library is searched during linking, only those modules
that export unresolved symbols are included in the executable program
file. When relocatable object modules are merged, many external
references are resolved. References that are still unresolved are
external calls and are resolved when the program is loaded for execution.
(The loader subsystem of the MPE XL operating system resolves external
calls. It searches executable libraries and the MPE XL System Library.)
Finally, the link editor assigns virtual addresses to each symbol,
assuring that there are no address overlaps. Although the addresses are
"final" addresses, they can still be relocated when the program is loaded
for execution.
Chapters 3 and 4 give more information about executable program files.
Using Relocatable Libraries
A relocatable library (RL) is a file containing one or more relocatable
object modules which can be incorporated into executable program files
during linking. Use relocatable libraries for routines that you want to
become integral parts of executable program files. When a relocatable
object module is linked into a program, the program contains its own
unique copy of the module. Changes to the relocatable object module in
the library are not reflected in the linked program unless the program is
relinked. Routines linked from relocatable libraries can share global
data.
Each relocatable library contains a Library Symbol Table (LST) at the
beginning of the file. The LST lists each exported symbol in each module
of the library.
You can create as many relocatable libraries as you need. You can add
modules to a relocatable library from relocatable object files. You can
also copy modules from one relocatable library to another or to a
relocatable object file, and you can purge and list modules in a
relocatable library. For more information on relocatable libraries, see
chapters 3 and 5.
Using Executable Libraries
An executable library file contains one or more executable modules that
you can load into memory and use at run time. Although the loader
searches the executable libraries at run time, you can use the link
editor to identify the ones to search in an executable program file. Put
routines in executable libraries when the routines are used by programs
that are run concurrently. The programs can then use the same physical
copy of code.
NOTE Routines in executable libraries cannot share global data with the
calling program and cannot have outer blocks.
Each executable library contains a Library Symbol Table (LST) at the
beginning of the file. During linking, the link editor places unresolved
references in an import list in each executable program file. At run
time, the loader resolves the symbols in the import list by searching
Library Symbol Tables in one or more executable libraries. It builds an
External Reference Table (XRT) that tracks externally-called procedures
and allows them to be shared.
You can search as many executable libraries as you need. You can add
relocatable object modules to an existing library, merging them when
necessary. You can copy executable modules from one library to another,
purge executable modules from a library, and list the contents of an
executable library. For more information about executable libraries, see
chapters 3 and 6.
MPE/iX 5.0 Documentation