Chapter 15
Storage Allocation
This chapter describes the following topics:
Program sections, which are groupings of data made by the compiler and used by the linker
The addressability of variables
Refer to the Endless PL/I for OpenVMS Reference Manual for information on storage classes.
15.1. Program Sections
When the PL/I compiler creates an object module, it groups data in the object module into contiguous areas called program sections. The data is grouped according to its attributes-for example, whether it contains executable code or read/write variables.
The compiler also writes, into each object module, information about the program sections contained in it. The linker uses this information when it binds object modules into an executable image. As the linker allocates virtual memory for the image, it groups program sections that have similar attributes.
15.1.1. Attributes of Program Sections
Table 15.1, “Program Section Attributes” lists the attributes that can be applied to program sections.
| Attribute[a] | Meaning |
|---|---|
| PIC or NOPIC | The program section or data it refers to does not depend on any specific virtual memory location (PIC), or the program section depends on one or more virtual memory locations (NOPIC). |
| CON or OVR | The program section will be concatenated with other program sections with the same name (CON), or will be overlaid on the same memory locations (OVR). |
| REL or ABS | The data in the program section must be relocated to a virtual memory address (REL), or does not occupy virtual memory (ABS). |
| GBL or LCL | The program section contains definitions for symbols that are shared with other program sections or modules (GBL), or are local to the current program section (LCL). |
| EXE or NOEXE | The program section contains executable code (EXE), or does not contain executable code (NOEXE). |
| WRT or NOWRT | The program section contains data that can be modified (WRT), or data that cannot be modified (NOWRT). |
| RD or NORD | These attributes are not currently used. |
| SHR or NOSHR | The program section can be shared in memory (SHR), or cannot be shared in memory (NOSHR). |
[a] This column lists pairs of conflicting attributes. | |
15.1.2. Program Sections Created by Endless PL/I V3.9 for OpenVMS VAX
Endless PL/I V3.9 for OpenVMS VAX creates the following program sections for every program:
$CODE-contains all executable code and constant data.
$DATA-contains all internal static variables.
PL/I also creates additional program sections for external variables and global symbols. Table 15.2, “Program Sections for VAX PL/I Variables” summarizes the program sections that PL/I creates for variables declared with different storage class attributes.
|
Storage Class Attributes |
Program Section Name[a] |
Program Section Attributes |
|---|---|---|
| EXTERNAL CONTROLLED | name |
PIC, OVR, REL, GBL, NOSHR, NOEXE, RD, WRT |
| EXTERNAL STATIC[a] | name |
PIC, OVR, REL, GBL, SHR, NOEXE, RD, WRT |
| EXTERNAL READONLY | name |
PIC, OVR, REL, GBL, SHR, NOEXE, RD, NOWRT |
| INTERNAL STATIC | $DATA |
PIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT |
| INTERNAL READONLY | $CODE |
PIC, CON, REL, LCL, SHR, EXE, RD, NOWRT |
| GLOBALDEF | $DATA |
PIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT |
GLOBALDEF (psect-name) |
psect-name
|
PIC, CON, REL, GBL, SHR, NOEXE, RD, WRT |
| GLOBALDEF READONLY | $CODE |
PIC, CON, REL, LCL, SHR, EXE, RD, NOWRT |
| GLOBALDEF READONLY | psect-name |
PIC, CON, REL, GBL, SHR, NOEXE, RD, NOWRT |
[a] File constants have the same attributes as EXTERNAL STATIC variables, but with the NOSHR attribute instead of the SHR attribute. | ||
15.1.3. Program Sections Created by Endless PL/I V5.0 for OpenVMS Alpha
PL/I creates the following program sections for every program:
$CODE$-contains all executable code and constant data.
$LINK$-contains all linkage data subject to link-time address fixups.
PL/I also creates additional program sections for external variables and global symbols. Table 15.3, “Program Sections for Alpha PL/I Variables” summarizes the program sections that PL/I creates for variables declared with different storage class attributes.
|
Storage Class Attributes |
Program Section Name[a] |
Program Section Attributes |
|---|---|---|
| EXTERNAL CONTROLLED | name |
NOPIC, OVR, REL, GBL, NOSHR, NOEXE, WRT, NOMOD |
| EXTERNAL | name |
NOPIC, OVR, REL, GBL, NOSHR, NOEXE, WRT, NOMOD |
| GLOBALDEF FILE | $DATA$ |
NOPIC, CON, REL, LCL, NOSHR, NOEXE, WRT, MOD |
| FILE | name |
NOPIC, OVR, REL, GBL, NOSHR, NOEXE, WRT, MOD |
| EXTERNAL READONLY | name |
NOPIC, OVR, REL, GBL, NOSHR, NOEXE, NOWRT, NOMOD |
| CONDITION | name |
NOPIC, OVR, REL, GBL, NOSHR, NOEXE, NOWRT, NOMOD |
|
STATIC or GLOBALDEF | $BSS$ |
NOPIC, CON, REL, LCL, NOSHR, NOEXE, WRT, NOMOD |
|
INITIAL or GLOBALDEF INITIAL | $DATA$ |
NOPIC, CON, REL, LCL, NOSHR, NOEXE, WRT, NOMOD |
|
READONLY or GLOBALDEF READONLY | $LITERAL$ |
PIC, CON, REL, LCL, SHR, NOEXE, NOWRT, MOD |
GLOBALDEF (psect-name) |
psect-name
|
NOPIC, CON, REL, GBL, NOSHR, NOEXE, WRT, NOMOD |
GLOBALDEF (psect-name) READONLY |
psect-name
|
NOPIC, CON, REL, GBL, NOSHR, NOEXE, NOWRT, NOMOD |
| FORMAT | $DPLI_FMTCONST$ |
NOPIC, CON, REL, LCL, NOSHR, NOEXE, NOWRT, MOD |
15.1.4. Sharing Program Sections with FORTRAN Procedures
In a FORTRAN program, separately compiled procedures share data by declaring common sections and specifying the names of one or more variables to be placed in those sections. Each named common section represents a separate program section; each procedure that declares the common section with the same name can access the same variable.
A PL/I external variable called XYZ therefore corresponds to a FORTRAN common section called XYZ. The following examples illustrate PL/I procedures and FORTRAN procedures that share data.
STRING.PLI
STRING: PROCEDURE OPTIONS(MAIN); DECLARE XYZ EXTERNAL CHARACTER(20), PRSTRING ENTRY; XYZ = 'THIS IS A STRING'; CALL PRSTRING; END;
PRSTRING.FOR
SUBROUTINE PRSTRING
CHARACTER*20 STRING
COMMON /XYZ/ STRING
WRITE (6,20) STRING
20 FORMAT (' ',A20)
RETURN
ENDIn this example, the PL/I external variable XYZ corresponds to the FORTRAN common section named XYZ. The FORTRAN procedure displays the data in the common section.
To share more than one variable in a program section with a FORTRAN program, the PL/I variables must be declared within a structure. For example:
NUMBERS.PLI
NUMBERS: PROCEDURE; DECLARE 1 NUMBERS EXTERNAL, 2 FIRST FIXED(31), 2 SECOND FIXED(31), 2 THIRD FIXED(31), FNUM ENTRY; FIRST = 1; SECOND = 2; THIRD = 3; CALL FNUM; END;
FNUM.FOR
SUBROUTINE FNUM
INTEGER*4 INUM,JNUM,KNUM
COMMON /NUMBERS/ INUM,JNUM,KNUM
WRITE (6,10) (INUM,JNUM,KNUM)
10 FORMAT (3I8)
RETURN
ENDIn this example, the fixed binary variables declared in the PL/I external structure NUMBERS correspond to the FORTRAN INTEGER*4 variables in the common section of the same name. Note that in a FORTRAN common section, all variables must be either integers or character strings. Variables of different data types cannot be grouped into the same common section.
15.2. Addressability
Variables are either addressable or nonaddressable. In some contexts, such as in argument lists of certain built-in functions, a variable must be addressable. A variable is addressable if it has all of the following properties:
It is not suitable for bit-string overlay defining; that is, it does not consist entirely of unaligned bit data.
It is not an unconnected array (typically a member of an array of structures).
It is not declared with the VALUE attribute.
These rules ensure that the variable can occupy contiguous storage beginning on a byte boundary. (Note that constants are never addressable in PL/I.)