[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP OpenVMS Linker Utility Manual
2.6.2 HP C++ ExamplesThe following HP C++ examples demonstrate how symbols are resolved when you link with compiler-generated UNIX-style weak and group symbols. The examples apply a user-written function template called myswap . Note that you can also use class templates, which are implemented in a similar manner. If you are an experienced C++ programmer, you will also recognize that there is a "swap" function in the HP C++ standard library, which you should use instead of writing your own function. In the examples, the compiler combines code sections (and other required data) into a group, giving it a unique group name derived from the template instantiation. The linker includes the first occurrence of this group in the image. All UNIX-style weak definitions obtained from that group are now defined by the module providing this group. All subsequent groups with the same name do not contribute code or data; that is, the linker ignores all subsequent sections. The UNIX-style weak definitions from these ignored sections become references, which are resolved by the definition from the designated instance (that is, first-encountered instance) of the group. In this manner, code (and data) from templates are included only once for the image. Example 2-3 shows UNIX-Style weak symbols and group symbols.
Example 2-4 shows the compile and link commands.
In the examples, the compiler combines code sections (and other required data) into a group, giving it a unique group name derived from the template instantiation. The linker includes the first occurrence of this group in the image. All UNIX-style weak definitions obtained from that group are now defined by the module providing this group. All subsequent groups with the same name do not contribute code or data; that is, the subsequent sections are ignored. The UNIX-style weak definitions from these ignored sections become references, which are resolved by the definition from the designated instance (first-encountered) of the group. In this manner, code (and data) from templates are included only once for the image.
2.6.3 Compiler-Generated Symbols and Shareable ImagesTo create a VMS shareable image, you must define the interface in a symbol vector at link time with a SYMBOL_VECTOR option. HP C++ generated objects contain mangled symbols and may contain compiler-generated data, which belongs to a public interface. In the SYMBOL_VECTOR option, the interface is describe with the names from the object modules. Because they contain mangled names, such a relationship may not be obvious from the source code and the symbols as seen in an object module. If you do not export all parts of an interface, code that is intended to update one data cell may be duplicated in the executable and the shareable image along with the data cell. That is, data can become inconsistent at run-time, producing a severe error condition. This error condition can not be detected at link time nor at image activation time. Conversely, if you export all symbols from an object module, you may export the same symbol which is already public from other shareable images. A conflict arises when an application is linked with two shareable images that export the same symbol name. In this case, the linker flags the multiple definitions with a MULDEF warning that should not be ignored. This type of error most often results when using templates defined in the C++ standard library but instantiated by the user with common data types. Therefore, HP recommends that you only create a shareable image when you know exactly what belongs to the public interface. In all other cases, use object libraries and let applications link against these libraries.
The HP C++ run-time library contains pre-instantiated templates. The
public interfaces for these are known and therefore, the HP C++
run-time library ships as a shareable image. The universal symbols from
the HP C++ run-time library and the group symbols take precedence over
user instantiated templates with the same data types. As with other
shareable images, this design is upwardly compatible and does not
require you to recompile or relink to make use of the improved HP C++
run-time library.
On OpenVMS I64 systems, if a module defines a variable as data (OBJECT), it must be referenced as data by all other modules. If a module defines a variable as a procedure (FUNC), it must be referenced as a procedure by all other modules. When data is referenced as a procedure, the linker displays the following informational message:
When a procedure is referenced as data, the following informational message is displayed:
Type checking is performed by the linker on OpenVMS I64 because the linker must create function descriptors. The equivalent procedure descriptor was created by the compiler on OpenVMS Alpha, so this informational message is new for the linker on OpenVMS I64. This message is informational only and does not require user action. However, if the linker detects data referenced as a procedure, it might issue the following warning message in addition to the DIFTYPE message:
The following example of two modules demonstrates how to fix these conditions:
When these modules are linked, you get an informational message and a warning message, as follows:
To correct the problem and avoid the informational and warning messages, correct TYPE1.C to define status as a procedure:
Chapter 3
|
ELF Section Attribute1 | Traditional OpenVMS Section Attribute |
---|---|
SHF_WRITE | WRT |
SHF_EXECINSTR | EXE |
SHF_VMS_GLOBAL | GBL |
SHF_VMS_OVERLAID | OVR |
-- 2 | REL |
SHF_VMS_SHARED | SHR |
SHF_VMS_VECTOR | VEC |
SHF_VMS_ALLOC_64BIT | ALLOC_64BIT |
SHF_IA_64_SHORT | SHORT 3 |
SHT_NOBITS 4 | NOMOD 5 |
Table 3-2 lists all section attributes with the keyword you can use to set or clear the attribute, using the PSECT_ATTR= option.
Attribute | Keyword | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Alignment | -- |
Specifies the alignment of the section as an integer that represents
the power of 2 required to generate the desired alignment. For certain
alignments, the linker supports keywords to express the alignment. The
following table lists all the alignments supported by the linker with
their keywords:
|
||||||||||||||||||||||||||||||||||||||||||||||||
Position Independence | PIC/NOPIC | This keyword is ignored by the I64 linker. | ||||||||||||||||||||||||||||||||||||||||||||||||
Overlaid/Concatenated | OVR/CON | When set to OVR, specifies that the linker will overlay this section with other sections with the same name and attribute settings. Sections that are overlaid are assigned the same base address. When set to CON, the linker concatenates the sections. | ||||||||||||||||||||||||||||||||||||||||||||||||
Relocatable/Absolute | REL/ABS | When set to REL, specifies that the linker can place the section anywhere in virtual memory. Absolute sections are used by compilers primarily to define constants, but in the ELF object language they are not put into an actual section. Setting the section to ABS on I64 is not meaningful, and the ABS keyword is ignored by the I64 linker. | ||||||||||||||||||||||||||||||||||||||||||||||||
Global/Local | GBL/LCL | When set to GBL, specifies that the linker should gather contributions to the section from all clusters and place them in the same segment. When set to LCL, the linker gathers sections into the same segment only if they are in the same cluster. The memory for a global section is allocated in the cluster that contains the first contributing module. | ||||||||||||||||||||||||||||||||||||||||||||||||
Shareability | SHR/NOSHR | Specifies that the section can be shared between several processes. Only used to sort sections in shareable images. | ||||||||||||||||||||||||||||||||||||||||||||||||
Executability | EXE/NOEXE | Specifies that the section contains executable code. | ||||||||||||||||||||||||||||||||||||||||||||||||
Writability | WRT/NOWRT | Specifies that the contents of a section can be modified at run time. | ||||||||||||||||||||||||||||||||||||||||||||||||
Protected Vectors | VEC/NOVEC | Specifies that the section contains privileged change-mode vectors or message vectors. In shareable images, segments with the VEC attribute are automatically protected. | ||||||||||||||||||||||||||||||||||||||||||||||||
Solitary | SOLITARY | Specifies that the linker should place this section in its own segment. Useful for programs that map data into specific locations in their virtual memory space. Note that compilers do not set this attribute. You can set this attribute using the PSECT_ATTR= option. | ||||||||||||||||||||||||||||||||||||||||||||||||
Unmodified | NOMOD/MOD | When set, specifies that the section has not been initialized (NOMOD). The I64 linker uses this attribute to create demand zero segments; see Section 3.4.4. Only compilers can set this attribute (in ELF objects, the section type SHT_NOBITS). You can clear this attribute only by specifying the MOD keyword in the PSECT_ATTR= option. | ||||||||||||||||||||||||||||||||||||||||||||||||
Readability | RD | This keyword is ignored by the I64 linker. | ||||||||||||||||||||||||||||||||||||||||||||||||
User/Library | USR/LIB | This keyword is ignored by the I64 linker. | ||||||||||||||||||||||||||||||||||||||||||||||||
Short Data | SHORT | When set this indicates that a data section should be put in one of the short sections. Compilers can set this attribute, in which case the user can not alter it. | ||||||||||||||||||||||||||||||||||||||||||||||||
Allocate section in P2 space | ALLOC_64BIT/NOALLOC_64BIT | When set this indicates that the section should be allocated in P2 space instead of P0 space. The program may run but not execute correctly when initialized data is put in P2 space. Code and demand zero data do work properly. |
Previous | Next | Contents | Index |