HPlogo HP C/HP-UX Release Notes for HP-UX 11.0: HP 9000 Computers > Chapter 1 New and Changed Features

Improving Shared Library Performance

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The pragmas described here can improve performance of shared libraries by reducing the overhead of calling shared library routines. All three pragmas should be used together, where applicable, as they depend on one another to a certain extent. You must be very careful using these pragmas because incorrect use can result in incorrect and unpredictable behavior. See the HP-UX Linker and Libraries User's Guide for more information on improving shared library performance.

HP_NO_RELOCATION Pragma

This pragma improves performance of shared library calls by omitting floating-point parameter relocation stubs in calls to shared library functions. Put this pragma in header files of functions that take floating point parameters or return floating point data and that will be placed in shared libraries. Putting it in the header file and ensuring all calls reference the header file is one way to ensure that it is specified at the function definition and at all calls.

WARNING! This pragma must be at the function definition and at all call sites. If the pragma is omitted from the function definition or from any call, the linker will generate parameter relocation code and the application will behave incorrectly since floating point parameters will not be in expected registers.

Syntax

#pragma HP_NO_RELOCATION name1[, name2[, ...]]

where name1, name2, and so forth are names of functions in shared libraries.

Background

Parameter relocation stubs are instructions that move (relocate) floating point parameters and function return values between floating point registers and general registers. They are generated for calls to routines in shared libraries. Relocation stubs are generated when passing floating point parameters or using a floating point function return in routines in shared libraries. This pragma prevents this unnecessary relocation from being done.

NOTE: Do not use this option with functions that use the varargs macros. See the HP C/HP-UX Reference Manual or the varargs(5) man page for information on the varargs macros.

HP_LONG_RETURN Pragma

This pragma improves performance of shared library calls by using a long return instruction sequence instead of an interspace branch and by omitting export stubs. An export stub is a short code segment generated by the linker for a global definition in a shared library. External calls to shared library functions go through the export stub.

Put this pragma in header files of functions that will go in shared libraries so it is specified at the function definition and at all calls. For functions with floating point parameters or returns, use the HP_NO_RELOCATION pragma along with this pragma.

WARNING! This pragma must be at the function definition and at all call sites. If the pragma is omitted from the function definition or from any call, the compiler will generate incompatible return code and the application will behave incorrectly.

Syntax

#pragma HP_LONG_RETURN name1[, name2[, ...]]

where name1, name2, and so forth are names of functions in shared libraries.

Background

An export stub is generated by default for each function in a shared library. Each call to the function goes through the export stub. The export stub serves two purposes: to relocate parameters and perform an interspace return.

The HP_LONG_RETURN pragma generates a long return sequence in the export stub instead of an interspace branch. If you also use the HP_NO_RELOCATION pragma (for functions taking floating point parameters), all the code in the export stub is omitted, eliminating the export stub entirely. For functions taking non-floating-point parameters, the HP_LONG_RETURN pragma by itself eliminates the need for export stubs.

NOTE: Using HP_LONG_RETURN without using HP_NO_RELOCATION with floating point parameters, could actually degrade performance by creating export stubs and relocation stubs.

These pragmas improve performance of calls to shared library functions from outside the shared library. Therefore do not use this pragma for hidden functions (see the -h and +e linker options) or for functions called only from within the same shared library linked with the -B symbolic linker option, otherwise this pragma may degrade performance. (See the HP-UX Linker & Libraries User's Guide for information on the above mentioned options.)

Do not use this pragma if you compile on PA-RISC 2.0 or later or with the +DA2.0 option since the effect is the default. That is, if no relocations are generated, export stubs are not generated on PA-RISC 2.0 and later, and a long return instruction sequence is generated by default, so this pragma has no effect.

HP_DEFINED_EXTERNAL Pragma

This pragma improves performance of shared library calls by inlining import stubs. Place this pragma at calls to shared library routines along with the HP_NO_RELOCATION pragma (if using floating-point parameters or return values) and the HP_LONG_RETURN pragma.

WARNING! Do not use this pragma at function definitions, only at function calls. Specifying it at function definitions will result in incorrect behavior.

On PA-RISC 1.1, use this pragma only when calling a shared library from an executable file. Using it on calls within an executable file will cause the program to abort.

Syntax

#pragma HP_DEFINED_EXTERNAL name1[, name2[, ...]]where name1, name2, and so forth are names of functions in shared libraries.

Background

Import stubs are code sequences generated at calls to shared library routines. The import stub queries the PLT (Procedure Linkage Table) to determine the address of the shared library function & calls it. The HP_DEFINED_EXTERNAL pragma inlines this import stub.

NOTE: If your function takes floating-point parameters, you should also use the HP_NO_RELOCATION pragma (if floating point parameters are present). You should also use the HP_LONG_RETURN pragma with this pragma. If you don't, the import stub may be too large to inline.

Use this pragma only on calls to functions in shared libraries. On PA-RISC 2.0, it will degrade performance of calls to any other functions.

© 1999 - Hewlett-Packard Development Company, L.P.