Linking a Program [ Getting Started as an MPE/iX Programmer Programmer's Guide ] MPE/iX 5.0 Documentation
Getting Started as an MPE/iX Programmer Programmer's Guide
Linking a Program
Many executable programs are originally generated from more than one
source file. On MPE/iX, each source file is compiled separately to
produce a relocatable object module. The linking phase of program
development makes a relocatable object file into an executable program
file. It can also bring together separately compiled relocatable object
modules into an executable program file.
Use the MPE/iX command :LINK to automatically access Link Editor to
create an executable program file from one or more relocatable object
modules.
NOTE Link Editor on MPE/iX replaces Segmenter on MPE V/E. You can still
use Segmenter in MPE/iX Compatibility Mode. For detailed
information, refer to MPE Segmenter Reference Manual (30000-90011).
For an explanation of the differences between Link Editor and
Segmenter, refer to Link Editor/XL Reference Manual (32650-90030).
:LINK is the MPE/iX counterpart to :PREP on MPE V/E systems.
However, it operates differently and has different options. For an
explanation of the differences between :LINK and :PREP, refer to
Link Editor/XL Reference Manual (32650-90030). Figure 3-3
shows the role of :LINK and Link Editor in MPE/iX.
Figure 3-3. Linking and Using User Libraries
:LINK operates on one or more relocatable object modules created by a
native compiler to perform the following tasks:
* Search one or more relocatable libraries (RLs) and resolve
references to them in any of the relocatable object modules being
linked.
* Resolve references among the relocatable object modules.
* Merge all the relocatable object modules associated with one
program to create an executable program file.
If you use language commands that compile, link, and execute in one
command (for example, :PASXLGO and :COB85XLG) or compile and link in one
command (for example, :PASXLLK and :FTNXLLK), then linking is automatic.
When you compile separately, you can use the MPE/iX command :LINK to
produce an executable program file. Use this method when you want to use
values different from standard Link Editor defaults. :LINK invokes Link
Editor and passes the specified parameters to it. (An analogous LINK
command exists in Link Editor; the MPE/iX command :LINK simply provides a
short cut.)
Creating Executable Program Files
The MPE/iX command :LINK creates a load module (an executable program
file). The :LINK command invokes Link Editor, which is an MPE/iX
subsystem that prepares compiled programs for execution and maintains
libraries. When invoked by using :LINK, Link Editor resolves external
references in relocatable object modules by merging relocatable object
modules to produce an executable program file containing all of the code
and data that was in the relocatable object modules.
It assigns final addresses to each symbol (for a variable or procedure)
to ensure that none overlap each other in the executable program file.
These addresses are called virtual addresses, because they are still
subject to a final relocation when the program is loaded into physical
memory. Once virtual addresses are determined, Link Editor can resolve
many of the references that could not be resolved at compile time,
because the symbol tables from all of the relocatable object modules have
been merged to one table. You can specify the relocatable libraries to
search for unresolved references at link time. Any remaining external
calls must be resolved at load time.
:LINK parameters can specify indirect files. An indirect file is a file
list contained in an ASCII file. For example, in the :LINK command, an
indirect file can be used to specify one of the following lists:
* Files to link
* Relocatable libraries (RLs) to merge
* Executable libraries (XLs) names to put in a program header
For an overview of Link Editor, refer to Chapter 4. For detailed
information on :LINK and Link Editor, refer to Link Editor/XL Reference
Manual (32650-90030).
You can request options at link time to:
* Produce a program file map.
* Search specified relocatable libraries (RLs) for any required code
not found in the relocatable object module.
* Give the executable program file certain privileges and
capabilities.
Symbol Listing
Example 3-1 shows a source file named EX1SRC. An executable program file
has been created for EX1SRC named EX1PROG.
____________________________________________________
| |
| IDENTIFICATION DIVISION. |
| PROGRAM-ID. EX1 |
| ENVIRONMENT DIVISION. |
| INPUT-OUTPUT DIVISION. |
| FILE-CONTROL. |
| SELECT IFILE ASSIGN "IFILE".|
| SELECT PFILE ASSIGN "PFILE".|
| DATA DIVISION. |
| FILE SECTION. |
| FD IFILE. |
| 01 IREC. |
| 05 NAME PIC X(30). |
| 05 SOC-SEC PIC X(9). |
| 05 HIRE-DATE. |
| 10 MO PIC XX. |
| 10 DA PIC XX. |
| 10 YR PIC XX. |
| 05 SALARY PIC S9(6). |
| 05 PIC X(29). |
| FD PFILE. |
| 01 PREC. |
| 05 SOC-SEC PIC X(9). |
| 05 PIC XX. |
| 05 NAME PIC X(30). |
| 05 PIC XX. |
| 05 HIRE-DATE. |
| 10 MO PIC XX. |
| 10 PIC X. |
| 10 DA PIC XX. |
| 10 PIC X. |
| 10 YR PIC XX. |
| 05 PIC X(81). |
| 01 HREC. |
| 05 HSOC-SEC PIC X(11). |
| 05 HNAME PIC X(32). |
| 05 HHIRE-DATE PIC X(89). |
| |
| |
| |
| |
| |
____________________________________________________
Example 3-1. Source File Example (page 1 of 2)
_____________________________________________________________________
| |
| WORKING STORAGE SECTION. |
| 01 LNCNT PIC S9(4) BINARY VALUE 60. |
| 01 W-DATE. |
| 05 WYR PIC XX. |
| 05 PIC X(4). |
| PROCEDURE DIVISION. |
| P1. |
| ACCEPT W-DATE FROM DATE. |
| OPEN INPUT IFILE OUTPUT PFILE. |
| PERFORM WITH TEST AFTER UNTIL SOC-SEC OF IREC = ALL "9" |
| READ IFILE |
| AT END MOVE ALL "9" TO SOC-SEC OF IREC |
| NOT AT END |
| IF WYR = YR OF IREC THEN |
| ADD 1 TO LNCNT |
| IF LNCNT > 50 PERFORM HEADINGS END-IF|
| MOVE SPACES TO PREC |
| MOVE CORR IREC TO PREC |
| WRITE PREC AFTER ADVANCING 1 LINE |
| END-IF |
| END-READ |
| END PERFORM |
| CLOSE IFILE PFILE |
| STOP RUN. |
| HEADINGS. |
| MOVE "SOC-SEC" TO HSOC-SEC. |
| MOVE "NAME" TO HNAME. |
| MOVE "HIRE DATE" TO HHIRE-DATE. |
| WRITE PREC AFTER ADVANCING PAGE. |
| MOVE 0 TO LNCNT. |
| |
| |
| |
| |
| |
_____________________________________________________________________
Example 3-1. (page 2 of 2)
The commands
:LINKEDIT
LinkEd> LISTPROG EX1PROG
invoke HP Link Editor/XL and create a program map displaying the symbols
in EX1PROG, as shown in the following example:
PROGRAM : EX1PROG
XL LIST
CAPABILITIES : BA, IA
HEAP SIZE :
STACK SIZE :
VERSION : 85082112
Sym C H X P Sym Sym Sym Lset
Name Type Scope Value Name
---- - - - - ---- ----- ----- ----
$START 0 3 3 sec_p univ 000059B7
_start 0 3 3 sec_p univ 00005A07
ex1 0 3 3 pri_p univ 000059EB
M$1 0 data local dp+00000000
In this program map, the portion preceding the symbol table is the
header, which provides general information about the executable program
file:
* PROGRAM names the executable program file.
* XL LIST shows the names of executable libraries specified in the
XL parameter of the LINK command.
* CAPABILITIES shows the capabilities assigned to the program in the
CAP parameter of the LINK command.
* HEAP SIZE shows the value specified in the NMHEAP parameter of the
LINK command.
* STACK SIZE shows the value specified in the NMSTACK parameter of
the LINK command.
* VERSION shows the executable program file format version.
The header information is followed by a list of symbols in the executable
program file. For information on understanding the symbol listing, refer
to Link Editor/XL Reference Manual (32650-90030).
MPE/iX 5.0 Documentation