Fortran User's Guide

-pic

Compile position-independent code for shared library.

    SPARC: 77/90 x86:77

This kind of code is for dynamic shared libraries. Each reference to a global datum is generated as a dereference of a pointer in the global offset table. Each function call is generated in program-counter-relative addressing mode through a procedure linkage table.

-pic is equivalent to -xcode=pic13.

There are two nominal performance costs with -pic and -PIC:

When considering the above costs, remember that the use of -pic and -PIC can significantly reduce system memory requirements, due to the effect of library code sharing. Every page of code in a shared library compiled -pic or -PIC can be shared by every process that uses the library. If a page of code in a shared library contains even a single non-pic (that is, absolute) memory reference, the page becomes nonsharable, and a copy of the page must be created each time a program using the library is executed.

The easiest way to tell whether or not a .o file has been compiled with -pic or -PIC is with the nm command:


% nm  file.o | grep _GLOBAL_OFFSET_TABLE_ 
U _GLOBAL_OFFSET_TABLE_

A .o file containing position-independent code contains an unresolved external reference to _GLOBAL_OFFSET_TABLE_, as indicated by the letter U.

To determine whether to use -pic or -PIC, use nm to identify the number of distinct global and static variables used or defined in the library. If the size of _GLOBAL_OFFSET_TABLE_ is under 8,192 bytes, you can use -pic. Otherwise, you must use -PIC.

When building shared dynamic libraries with -xarch=v9 or v9a on 64-bit Solaris 7, the -pic or -PIC option, or their -xcode equivalents, must be specified.