Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Linker and Libraries User's Guide: HP 9000 Computers > Chapter 8 Ways to Improve Performance

Linker Optimizations

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The linker supports the -O option which performs the following optimizations at link time:

  • optimizes references to data by removing unnecessary ADDIL instructions from the object code.

  • removes procedures that can never be reached.

These optimizations can be separately enabled or disabled with the +O[no]fastaccess and +O[no]procelim options respectively. The -O linker option simply combines enabling of these into one option. For example, the following ld command enables linker optimizations and results in a smaller, faster executable:

$ ld -O -o prog /usr/ccs/lib/crt0.o prog.o -lm -lc

To enable one or the other optimization only, use the appropriate +O option:

$ ld +Ofastaccess -o prog /usr/ccs/lib/crt0.o prog.o -lm -lc
$ ld +Oprocelim -o prog /usr/ccs/lib/crt0.o prog.o -lm -lc

Invoking Linker Optimizations from the Compile Line

The compilers automatically call the linker with the +Ofastaccess and +Oprocelim options if compiler optimization level 4 is selected. For example, the following cc command invokes full compiler optimization as well as linker optimization:

$ cc -o prog +O4 prog.c       O4 invokes +Ofastaccess and +Oprocelim

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: With the HP-UX 10.0 release, you can also invoke linker optimizations at levels 2 and 3 by using the +Ofastaccess or +Oprocelim option.

See Also:

For a brief description of compiler optimization options see “Selecting an Optimization Level with PBO ”. For a complete description, see your compiler manuals or online help.

Incompatibilities with other Options

The -O, +Ofastaccess, and +Oprocelim options are incompatible with these linker options:

-b

These options have no effect on position-independent code, so they are not useful when building shared libraries with ld -b.

-A

Dynamic linking is incompatible with link-time optimization.

-r

Relocatable linking is incompatible with link-time optimization.

-D

Setting the offset of the data space is incompatible with link-time optimization.

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 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 a per subspace basis. 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.

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 candidates for removal.

If the address of a procedure is taken, the subspace within which it resides is not removed. If a subspace is referenced in any way by a fixup representing a reference other than a PC-relative call or an absolute call it is not removed.

Incomplete Executables

For incomplete executables, dead procedure elimination works the same as for complete executables except that no exported symbols or their dependencies are removed. If an incomplete executable contains a symbol that is to be referenced by a shared library and is not exported, it is removed if the other conditions discussed above hold.

Shared Libraries

In shared libraries only symbols that are not referenced and not exported are removed. In shared libraries all symbols that are not of local scope are exported. Therefore only locally scoped symbols not referenced are removed.

Relocatable Objects

When performing a relocatable link with the -r option, dead procedure elimination is disabled since the only possible gain would be the removal of unreferenced local procedures. Objects resulting from a relocatable link are subject to dead procedure elimination upon a final link.

Affects on Symbolic Debugging

Any procedure that has symbolic debug information associated with it is not removed. Procedures that do not have symbolic debug information associated with them but are included in a debug link are removed if they are not referenced.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1997 Hewlett-Packard Development Company, L.P.