HP-UX Linker and Libraries User's Guide

If invoked with +O4, the compilers generate object code in such a way that code optimization is done at link
time. Thus, the linker does a better job of optimizing code that was compiled with +O4.
When the compile and link phases are invoked by separate commands, specify +O4 on both
command lines. For example:
$ cc -c +O4 prog.c //invokes compiler optimizations
$ cc -o prog +O4 prog.o //invokes linker optimizations
NOTE: You can also invoke linker optimizations at levels 2 and 3 by using the +Ofastaccess or
+Oprocelim option.
For a brief description of compiler optimization options, see “Optimizing Based on Profile Data
(+P/-P)” (page 210) . For a complete description, see your compiler documentation.
Incompatibilities with other Options
The -O, +Ofastaccess, and +Oprocelim options are incompatible with the following linker
options:
These options have no effect on position-independent code, so they are not useful when building shared
libraries with ld -b.
-b
(PA32 only) Dynamic linking is incompatible with link-time optimization.-A
Relocatable linking is incompatible with link-time optimization.-r
Setting the offset of the data space is incompatible with link-time optimization.-D
The linker issues a warning when such conflicts occur. If you require any of these features, do not
use the linker optimization options.
Unused Procedure Elimination with +Oprocelim
Unused or "dead" procedure elimination is the process of removing unreferenced procedures from
the $TEXT$ space (or .text section in the case of ELF object file) of an executable or shared
library to reduce the size of the program or library.
Dead procedure elimination is performed after all symbols have been resolved prior to any
relocation. It works on the basis of per subspace (per section in the case of ELF object file). That
is, only entire subspaces are removed and only if all procedures in the subspace are unreferenced.
Typically, if a relocatable link (ld -r) has not been performed and the code is not written in
assembly, every procedure is in its own subspace. Relocatable links may merge subspaces. Merged
subspaces can prevent the removal of dead procedures. Therefore, it is optimal to have each
procedure in its own subspace.
Along with dead procedures, the +Oprocelim option removes unreferenced data and debug
information associated with the dead procedures.
If your program does symbol binding at run-time, rather than at link-time, be cautious about using
the +Oprocelim option. The +Oprocelim option works on most compiler-generated
subspace/sections.
The +Onoprocelim is the default procelim option in linker. Compilers often automatically pass
+Oprocelim to the linker for higher levels of optimization. For more information on when compilers
automatically pass +Oprocelim to the linker for higher levels of optimization, refer the Compiler
documentation.
Complete Executables
For complete executables, dead procedure elimination removes any text subspaces that are not
referenced from another subspace. Self-references, such as recursive procedures or subspaces with
multiple procedures that call each other, are not considered outside references and are therefore
Linker Optimizations 203