Sun Studio 12 Update 1: C++ User's Guide

A.2.142 -xlinkopt[=level]

Instructs the compiler to perform link-time optimization on the resulting executable or dynamic library over and above any optimizations in the object files. These optimizations are performed at link time by analyzing the object binary code. The object files are not rewritten but the resulting executable code may differ from the original object codes.

You must use -xlinkopt on at least some of the compilation commands for -xlinkopt to be useful at link time. The optimizer can still perform some limited optimizations on object binaries that are not compiled with -xlinkopt.

-xlinkopt optimizes code coming from static libraries that appear on the compiler command line, but it skips and does not optimize code coming from shared (dynamic) libraries that appear on the command line. You can also use -xlinkopt when you build shared libraries (compiling with -G).

A.2.142.1 Values

level sets the level of optimizations performed, and must be 0, 1, or 2. The optimization levels are:

Table A–37 The -xlinkopt Values



The link optimizer is disabled. (This is the default.) 

Perform optimizations based on control flow analysis, including instruction cache coloring and branch optimizations, at link time. 

Perform additional data flow analysis, including dead-code elimination and address computation simplification, at link time. 

If you compile in separate steps, -xlinkopt must appear on both compile and link steps:

example% cc -c -xlinkopt a.c b.c
example% cc -o myprog -xlinkopt=2 a.o

Note that the level parameter is only used when the compiler is linking. In the example above, the link optimizer level is 2 even though the object binaries are compiled with an implied level of 1.


Specifying -xlinkopt without a level parameter implies -xlinkopt=1.


This option is most effective when you use it to compile the whole program, and with profile feedback. Profiling reveals the most and least used parts of the code and building directs the optimizer to focus its effort accordingly. This is particularly important with large applications where optimal placement of code performed at link time can reduce instruction cache misses. Typically, this compiles as follows:

example% cc -o progt -xO5 -xprofile=collect:prog file.c
example% progt
example% cc -o prog -xO5 -xprofile=use:prog -xlinkopt file.c

For details on using profile feedback, see A.2.170 -xprofile=p.


Do not use the -zcombreloc linker option when you compile with -xlinkopt.

Note that compiling with this option increases link time slightly. Object file sizes also increase, but the size of the executable remains the same. Compiling with -xlinkopt and -g increases the size of the executable by including debugging information.