| C++ User's Guide |      | 
C++ Compiler Options
This chapter details the command-line options for the
CCcompiler running under Solaris 2.6, Solaris 7, and Solaris 8. The features described apply to all platforms except as noted; features unique to one platform are identified as SPARC or IA. See Multiplatform Release" in the preface for more information.The following table shows examples of typical option syntax formats.
TABLE 3-1 Option Syntax Format Examples option-E-optionvalue-Ipathname-option=value-xunroll=4-optionvalue-ofilename
The typographical conventions in TABLE P-1 are used in this section of the manual to describe individual options.
Parentheses, braces, brackets, pipe characters, and ellipses are metacharacters used in the descriptions of the options and are not part of the options themselves.
Some general guidelines for options are:
- The
-llib option links with libraryliblib.a(orliblib.so). It is always safer to put-llib after the source and object files to ensure the order in which libraries are searched.- In general, processing of the compiler options is from left to right (with the exception that
-Uoptions are processed after all-Doptions), allowing selective overriding of macro options (options that include other options). This rule does not apply to linker options.- The
-I,-L,-pti, and-Roptions accumulate, they do not override.Source files, object files, and libraries are compiled and linked in the order in which they appear on the command line.
3.1 Options Summarized by Function
In this section, the compiler options are grouped by function to provide a quick reference.
3.1.1 Code Generation Options
The following code generation options are listed in alphabetical order.
3.1.2 Debugging Options
The following debugging options are listed in alphabetical order.
3.1.3 Floating-Point Options
The following floating-point options are listed in alphabetical order.
3.1.4 Language Options
The following language options are listed in alphabetical order.
TABLE 3-5 Language Options Sets the major release compatibility mode of the compiler. -compatEnables or disables various C++ language features. -features=alst
3.1.5 Library Options
The following library linking options are listed in alphabetical order.
3.1.6 Licensing Options
The following licensing options are listed in alphabetical order.
TABLE 3-7 Licensing Options Disables license queueing. -noqueueSPARC: Links in the Sun Performance Library. -xlic_lib=sunperfShows license server information. -xlicinfo
3.1.7 Obsolete Options
The following options are obsolete or will become obsolete.
3.1.8 Output Options
The following output options are listed in alphabetical order.
3.1.9 Performance Options
The following performance options are listed in alphabetical order.
3.1.10 Preprocessor Options
The following preprocessor options are listed in alphabetical order.
3.1.11 Profiling Options
The following profiling options are listed in alphabetical order.
3.1.12 Reference Options
The following options provide a quick reference to compiler information.
3.1.13 Source Options
The following source options are listed in alphabetical order.
TABLE 3-14 Source Options Adds pathname to the includefile search path.-IpathnameOutputs makefile dependency information. -xMGenerates dependency information, but excludes /usr/include.-xM1
3.1.14 Template Options
The following template options are listed in alphabetical order.
3.1.15 Thread Options
The following thread options are listed in alphabetical order.
TABLE 3-16 Thread Options Compiles and links for multithreaded code. -mtSPARC: Allows no memory-based traps. -xsafe=mem
3.1.16 How Option Information Is Organized
To help you find information, compiler option descriptions are separated into the following subsections. If the option is one that is replaced by or identical to some other option, see the description of the other option for full details.
3.2 Option Reference
3.2.1
-386IA: Same as
-xtarget=386. This option is provided for backward compatibility only.3.2.2
-486IA: Same as
-xtarget=486. This option is provided for backward compatibility only.3.2.3
-a3.2.4
-BbindingSpecifies whether a library binding for linking is symbolic, dynamic (shared), or static (nonshared).
You can use the
-Boption to toggle several times on a command line. This option is passed to the linker,ld.
Note  On the Solaris 7 and Solaris 8 platforms, not all libraries are available as static libraries.
Values
binding must be one of the following:
(No space is allowed between
-Band the binding value.)Defaults
If -
Bis not specified,-Bdynamicis assumed.Interactions
To link the C++ default libraries statically, use the
-staticliboption.The
-Bstaticand-Bdynamicoptions affect the linking of the libraries that are provided by default. To ensure that the default libraries are linked dynamically, the last use of-Bshould be-Bdynamic.Examples
The following compiler command links
libfoo.aeven iflibfoo.soexists; all other libraries are linked dynamically:
CC a.o -Bstatic -lfoo -BdynamicWarnings
If you compile and link in separate steps and are using the
-Bbinding option, you must include the option in the link step.When building a shared library in compatibility mode (
-compat[=4]), do not use -Bsymbolic if the library has exceptions in it. Exceptions that should be caught might be missed.See also
-nolib,-staticlib,ld(1), Section 5.5 "Statically Linking Standard Libraries"," Linker and Libraries Guide3.2.5
-cCompile only; produce object
.ofiles, but suppress linking.This option directs the
CCdriver to suppress linking withldand produce a.ofile for each source file. If you specify only one source file on the command line, then you can explicitly name the object file with the-ooption.Examples
If you enter
CC -c x.cc, thex.oobject file is generated.If you enter
CC -c x.cc -o y.o, they.oobject file is generated.Warnings
When the compiler produces object code for an input file (
.c,.i), the compiler always produces a.ofile in the working directory. If you suppress the linking step, the.ofiles are not removed.See also
3.2.6
-cg[89|92]3.2.7
-compat[=(4|5)]Sets the major release compatibility mode of the compiler. This option controls the
__SUNPRO_CC_COMPATand__cplusplusmacros.The C++ compiler has two principal modes. The compatibility mode accepts ARM semantics and language defined by the 4.2 compiler. The standard mode accepts constructs according to the ANSI/ISO standard. These two modes are incompatible with each other because the ANSI/ISO standard forces significant, incompatible changes in name mangling, vtable layout, and other ABI details. These two modes are differentiated by the
-compatoption as shown in the following values.Values
The
-compatoption can have the following values.
Defaults
If the
-compatoption is not specified,-compat=5 is assumed.If only
-compatis specified,-compat=4is assumed.Regardless of the
-compatsetting,__SUNPRO_CCis set to0x510.Interactions
Use of
-compat[=4]with-xarch=v9,-xarch=v9a, or-xarch=v9bis not supported.See also
3.2.8
+dDoes not expand C++ inline functions.
Interactions
This option is automatically turned on when you specify
-g, the debugging option.The
-g0debugging option does not turn on+d.See also
3.2.9
-Dname[=def]Defines the macro symbol name to the preprocessor.
Using this option is equivalent to including a
#definedirective at the beginning of the source. You can use multiple-Doptions.Values
The following tables show the predefined macros. You can use these values in such preprocessor conditionals as
#ifdef.
TABLE 3-18 SPARC and IA Predefined Symbols __ARRAYNEW__ARRAYNEWis defined if the "array" forms of operatorsnewanddeleteare enabled. See-features=[no%]arraynewfor more information._BOOL_BOOL is defined if type boolis enabled. See-features=[no%]boolfor more information.__BUILTIN_VA_ARG_INCRFor the __ builtin_alloca, __builtin_va_alist,and__builtin_va_arg_incrkeywords invarargs.h, stdarg.h, andsys/varargs.h.__cplusplus__DATE____FILE____ LINE____STDC____ sunsunSee Interactions. __SUNPRO_CC=0x510The value of __SUNPRO_CCindicates the release number of the compiler__SUNPRO_CC_COMPAT=(4|5)See Section 3.2.7 -compat[=(4|5)] __SVR4__TIME____'uname -s'_'uname -r'Where uname -s is the output ofuname -sand uname -r is the output ofuname -rwith the invalid characters, such as periods (.), replaced by underscores, as in-D__SunOS_5_7and-D__SunOS_5_8.__unixunixSee Interactions. 
TABLE 3-19 UNIX Predefined Symbols _WCHAR_T
TABLE 3-20 SPARC Predefined Symbols __sparc32-bit compilation modes only sparcSee Interactions. 
TABLE 3-21 SPARC v9Predefined Symbols__sparcv964-bit compilation modes only 
TABLE 3-22 IA Predefined Symbols __i386i386See Interactions. 
Defaults
If you do not use =def, name is defined as 1.
Interactions
If
+pis used,sun,unix,sparc, andi386are not defined.See also
3.2.10
-d(y|n)Allows or disallows dynamic libraries for the entire executable.
This option can appear only once on the command line.
Values
-dySpecifies dynamic linking in the link editor. -dnSpecifies static linking in the link editor. 
Defaults
If no
-doption is specified,-dyis assumed.See also
ld(1), Linker and Libraries Guide3.2.11
-dalignSPARC: Generates
double-word loadandstoreinstructions whenever possible for improved performance.This option assumes that all
doubletype data aredouble-wordaligned.Warnings
If you compile one program unit with
-dalign, compile all units of a program with-dalign, or you might get unexpected results.3.2.12
-dryrunShows commands built by driver, but does not compile.
This option directs the driver
CCto show, but not execute, the subcommands constructed by the compilation driver.3.2.13
-ERuns the preprocessor on source files; does not compile.
Directs the
CCdriver to run only the preprocessor on C++ source files, and to send the result tostdout(standard output). No compilation is done; no.ofiles are generated.This option causes preprocessor-type line number information to be included in the output.
Examples
This option is useful for determining the changes made by the preprocessor. For example, the following program,
.foo.cc, generates the output shown in CODE EXAMPLE 3-2
CODE EXAMPLE 3-1 foo.ccint main () {int x;x=power(2, 10);}
CODE EXAMPLE 3-2 Output of foo.ccUsing-EOptionCC -E foo.cc#4 "foo.cc"template < > int power ( int , int ) ;int main ( ) {int x ;x = power ( 2 , 10 ) ;}Warnings
Output from this option is not supported as input to the C++ compiler when templates are used.
See also
3.2.14
+e(0|1)Controls virtual table generation in compatibility mode (
-compat[=4]). Invalid and ignored when in standard mode (the default mode).Values
The
+eoption can have the following values.
0Suppresses the generation of virtual tables and creates external references to those that are needed. 1Creates virtual tables for all defined classes with virtual functions. 
Interactions
When you compile with this option, also use the
-features=no%exceptoption. Otherwise, the compiler generates virtual tables for internal types used in exception handling.See also
3.2.15
-fastOptimizes for speed of execution using a selection of options.
This option is a macro that selects a combination of compilation options for optimum execution speed on the machine upon which the code is compiled.
Expansions
This option provides near maximum performance for many applications by expanding to the following compilation options.
TABLE 3-23 -fastExpansion-dalignX - -fnsX - -fsimple=2X - -ftrap=%noneX X -nofstore- X -xlibmilX X -xlibmoptX X -xO5X X -xtarget=nativeX X 
Interactions
The
-fastmacro expands into compilation options that may affect other specified options. For example, in the following command, the expansion of the-fastmacro includes-xtarget=nativewhich reverts-xarchto one of the 32-bit architecture options.Incorrect:
CC -xarch=v9 -fast test.ccCorrect:
CC -fast -xarch=v9 test.ccSee the description for each option to determine possible interactions.
The code generation option, optimization level, and use of inline template files can be overridden by subsequent options (see examples). The optimization level that you specify overrides a previously set optimization level.
The
-fastoption includes-fns-ftrap=%none; that is, this option turns off all trapping.Examples
The following compiler command results in an optimization level of
-xO3.
CC -fast -xO3The following compiler command results in an optimization level of
-xO5.
CC -xO3 -fastWarnings
Code that is compiled with the
-fastoption is not portable. For example, using the following command on an UltraSPARC-III system generates a binary that will not execute on an UltraSPARC-II system.
CC -fast test.ccDo not use this option for programs that depend on IEEE standard floating-point arithmetic; different numerical results, premature program termination, or unexpected SIGFPE signals can occur.
In previous SPARC releases, the
-fastmacro expanded to-fsimple=1. Now it expands to-fsimple=2.In previous releases, the
-fastmacro expanded to-xO4. Now it expands to-xO5.
Note  In previous SPARC releases, the-fastmacro option included-fnonstd;now it does not. Nonstandard floating-point mode is not initialized by-fast. See the Numerical Computation Guide,ieee_sun(3M).
See also
-dalign,-fns,-fsimple,-ftrap=%none,-libmil,-nofstore,-xO5,-xlibmopt,-xtarget=native3.2.16
-features=a[,...a]Enables/disables various C++ language features named in a comma-separated list.
Values
In both compatibility mode (
-compat[=4]) and standard mode (the default mode), a can have the following values.
In standard mode (the default mode), a can have the following additional values.
In compatibility mode (
-compat[=4]), a can have the following additional values.
Note  The[no%]castopsetting is allowed for compatibility with makefiles written for the C++ 4.2 compiler, but has no affect on the 5.0 and Sun WorkShop 6 C++ compilers. The new style casts (const_cast,dynamic_cast,reinterpret_cast, andstatic_cast) are always recognized and cannot be disabled.
Defaults
If
-featuresis not specified, the following is assumed:
- Compatibility mode (
-compat[=4])
-features=%none,anachronisms,except- Standard mode (the default mode)
-features=%all,no%iddollarSee also
3.2.17
-flags3.2.18
-fnonstdIA: Causes nonstandard initialization of floating-point hardware.
In addition, the
-fnonstdoption causes hardware traps to be enabled for floating-point overflow, division by zero, and invalid operations exceptions. These results are converted into SIGFPE signals; if the program has no SIGFPE handler, it terminates with a memory dump (unless you limit the core dump size to 0).Defaults
If
-fnonstdis not specified, IEEE 754 floating-point arithmetic exceptions do not abort the program, and underflows are gradual.See also
-fns,-ftrap=common, Numerical Computation Guide.3.2.19
-fns[=(yes|no)]SPARC: Enables/disables the SPARC nonstandard floating-point mode.
-fns=yes(or-fns) causes the nonstandard floating point mode to be enabled when a program begins execution.This option provides a way of toggling the use of nonstandard or standard floating-point mode following some other macro option that includes
-fns, such as-fast. (See "Examples.")On some SPARC devices, the nonstandard floating-point mode disables "gradual underflow," causing tiny results to be flushed to zero rather than to produce subnormal numbers. It also causes subnormal operands to be silently replaced by zero.
On those SPARC devices that do not support gradual underflow and subnormal numbers in hardware,
-fns=yes(or-fns) can significantly improve the performance of some programs.Values
The
-fnsoption can have the following values.
yesSelects nonstandard floating-point mode noSelects standard floating-point mode 
Defaults
If
-fnsis not specified, the nonstandard floating point mode is not enabled automatically. Standard IEEE 754 floating-point computation takes place--that is, underflows are gradual.If only
-fnsis specified,-fns=yesis assumed.Examples
In the following example,
-fastexpands to several options, one of which is-fns=yeswhich selects nonstandard floating-point mode. The subsequent-fns=nooption overrides the initial setting and selects floating-point mode.
CC foo.cc -fast -fns=noWarnings
When nonstandard mode is enabled, floating-point arithmetic can produce results that do not conform to the requirements of the IEEE 754 standard.
If you compile one routine with the
-fnsoption, then compile all routines of the program with the-fnsoption; otherwise, you might get unexpected results.This option is effective only on SPARC devices, and only if used when compiling the main program. On IA devices, the option is ignored.
Use of the
-fns=yes(or-fns) option might generate the following message if your program experiences a floating-point error normally managed by the IEEE floating-point trap handlers:See also
Numerical Computation Guide,
ieee_sun(3M)3.2.20
-fprecision=pIA: Sets the non-default floating-point precision mode.
The
-fprecisionoption sets the rounding precision mode bits in the Floating Point Control Word. These bits control the precision to which the results of basic arithmetic operations (add, subtract, multiply, divide, and square root) are rounded.Values
p must be one of the following values.
singleRounds to an IEEE single-precision value. doubleRounds to an IEEE double-precision value. extendedRounds to the maximum precision available. 
If p is
singleordouble, this option causes the rounding precision mode to be set tosingleordoubleprecision, respectively, when a program begins execution. If p isextendedor the-fprecisionoption is not used, the rounding precision mode remains at theextendedprecision.The
singleprecision rounding mode causes results to be rounded to 24 significant bits, anddoubleprecision rounding mode causes results to be rounded to 53 significant bits. In the defaultextendedprecision mode, results are rounded to 64 significant bits. This mode controls only the precision to which results in registers are rounded, and it does not affect the range. All results in register are rounded using the full range of the extended double format. Results that are stored in memory are rounded to both the range and precision of the destination format, however.The nominal precision of the
floattype issingle. The nominal precision of thelong doubletype isextended.Defaults
When the
-fprecisionoption is not specified, the rounding precision mode defaults toextended.Warnings
This option is effective only on IA devices and only if used when compiling the main program. On SPARC devices, this option is ignored.
3.2.21
-fround=rSets the IEEE rounding mode in effect at startup.
This option sets the IEEE 754 rounding mode that:
- Can be used by the compiler in evaluating constant expressions
- Is established at runtime during the program initialization
The meanings are the same as those for the
ieee_flagssubroutine, which can be used to change the mode at runtime.Values
r must be one of the following values.
nearestRounds towards the nearest number and breaks ties to even numbers. tozeroRounds to zero. negativeRounds to negative infinity. positiveRounds to positive infinity. 
Defaults
When the
-froundoption is not specified, the rounding mode defaults to-fround=nearest.Warnings
If you compile one routine with
-fround=r, compile all routines of the program with the same-fround=r option; otherwise, you might get unexpected results.This option is effective only if used when compiling the main program.
3.2.22
-fsimple[=n]Selects floating-point optimization preferences.
This option allows the optimizer to make simplifying assumptions concerning floating-point arithmetic.
Values
If n is present, it must be 0, 1, or 2.
Defaults
If
-fsimpleis not designated, the compiler uses-fsimple=0.If
-fsimpleis designated but no value is given for n, the compiler uses-fsimple=1.Interactions
Warnings
This option can break IEEE 754 conformance.
See also
3.2.23
-fstoreIA: This option causes the compiler to convert the value of a floating-point expression or function to the type on the left side of an assignment rather than leave the value in a register when the following is true:
- The expression or function is assigned to a variable.
- The expression is cast to a shorter floating-point type.
To turn off this option, use the
-nofstoreoption.Warnings
Due to roundoffs and truncation, the results can be different from those that are generated from the register values.
See also
3.2.24 -
ftrap=t[,...t]Sets the IEEE trapping mode in effect at startup.
This option sets the IEEE 754 trapping modes that are established at program initialization, but does not install a
SIGFPEhandler. You can useieee_handlerto simultaneously enable traps and install a SIGFPE handler. When more than one value is used, the list is processed sequentially from left to right.Values
t can be one of the following values.
Note that the
[no%]form of the option is used only to modify the meaning of the%allandcommonvalues, and must be used with one of these values, as shown in the example. The[no%]form of the option by itself does not explicitly cause a particular trap to be disabled.If you want to enable the IEEE traps,
-ftrap=commonis the recommended setting.Defaults
If
-ftrapis not specified, the-ftrap=%nonevalue is assumed.(Traps are not enabled automatically.)Examples
When one or more terms are given, the list is processed sequentially from left to right, thus
-ftrap=%all,no%inexactmeans to set all traps except inexact.Interactions
The mode can be changed at runtime with
ieee_handler(3M).Warnings
If you compile one routine with
-ftrap=t, compile all routines of the program with the same-ftrap=t option; otherwise, you might get unexpected results.Use the
-ftrap=inexacttrap with caution. Use of-ftrap=inexactresults in the trap being issued whenever a floating-point value cannot be represented exactly. For example, the following statement generates this condition:
x = 1.0 / 3.0;This option is effective only if used when compiling the main program. Be cautious when using this option. If you wish to enable the IEEE traps, use
-ftrap=common.See also
3.2.25
-GBuild a dynamic shared library instead of an executable file.
All source files specified in the command line are compiled with
-Kpicby default.When building a shared library that uses templates, it is necessary in most cases to include in the shared library those template functions that are instantiated in the template data base. Using this option automatically adds those templates to the shared library as needed.
Interactions
The following options are passed to
ldif-c(the compile-only option) is not specified:
-dy
-G
-RWarnings
Do not use
ld-Gto build shared libraries; useCC-G. TheCCdriver automatically passes several options toldthat are needed for C++.See also
-dy, -Kpic, -xcode=pic13, -xildoff, -ztext, ld(1) man page, C++ Library Reference.3.2.26
-gInstructs both the compiler and the linker to prepare the file or program for debugging.
- Producing detailed information, known as stabs, in the symbol table of the object files and the executable
- Producing some "helper functions," which the debugger can call to implement some of its features
- Disabling the inline generation of functions
- Disabling certain levels of optimization
Interactions
If you use this option with
-xOlevel, you will get limited debugging information. For more information, see Section 3.2.117 -xOlevel.If you use this option and the optimization level is
-xO3or lower, the compiler provides best-effort symbolic information with almost full optimization. Tail-call optimization and back-end inlining are disabled.If you use this option and the optimization level is
-xO4or higher, the compiler provides best-effort symbolic information with full optimization.When you specify this option, the
+doption is specified automatically.This option makes
-xildonthe default incremental linker option in order to speed up the compile-edit-debug cycle.This option invokes
ildin place ofldunless any of the following are true:
- The
-Goption is present- The
-xildoffoption is present- Any source files are named on the command line
See also
+d, -g0, -xildoff, -xildon, -xs, ld(1) man page, Debugging a Program Withdbx(for details about stabs)3.2.27
-g0Compiles and links for debugging, but does not disable inlining.
This option is the same as
-g, except that+dis disabled.See also
+d, -g, -xildon,Debugging a Program Withdbx3.2.28
-HPrints path names of included files.
On the standard error output
(stderr), this option prints, one per line, the path name of each#includefile contained in the current compilation.3.2.29
-help3.2.30
-hnameAssigns the name name to the generated dynamic shared library. This is a loader option, passed to
ld. In general, the name after-hshould be exactly the same as the one after-o. A space between the-hand name is optional.The compile-time loader assigns the specified name to the shared dynamic library you are creating. It records the name in the library file as the intrinsic name of the library. If there is no
-hname option, then no intrinsic name is recorded in the library file.Every executable file has a list of shared library files that are needed. When the runtime linker links the library into an executable file, the linker copies the intrinsic name from the library into that list of needed shared library files. If there is no intrinsic name of a shared library, then the linker copies the path of the shared library file instead.
Examples
CC -G -o libx.so.1 -h libx.so.1 a.o b.o c.o3.2.31
-iTells the linker,
ld,to ignore anyLD_LIBRARY_PATHsetting.3.2.32
-IpathnameAdd pathname to the
#includefile search path.This option adds pathname to the list of directories that are searched for
#includefiles with relative file names (those that do not begin with a slash).The preprocessor searches for
#includefiles in the following order:
- For include statements of the form
#include "foo.h"(where quotation marks are used), the directory containing the source file is searched- For include statements of the form
#include <foo.h>(where angle brackets are used), the directory containing the source file is not searched- The directories named with
-Ioptions, if any- The directories for compiler-provided C++ header files, ANSI C header files, and special-purpose files
- The
/usr/includedirectory
Note  The standard headers are treated differently. For more information, see Section 5.7.4 Standard Header Implementation.
Interactions
If
-ptipath is not used, the compiler looks for template files in-Ipathname.Use
-Ipathname instead of-ptipath.3.2.33
-instances=aControls the placement and linkage of template instances.
Values
a must be one of the following values.
Defaults
If
-instancesis not specified,-instances=externis assumed.See also
3.2.34
-keeptmpRetains temporary files created during compilation.
Along with
-verbose=diags, this option is useful for debugging.See also
3.2.35
-KPIC3.2.36
-KpicIA: Compiles with position-independent code.
Use this option to compile source files when building a shared library. 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 pc-relative addressing mode through a procedure linkage table.
3.2.37
-LdirAdds dir to list of directories to search for libraries.
This option is passed to
ld. The directory dir is searched before compiler-provided directories.3.2.38
-llibAdds library
liblib.aorliblib.soto the linker's list of search libraries.This option is passed to
ld.Normal libraries have names such asliblib.aorliblib.so, where theliband.aor.soparts are required. You should specify the lib part with this option. Put as many libraries as you want on a single command line; they are searched in the order specified with-Ldir.Use this option after your object file name.
Interactions
It is always safer to put
-lx after the list of sources and objects to insure that libraries are searched in the correct order.Warnings
To ensure proper library linking order, you must use
-mt, rather than-lthread, to link withlibthread.If you are using POSIX threads, you must link with the
-mtand-lpthreadoptions. The-mtoption is necessary becauselibCrun(standard mode) andlibC(compatibility mode) needlibthreadfor a multithreaded application.See also
-Ldir,-mt,C++ Library Reference, and Tools.h++ Class Library Reference3.2.39
-libmieee3.2.40
-libmil3.2.41
-library=l[,...l]Incorporates specified CC-provided libraries into compilation and linking.
Values
For compatibility mode (
-compat[=4]), l must be one of the following values.
For standard mode (the default mode), l must be one of the following:
Defaults
- Compatibility mode (
-compat[=4])
- If
-libraryis not specified,-library=%none,libCis assumed.- The
libClibrary always is included unless it is specifically excluded using-library=%noneor-library=no%libC.- Standard mode (the default mode)
Examples
To link in standard mode without any C++ libraries (except
libCrun), use:
CC -library=%noneTo include the Rogue Wave
tools.h++version 7 library and theiostreamlibrary in standard mode:
CC -library=rwtools7,iostreamInteractions
If a library is specified with
-library, the proper-Ipaths are set during compilation. The proper-L,-Y P,-Rpaths and-loptions are set during linking.Use of the
-libraryoption ensures that the-loptions for the specified libraries are emitted in the right order. For example, the-loptions are passed toldin the order-lrwtool -liostreamfor both-library=rwtools7,iostreamand-library=iostream,rwtools7.The specified libraries are linked before the system support libraries are linked.
Only one Rogue Wave tools library can be used at a time.
The Rogue Wave
Tools.h++ version 7 library is built with classic iostreams. Therefore, when you include the Rogue Wave tools library in standard mode, you must also includelibiostream. For more information, see the C++ Migration Guide.If you include both
libCstdandlibiostream, you must be careful to not use the old and new forms of iostreams (for example,coutandstd::cout) within a program to access the same file. Mixing standard iostreams and classic iostreams in the same program is likely to cause problems if the same file is accessed from both classic and standard iostream code.Programs linking neither
libCnorlibCrunmight not use all features of the C++ language.If
-xnolibis specified,-libraryis ignored.Warnings
The set of libraries is not stable and might change from release to release.
See also
-I,-l,-R,-staticlib,-xnolib, Section 2.5.3.3 "Using make With Standard Library Header Files"," C++ Library Reference, Tools.h++ User's Guide, Tools.h++ Class Library Reference, Standard C++ Class Library Reference.For information on using the
-library=no%cstdoption to enable use of your own C++ standard library, see Section 5.7 Replacing the C++ Standard Library.3.2.42
-migrationExplains where to get information about migrating source code that was built for earlier versions of the compiler.
3.2.43
-misalignSPARC: Permits misaligned data, which would otherwise generate an error, in memory. This is shown in the following code:
int f(int * ar) {return *(int *) (b +2) + *ar;}This option informs the compiler that some data in your program is not properly aligned. Thus, very conservative loads and stores must be used for any data that might be misaligned, that is, one byte at a time. Using this option may cause significant degradation in runtime performance. The amount of degradation is application dependent.
Interactions
When using
#pragmapackon a SPARC platform to pack denser than the type's default alignment, the-misalignoption must be specified for both the compilation and the linking of the application.Misaligned data is handled by a trap mechanism that is provided by
ldat runtime. If an optimization flag (-x0[1|2|3|4|5]or an equivalent flag) is used with the-misalignoption, the additional instructions required for alignment of misaligned data are inserted into the resulting object file and will not generate runtime misalignment traps.Warnings
If possible, do not link aligned and misaligned parts of the program.
If compilation and linking are performed in separate steps, the
-misalignoption must appear in both the compile and link commands.3.2.44
-mtCompiles and links for multithreaded code.
- Passes
-D_REENTRANTto the preprocessor- Passes
-lthreadin the correct order to ld- Ensures that, for standard mode (the default mode),
libthreadis linked beforelibCrun- Ensures that, for compatibility mode (
-compat),libthreadis linked beforelibCThe
-mtoption is required if the application or libraries are multithreaded.Warnings
To ensure proper library linking order, you must use this option, rather than
-lthread, to link withlibthread.If you are using POSIX threads, you must link with the
-mtand-lpthreadoptions. The-mtoption is necessary becauselibCrun(standard mode) andlibC(compatibility mode) needlibthreadfor a multithreaded application.If you compile and link in separate steps and you compile with
-mt, be sure to link with-mt, as shown in the following example, or you might get unexpected results.
CC -c -mt myprog.ccexample%CC -mt myprog.oSee also
-xnolib, C++ Programming Guide, Multithreaded Programming Guide, Linker and Libraries Guide, C++ Library Reference3.2.45
-native3.2.46
-noex3.2.47
-nofstoreThis option does not force the value of a floating-point expression or function to the type on the left side of an assignment, but leaves the value in a register when either of the following are true:
- The expression or function is assigned to a variable
or- The expression or function is cast to a shorter floating-point type
See also
3.2.48
-nolib3.2.49
-nolibmil3.2.50
-noqueueIf no license is available, this option returns without queuing your request and without compiling. A nonzero status is returned for testing makefiles.
3.2.51
-norunpathDoes not build a runtime search path for shared libraries into the executable.
If an executable file uses shared libraries, then the compiler normally builds in a path that points the runtime linker to those shared libraries. To do so, the compiler passes the
-Roption told. The path depends on the directory where you have installed the compiler.This option is helpful if you have installed the compiler in some nonstandard location, and you ship an executable file to your customers. Your customers do not have to work with that nonstandard location.
Interactions
If you use any shared libraries under the compiler installed area (the default location is
/opt/SUNWspro/lib) and you also use-norunpath, then you should either use the-Roption at link time or set the environment variableLD_LIBRARY_PATHat runtime to specify the location of the shared libraries. Doing so allows the runtime linker to find the shared libraries.3.2.52
-O3.2.53
-Olevel3.2.54
-ofilenameSets the name of the output file or the executable file to filename.
Interactions
When the compiler must store template instances, it stores them in the template repository in the output file's directory. For example, the following command writes the object file to
./sub/a.oand writes template instances into the repository contained within./sub/SunWS_cache.
CC -o sub/a.o a.ccThe compiler reads from the template repositories corresponding to the object files that it reads. For example, the following command reads from
./sub1/SunWS_Cacheand./sub2/SunWS_cache, and, if necessary, writes to./SunWS_cache.
CC sub1/a.o sub2/b.oFor more information, see Section 4.4 "The Template Repository"."
Warnings
The filename must have the appropriate suffix for the type of file to be produced by the compilation. It cannot be the same file as the source file, since the
CCdriver does not overwrite the source file.3.2.55
+pIgnore non-standard preprocessor asserts.
Defaults
If
+pis not present, the compiler recognizes non-standard preprocessor asserts.Interactions
If
+pis used, the following macros are not defined:
sun
unix
sparc
i3863.2.56
-POnly preprocesses source; does not compile. (Outputs a file with a
.isuffix)This option does not include preprocessor-type line number information in the output.
See also
3.2.57
-p
Prepares object code to collect data for profiling withprof.This option invokes a runtime recording mechanism that produces a
mon.outfile at normal termination.See also
-xpg,-xprofile,analyzer(1) man page, Analyzing Program Performance With Sun WorkShop.3.2.58
-pentiumIA: Replace with
-xtarget=pentium.3.2.59
-pg3.2.60
-PIC3.2.61
-pic3.2.62
-pta3.2.63
-ptipathSpecifies an additional search directory for template source.
This option is an alternative to the normal search path set by
-Ipathname. If the-ptipath option is used, the compiler looks for template definition files on this path and ignores the-Ipathname option.Using the
-Ipathname option instead of-ptipath produces less confusion.See also
3.2.64
-pto3.2.65
-ptrThis option is obsolete and is ignored by the compiler.
Warnings
Even though the
-ptroption is ignored, you should remove-ptrfrom all compilation commands because, in a later release, it may be reused with a different behavior.See also
For information about repository directories, see Section 4.4 "The Template Repository"."
3.2.66
-ptv3.2.67
-Qoptionphase option[,...option]
Passes option to the compilation phase.To pass multiple options, specify them in order as a comma-separated list.
Values
phase must have one of the following values.
ccfeccfeiroptcg386cgcodegenCClinkCClinkldld
Examples
In the following command line, when
ldis invoked by theCCdriver,-Qoptionpasses the-iand-moptions told:
CC -Qoption ld -i,-m test.cWarnings
Be careful to avoid unintended effects. For example,
is interpreted as
The correct usage is
3.2.68
-qoptionphase option3.2.69
-qp3.2.70
-QproducesourcetypeCauses the
CCdriver to produce output of the type sourcetype.Sourcetype suffixes are defined below.
.iPreprocessed C++ source from ccfe.oObject file from cg, the code generator.sAssembler source from cg
3.2.71
-qproducesourcetype3.2.72
-Rpathname[:...pathname]Builds dynamic library search paths into the executable file.
You can have more than one pathname, such as
-R/path1:/path2.Defaults
If the
-Roption is not present, the library search path that is recorded in the output object and passed to the runtime linker depends upon the target architecture instruction specified by the-xarchoption (when-xarchis not present,-xarch=genericis assumed).
v9,v9a, orv9binstall_directory /SUNWspro/lib/v9All other values install_directory /SUNWspro/lib
In a default installation, install-directory is
/opt.Interactions
If the
LD_RUN_PATHenvironment variable is defined and the-Roption is specified, then the path from-Ris scanned and the path fromLD_RUN_PATHis ignored.See also
-norunpath,Linker and Libraries Guide3.2.73
-readme3.2.74
-SCompiles and generates only assembly code.
This option causes the
CCdriver to compile the program and output an assembly source file, without assembling the program. The assembly source file is named with a.ssuffix.3.2.75
-sStrips the symbol table from the executable file.
This option removes all symbol information from output executable files. This option is passed to
ld.3.2.76
-sb3.2.77
-sbfast3.2.78
-staticlib=l[,...l]Indicates which C++ libraries specified in the
-libraryoption (including its defaults) are to be linked statically.Values
l must be one of the following values.
Defaults
If
-staticlibis not specified,-staticlib=%noneis assumed.Examples
The following command line links
libCrunstatically becauseCrunis a default value for-library:
CC -staticlib=Crun(correct)However, the following command line does not link
libgcbecauselibgcis not linked unless explicitly specified with the-libraryoption:
CC-staticlib=gc(incorrect)To link
libgcstatically, use the following command:
CC -library=gc -staticlib=gc(correct)With the following command, the
librwtoollibrary is linked dynamically. Becauselibrwtoolis not a default library and is not selected using the-libraryoption,-staticlibhas no effect:
CC -lrwtool -library=iostream \-staticlib=rwtools7(incorrect)This command links the
librwtoollibrary statically:
CC -library=rwtools7,iostream -staticlib=rwtools7(correct)Interactions
The
-staticliboption only works for C++ libraries that are selected explicitly with the-libraryoption or that are selected implicitly by default. In compatibility mode (-compat=[4]),libCis selected by default. In standard mode (the default mode),CstdandCrunare selected by default.When using
-xarch=v9,-xarch=v9a, or-xarch=v9b, some C++ libraries are not available as static libraries.Warnings
The set of allowable values for library is not stable and might change from release to release.
See also
-library, Section 5.5 "Statically Linking Standard Libraries""3.2.79
-temp=dirDefines directory for temporary files.
This option sets the name of the directory for temporary files, generated during the compilation process, to dir.
See also
3.2.80
-template=w[,...w]Enables/disables various template options.
Values
w must be one of the following values.
Defaults
If the
-templateoption is not specified,-template=no%wholeclass,extdefis assumed.3.2.81
-time3.2.82
-UnameDeletes initial definition of the preprocessor symbol name.
This option removes any initial definition of the macro symbol name created by
-Don the command line including those implicitly placed there by theCCdriver. It has no effect on any other predefined macros, nor any macro definitions in source files.You can specify multiple
-Uoptions on the command line.Interactions
All
-Uoptions are processed after any-Doptions that are present.3.2.83
-unroll=n3.2.84
-V3.2.85
-v3.2.86
-vdelxCompatibility mode only (
-compat[=4]):For expressions using
delete[], this option generates a call to the runtime library function_vector_deletex_instead of generating a call to_vector_delete_. The function_vector_delete_takes two arguments: the pointer to be deleted and the size of each array element.The function
_vector_deletex_behaves the same as_vector_delete_except that it takes a third argument: the address of the destructor for the class. This third argument is not used by the function, but is provided to be used by third-party vendors.Default
The compiler generates a call to
_vector_delete_for expressions usingdelete[].Warnings
This is an obsolete option that will be removed in future releases. Don't use this option unless you have bought some software from a third-party vendor and the vendor recommends using this option.
3.2.87
-verbose=v[,...v]Values
v must be one of the following values.
You can specify more than one option, for example,
-verbose=template,diags.Defaults
If
-verboseis not specified,-verbose=%noneis assumed.3.2.88
+wIdentifies code that might have unintended consequences.
This option generates additional warnings about questionable constructs that are:
- Nonportable
- Likely to be mistakes
- Inefficient
Defaults
If
+wis not specified, the compiler warns about constructs that are almost certainly problems.See also
3.2.89
+w2Emits all the warnings emitted by
+wplus warnings about technical violations that are probably harmless, but that might reduce the maximum portability of your program.Warnings
Some Solaris and C++ standard header files result in warnings when compiled with
+w2.See also
3.2.90
-wSuppresses most warning messages.
This option causes the compiler not to print warning messages. However, some warnings, particularly warnings regarding serious anachronisms, cannot be suppressed.
See also
3.2.91
-xaIf set at compile time, the
TCOVDIRenvironment variable specifies the directory where the coverage (.d)files are located. If this variable is not set, then the coverage (.d)files remain in the same directory as thesourcefiles.Use this option only for backward compatibility with old coverage files.
Interactions
The -
xprofile=tcovoption and the-xaoption are compatible in a single executable. That is, you can link a program that contains some files that have been compiled with-xprofile=tcov, and others that have been compiled with-xa. You cannot compile a single file with both options.The
-xaoption is incompatible with-g.Warnings
If you compile and link in separate steps and you compile with
-xa, be sure to link with-xa, or you might get unexpected results.See also
-xprofile=tcov,tcov(1) man page, Analyzing Program Performance With Sun WorkShop3.2.92
-xarWhen building a C++ archive that uses templates, it is necessary in most cases to include in the archive those template functions that are instantiated in the template database. Using this option automatically adds those templates to the archive as needed.
Examples
The following command line archives the template functions contained in the library and object files.
CC -xar -o libmain.a a.o b.o c.oWarnings
Do not add
.ofiles from the template database on the command line.Do not use the
arcommand directly for building archives. UseCC-xarto ensure that template instantiations are automatically included in the archive.See also
3.2.93
-xarch=isaSpecifies the target instruction set architecture (ISA).
This option limits the code generated by the compiler to the instructions of the specified instruction set architecture by allowing only the specified set of instructions. This option does not guarantee use of any target-specific instructions.
Values
TABLE 3-29 gives the details for each of the
-xarchkeywords on SPARC platforms.
- SPARC instruction set architectures V7, V8, and V8a are all binary compatible.
- Object binary files (
.o) compiled withv8plusandv8plusacan be linked and can execute together, but only on a SPARC V8plusa compatible platform.- Object binary files (
.o) compiled withv8plus,v8plusa, andv8plusbcan be linked and can execute together, but only on a SPARC V8plusb compatible platform.
-xarchvaluesv9,v9a, andv9bare only available on UltraSPARC 64-bit Solaris environments.- Object binary files (
.o) compiled withv9andv9acan be linked and can execute together, but will run only on a SPARC V9a compatible platform.- Object binary files (
.o) compiled withv9,v9a, andv9bcan be linked and can execute together, but will run only on a SPARC V9b compatible platform.For any particular choice, the generated executable may run much more slowly on earlier architectures. Also, although quad-precision (
REAL*16andlongdouble) floating-point instructions are available in many of these instruction set architectures, the compiler does not use these instructions in the code it generates.TABLE 3-30 gives the details for each of the
-xarchkeywords on IA platforms.
Defaults
If
-xarch=isa is not specified,-xarch=genericis assumed.Interactions
Although this option can be used alone, it is part of the expansion of the
-xtargetoption and may be used to override the-xarchvalue that is set by a specific-xtargetoption. For example,-xtarget=ultra2expands to-xarch=v8-xchip=ultra2-xcache=15/32/1:512/64/1. In the following command-xarch=v8plusboverrides the-xarch=v8that is set by the expansion of-xtarget=ultra2.
CC -xtarget=ultra2 -xarch=v8plusb foo.ccUse of
-compat[=4]with-xarch=v9,-xarch=v9a, or-xarch=v9bis not supported.Warnings
If this option is used with optimization, the appropriate choice can provide good performance of the executable on the specified architecture. An inappropriate choice, however, might result in serious degradation of performance or in a binary program that is not executable on the intended target platform.
3.2.94
-xcache=cSPARC: Defines cache properties for use by the optimizer.
This option specifies the cache properties that the optimizer can use. It does not guarantee that any particular cache property is used.
Note  Although this option can be used alone, it is part of the expansion of the-xtargetoption; its primary use is to override a value supplied by the-xtargetoption.
Values
c must be one of the following values.
The definitions of the cache properties, si/li/ai, are as follows:
si
The size of the data cache at level i, in kilobytes li
The line size of the data cache at level i, in bytes ai
The associativity of the data cache at level i 
For example, i=1 designates level 1 cache properties, s1
/l1/a1.Defaults
If
-xcacheis not specified, the default-xcache=genericis assumed. This value directs the compiler to use cache properties for good performance on most SPARC processors, without major performance degradation on any of them.Examples
-xcache=16/32/4:1024/32/1specifies the following:
16 Kbytes 1024 Kbytes 32 bytes line size 32 bytes line size 4-way associativity Direct mapping associativity 
See also
3.2.95
-xcg89Warnings
If you compile and link in separate steps and you compile with
-xcg89, be sure to link with the same option, or you might get unexpected results.3.2.96
-xcg92Warnings
If you compile and link in separate steps and you compile with
-xcg92, be sure to link with the same option, or you might get unexpected results.3.2.97
-xchip=cSpecifies target processor for use by the optimizer.
The
-xchipoption specifies timing properties by specifying the target processor. This option affects:
- The ordering of instructions--that is, scheduling
- The way the compiler uses branches
- The instructions to use in cases where semantically equivalent alternatives are available
Note  Although this option can be used alone, it is part of the expansion of the-xtargetoption; its primary use is to override a value supplied by the-xtargetoption.
Values
c must be one of the following values.
Defaults
On most SPARC processors,
genericis the default value that directs the compiler to use the best timing properties for good performance without major performance degradation on any of the processors.3.2.98
-xcode=aSPARC: Specifies the code address space.
Values
a must be one of the following values.
Defaults
For SPARC V8 and V7 processors, the default is
-xcode=abs32.For SPARC and UltraSPARC processors, when you use
-xarch=(v9|v9a|v9b), the default is-xcode=abs64.3.2.99
-xcrossfile[=n]SPARC: Enables optimization and inlining across source files.
Values
n must be one of the following values.
0Do not perform cross-file optimizations or cross-file inlining. 1Perform optimization and inlining across source files. 
Normally the scope of the compiler's analysis is limited to each separate file on the command line. For example, when the
-xO4option is passed, automatic inlining is limited to subprograms defined and referenced within the same source file.With
-xcrossfileor-xcrossfile=1, the compiler analyzes all the files named on the command line as if they had been concatenated into a single source file.Defaults
If
-xcrossfileis not specified,-xcrossfile=0is assumed and no cross-file optimizations or inlining are performed.
-xcrossfileis the same as-xcrossfile=1.Interactions
The
-xcrossfileoption is effective only when it is used with-xO4or-xO5.Warnings
The files produced from this compilation are interdependent due to possible inlining, and must be used as a unit when they are linked into a program. If any one routine is changed and the files recompiled, they must all be recompiled. As a result, using this option affects the construction of makefiles.
3.2.100 -
xFIf you compile with the
-xFoption and then run the Analyzer, you can generate a map file that shows an optimized order for the functions. A subsequent link to build the executable file can be directed to use that map by using the linker-Mmapfile option. It places each function from the executable file into a separate section.Reordering the subprograms in memory is useful only when the application text page fault time is consuming a large percentage of the application time. Otherwise, reordering might not improve the overall performance of the application.
Interactions
The
-xFoption is only supported with-features=no%except(-noex).See also
analyzer(1),debugger(1),ld(1) man pages3.2.101 -
xhelp=flagsDisplays a brief description of each compiler option.
3.2.102 -
xhelp=readmeDisplays contents of the online
READMEfile.The
READMEfile is paged by the command specified in the environment variable,PAGER. IfPAGERis not set, the default paging command ismore.3.2.103 -
xildoffTurns off the incremental linker.
Defaults
This option is assumed if you do not use the
-goption. It is also assumed if you do use the-Goption, or name any source file on the command line. Override this default by using the-xildonoption.See also
-xildon,ild(1) man page,ld(1) man page, Incremental Link Editor Guide3.2.104 -
xildonTurns on the incremental linker.
This option is assumed if you use
-gand not-G, and you do not name any source file on the command line. Override this default by using the-xildoffoption.See also
-xildoff,ild(1) man page,ld(1) man page, Incremental Link Editor Guide3.2.105 -
xlibmieeeCauses
libmto return IEEE 754 values for math routines in exceptional cases.The default behavior of
libmis XPG-compliant.See also
3.2.106 -
xlibmilInlines selected
libmlibrary routines for optimization.
Note  This option does not affect C++ inline functions.
There are inline templates for some of the
libmlibrary routines. This option selects those inline templates that produce the fastest executables for the floating-point option and platform currently being used.Interactions
This option is implied by the
-fastoption.See also
-fast, Numerical Computation Guide3.2.107
-xlibmoptUses library of optimized math routines.
This option uses a math routine library optimized for performance and usually generates faster code. The results might be slightly different from those produced by the normal math library; if so, they usually differ in the last bit.
The order on the command line for this library option is not significant.
Interactions
This option is implied by the
-fastoption.See also
3.2.108
-xlic_lib=sunperfSPARC: Links in the Sun Performance LibraryTM.
This option, like
-l, should appear at the end of the command line, after source or object files.See also
3.2.109
-xlicinfoShows license server information.
This option returns the license-server name and the user ID for each user who has a license checked out. When you use this option, the compiler is not invoked, and a license is not checked out.
If a conflicting option is used, the latest one on the command line takes precedence, and a warning is issued.
Examples
Do not compile; report license information:
CC -c -xlicinfo any.ccCompile; do not report license information:
CC -xlicinfo -c any.cc3.2.110
-Xm3.2.111
-xMOutputs makefile dependency information.
Examples
The program
foo.cccontains the following statement:
When
foo.cis compiled with the-xM, the output includes the following line:
See also
make(1S) (for details about makefiles and dependencies)3.2.112
-xM1Generates dependency information, but excludes
/usr/include.This is the same as
-xM, except that this option does not report dependencies for the/usr/includeheader files.3.2.113
-xMergeSPARC: Merges the data segment with the text segment.
The data in the object file is read-only and is shared between processes, unless you link with
ld-N.See also
3.2.114
-xnolibDisables linking with default system libraries.
Normally (without this option), the C++ compiler links with several system libraries to support C++ programs. With this option, the
-llib options to link the default system support libraries are not passed told.Normally, the compiler links with the system support libraries in the following order:
- Standard mode (default mode):
-lCstd -lCrun -lm -lw -lcx -lc- Compatibility mode (-
compat):
-lC -lm -lw -lcx -lcThe order of the
-loptions is significant. The-lm,-lw, and-lcxoptions must appear before-lc.
Note  If the-mtcompiler option is specified, the compiler normally links with-lthreadjust before it links with-lm.
To determine which system support libraries will be linked by default, compile with the
-dryrunoption. For example, the output from the following command:
CC foo.cc -xarch=v9 -dryrunIncludes the following in the output:
-lCstd -lCrun -lm -lw -lcNote that when
-xarch=v9is specified,-lcxis not linked.Examples
For minimal compilation to meet the C application binary interface (that is, a C++ program with only C support required), use:
CC -xnolib test.cc -lcTo link
libmstatically into a single-threaded application with the generic architecure instruction set, use:
- Standard mode:
CC -xnolib test.cc -lCstd -lCrun -Bstatic -lm \-Bdynamic -lw -lcx -lc- Compatibility mode:
CC -compat -xnolib test.cc -lC -Bstatic -lm \-Bdynamic -lw -lcx -lcInteractions
Some static system libraries, such as
libm.aandlibc.a, are not available when linking with-xarch=v9,-xarch=v9aor-xarch=v9b.If you specify
-xnolib, you must manually link all required system support libraries in the given order. You must link the system support libraries last.If
-xnolibis specified,-libraryis ignored.Warnings
Many C++ language features require the use of
libC(compatibility mode) orlibCrun(standard mode).This set of system support libraries is not stable and might change from release to release.
In 64-bit compilation modes,
-lcxis not present.See also
3.2.115
-xnolibmilCancels
-xlibmilon the command line.Use this option with
-fastto override linking with the optimized math library.3.2.116
-xnolibmoptDoes not use the math routine library.
Examples
Use this option after the
-fastoption on the command line, as in this example:
CC -fast -xnolibmopt3.2.117
-xOlevelSpecifies optimization level. In general, program execution speed depends on level of optimization. The higher the level of optimization, the faster the speed.
If
-xOlevel is not specified, only a very basic level of optimization (limited to local common subexpression elimination and dead code analysis) is performed. A program's performance might be significantly improved when it is compiled with an optimization level. Use of-xO2(or the equivalent options-Oand-O2) is recommended for most programs.Generally, the higher the level of optimization with which a program is compiled, the better the runtime performance. However, higher optimization levels can result in increased compilation time and larger executable files.
In a few cases,
-xO2might perform better than the others, and-xO3might outperform-xO4. Try compiling with each level to see if you have one of these rare cases.If the optimizer runs out of memory, it tries to recover by retrying the current procedure at a lower level of optimization. The optimizer resumes subsequent procedures at the original level specified in the
-xOlevel option.There are five levels that you can use with
-xO. The following sections describe how they operate on the SPARC platform and the IA platform.Values
-xO1does only the minimum amount of optimization (peephole), which is postpass, assembly-level optimization. Do not use-xO1unless using-xO2or-xO3results in excessive compilation time, or you are running out of swap space.
-xO2does basic local and global optimization, which includes:
- Induction-variable elimination
- Local and global common-subexpression elimination
- Algebraic simplification
- Copy propagation
- Constant propagation
- Loop-invariant optimization
- Register allocation
- Basic block merging
- Tail recursion elimination
- Dead-code elimination
- Tail-call elimination
- Complicated expression expansion
- This level does not optimize references or definitions for external or indirect variables. In general, this level results in minimum code size.
Note  The-Ooptions is equivalent to the-xO2option.
-xO3, in addition to optimizations performed at the-xO2level, also optimizes references and definitions for external variables. This level does not trace the effects of pointer assignments. When compiling either device drivers that are not properly protected byvolatileor programs that modify external variables from within signal handlers, use-xO2. In general,-xO3 results in increased code size. If you are running out of swap space, use-xO2.
-xO4does automatic inlining of functions contained in the same file in addition to performing-xO3optimizations. This automatic inlining usually improves execution speed but sometimes makes it worse. In general, this level results in increased code size.
-xO5generates the highest level of optimization. It is suitable only for the small fraction of a program that uses the largest fraction of computer time. This level uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Optimization at this level is more likely to improve performance if it is done with profile feedback. See Section 3.2.120 "-xprofile=p"."
-xO1preloads arguments from memory and causes cross jumping (tail merging), as well as the single pass of the default optimization.
-xO2schedules both high- and low-level instructions and performs improved spill analysis, loop memory-reference elimination, register lifetime analysis, enhanced register allocation, global common subexpression elimination, as well as the optimization done by level 1.
-xO3performs loop strength reduction and inlining, as well as the optimization done by level 2.
-xO4performs architecture-specific optimization, as well as the optimization done by level 3.
-xO5generates the highest level of optimization. It uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time.Interactions
If you use
-gor-g0and the optimization level is-xO3or lower, the compiler provides best-effort symbolic information with almost full optimization. Tail-call optimization and back-end inlining are disabled.If you use
-gor-g0and the optimization level is-xO4or higher, the compiler provides best-effort symbolic information with full optimization.Debugging with
-gdoes not suppress-xOlevel, but-xOlevel limits-gin certain ways. For example, the-xOlevel options reduce the utility of debugging so that you cannot display variables fromdbx, but you can still use thedbxwherecommand to get a symbolic traceback. For more information, see Debugging a Program Withdbx.The
-xcrossfileoption is effective only if it is used with-xO4or-xO5.Warnings
If you optimize at
-xO3or-xO4with very large procedures (thousands of lines of code in a single procedure), the optimizer might require an unreasonable amount of memory. In such cases, machine performance can be degraded.To prevent this degradation from taking place, use the
limitcommand to limit the amount of virtual memory available to a single process (see thecsh(1) man page). For example, to limit virtual memory to 16 megabytes:
limit datasize 16MThis command causes the optimizer to try to recover if it reaches 16 megabytes of data space.
The limit cannot be greater than the total available swap space of the machine, and should be small enough to permit normal use of the machine while a large compilation is in progress.
The best setting for data size depends on the degree of optimization requested, the amount of real memory, and virtual memory available.
To find the actual swap space, type:
swap -lTo find the actual real memory, type:
dmesg | grep memSee also
-fast,-xcrossfile=n,-xprofile=p,csh(1) man page3.2.118
-xpgThe
-xpgoption compiles self-profiling code to collect data for profiling withgprof. This option invokes a runtime recording mechanism that produces agmon.outfile when the program normally terminates.Warnings
If you compile and link separately, and you compile with
-xpg, be sure to link with-xpg.See also
-xprofile=p,analyzer(1) man page, Analyzing Program Performance With Sun WorkShop.3.2.119
-xprefetch[=a[,a]]SPARC: Enable prefetch instructions on those architectures that support prefetch, such as UltraSPARC II (
-xarch=v8plus,v8plusa,v9plusb,v9,v9a, orv9b)a must be one of the following values.
Defaults
If
-xprefetchis not specified,-xprefetch=no%auto,explicitis assumed.If only
-xprefetchis specified,-xprefetch=auto,explicitis assumed.The default of
no%autois assumed unless explicitly overridden with the use of-xprefetchwithout any arguments or with an argument ofautooryes. For example,-xprefetch=explicitis the same as-xprefetch=explicit,no%auto.The default of
explicitis assumed unless explicitly overridden with an argument ofno%explicitor an argument ofno. For example,-xprefetch=autois the same as-xprefetch=auto,explicit.Interactions
The
sun_prefetch.hheader file provides the macros for specifying explicit prefetch instructions. The prefetches will be approximately at the place in the executable that corresponds to where the macros appear.To use the explicit prefetch instructions, you must be on the correct architecture, include
sun_prefetch.h, and either exclude-xprefetchfrom the compiler command or use-xprefetch=explicitor-xprefetch=yes.If you call the macros and include the
sun_prefetch.h header file, but pass-xprefetch=no%explicitor-xprefetch=no, the explicit prefetches will not appear in your executable.With
-xprefetch,-xprefetch=auto, and-xprefetch=yes, the compiler is free to insert prefetch instructions into the code it generates. This may result in a performance improvement on architectures that support prefetch.Warnings
Explicit prefetching should only be used under special circumstances that are supported by measurements.
3.2.120
-xprofile=pCollects or optimizes with runtime profiling data.
This option causes execution frequency data to be collected and saved during the execution. The data can then be used in subsequent runs to improve performance. This option is valid only when a level of optimization is specified.
Values
p must be one of the following values.
Interactions
The
-xprofile=tcovand the-xaoptions are compatible in a single executable. That is, you can link a program that contains some files that have been compiled with-xprofile=tcovand other files compiled with-xa. You cannot compile a single file with both options.The code coverage report produced by
-xprofile=tcovcan be unreliable if there is inlining of functions due to use of-xO4.Warnings
If compilation and linking are performed in separate steps, the same
-xprofileoption must appear in the compile as well as the link step.See also
-xa,tcov(1) man page, Analyzing Program Performance With Sun WorkShop3.2.121
-xregs=r[,...r]SPARC: Controls scratch register usage.
The compiler can generate faster code if it has more registers available for temporary storage (scratch registers). This option makes available additional scratch registers that might not always be appropriate.
Values
r must be one of the following values. The meaning of each value depends upon the
-xarchsetting.
Defaults
If
-xregsis not specified,-xregs=appl,floatis assumed.Examples
To compile an application program using all available scratch registers, use
-xregs=appl,float.To compile non-floating-point code that is sensitive to context switch, use
-xregs=no%appl,no%float.See also
3.2.122
-xsAllows debugging by
dbxwithout object (.o) files.This option disables Auto-Read for
dbx. Use this option if you cannot keep the.ofiles. This option passes the-soption to the assembler.No Auto-Read is the older way of loading symbol tables. It places all symbol tables for
dbxin the executable file. The linker links more slowly, anddbxinitializes more slowly.Auto-Read is the newer and default way of loading symbol tables. With Auto-Read the information is placed in the
.ofiles, so thatdbxloads the symbol table information only if it is needed. Hence the linker links faster, and dbx initializes faster.With
-xs, if you move executables to another directory, you do not have to move the object (.o) files to usedbx.Without
-xs, if you move the executables to another directory, you must move both the source files and the object (.o) files to usedbx.3.2.123
-xsafe=memSPARC: Allows no memory-based traps to occur.
This option grants permission to use the speculative load instruction on V9 machines.
Interactions
This option is only effective if used with
-xO5optimization when-xarch=v8plus,v8plusa,v8plusb,v9,v9a, orv9bis specified.Warnings
You should use this option only if you can safely assert that no memory-based traps occur in your program. For most programs, this assertion is appropriate and can be safely made. For a program that explicitly forces memory-based traps to handle exceptional conditions, this assertion is not safe.
3.2.124
-xsbProduces information for the Sun WorkShop source browser.
This option causes the
CCdriver to generate extra symbol table information in theSunWS_cachesubdirectory for the source browser.See also
3.2.125
-xsbfastProduces only source browser information, no compilation.
This option runs only the
ccfephase to generate extra symbol table information in theSunWS_cachesubdirectory for the source browser. No object file is generated.See also
3.2.126
-xspaceSPARC: Does not allow optimizations that increase code size.
3.2.127
-xtarget=tSpecifies the target platform for instruction set and optimization.
The performance of some programs can benefit by providing the compiler with an accurate description of the target computer hardware. When program performance is critical, the proper specification of the target hardware could be very important. This is especially true when running on the newer SPARC processors. However, for most programs and older SPARC processors, the performance gain is negligible and a generic specification is sufficient.
Values
On SPARC platforms, t must be one of the following values.
nativeGets the best performance on the host system. 
The compiler generates code optimized for the host system. It determines the available architecture, chip, and cache properties of the machine on which the compiler is running.genericGets the best performance for generic architecture, chip, and cache. The compiler expands -xtarget=genericto:-xarch=generic -xchip=generic -xcache=generic
This is the default value.platform-name Gets the best performance for the specified platform. 
Select a SPARC platform name from TABLE 3-34.
The following table details the
-xtargetSPARC platform names and their expansions.
On IA platforms,
-xtargetaccepts the following values:
nativeorgeneric
386--Directs the compiler to generate code for the best performance on the Intel 80386 microprocessor.
486--Directs the compiler to generate code for the best performance on the Intel 80486 microprocessor.
pentium--Directs the compiler to generate code for the best performance on the Pentium or Pentium Pro microprocessor.
pentium_pro--Directs the compiler to generate code for the best performance on the Pentium Pro microprocessor.Defaults
On both SPARC and IA devices, if
-xtargetis not specified,-xtarget=genericis assumed.Expansions
The
-xtargetoption is a macro that permits a quick and easy specification of the-xarch,-xchip, and-xcachecombinations that occur on commercially purchased platforms. The only meaning of-xtargetis in its expansion.Examples
-xtarget=sun4/15means-xarch=v8a -xchip=micro -xcache=2/16/1Interactions
Compilation for SPARC V9 architecture indicated by the
-xarch=v9|v9a|v9boption. Setting-xtarget=ultraorultra2is not necessary or sufficient. If-xtargetis specified, the-xarch=v9,v9a, orv9boption must appear after the-xtarget. For example:
expands to the following and reverts the
-xarchvalue tov8.
The correct method is to specify
-xarchafter-xtarget. For example:
3.2.128
-xtimeCauses the
CCdriver to report execution time for the various compilation passes.3.2.129
-xunroll=nEnables unrolling of loops where possible.
This option specifies whether or not the compiler optimizes (unrolls) loops.
Values
When n is
1, it is a suggestion to the compiler to not unroll loops.When n is an integer greater than 1,
-unroll=n causes the compiler to unroll loops n times.3.2.130
-xvector[=(yes|no)]SPARC: Enable automatic calls to the SPARC vector library functions.
Defaults
The compiler defaults to
-xvector=no. Specifying-xvectorby itself defaults to-xvector=yes.Warnings
If you compile and link in separate steps, you must use the same
-xvectorsettings in each step.3.2.131
-xweConverts all warnings to errors by returning nonzero exit status.
3.2.132
-zargLink editor option. For more information, see the
ld(1) man page and the Solaris Linker and Libraries Guide.3.2.133
-ztextForces a fatal error if any relocations remain against nonwritable, allocatable sections.
| Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback | Library | Contents | Previous | Next | Index |