JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: C User's Guide
search filter icon
search icon

Document Information

Preface

1.  Introduction to the C Compiler

2.  C-Compiler Implementation-Specific Information

3.  Parallelizing C Code

4.  lint Source Code Checker

5.  Type-Based Alias Analysis

6.  Transitioning to ISO C

7.  Converting Applications for a 64-Bit Environment

8.  cscope: Interactively Examining a C Program

A.  Compiler Options Grouped by Functionality

B.  C Compiler Options Reference

B.1 Option Syntax

B.2 The cc Options

B.2.1 -#

B.2.2 -###

B.2.3 -Aname[(tokens)]

B.2.4 -B[static|dynamic]

B.2.5 -C

B.2.6 -c

B.2.7 -Dname[(arg[,arg])][=expansion]

B.2.8 -d[y|n]

B.2.9 -dalign

B.2.10 -E

B.2.11 -errfmt[=[no%]error]

B.2.12 -errhdr[=h]

B.2.13 -erroff[=t]

B.2.14 -errshort[=i]

B.2.15 -errtags[=a]

B.2.16 -errwarn[=t]

B.2.17 -fast

B.2.18 -fd

B.2.19 -features=[v]

B.2.20 -flags

B.2.21 -flteval[={any|2}]

B.2.22 -fma[={none|fused}]

B.2.23 -fnonstd

B.2.24 -fns[={no|yes}]

B.2.25 -fPIC

B.2.26 -fpic

B.2.27 -fprecision=p

B.2.28 -fround=r

B.2.29 -fsimple[=n]

B.2.30 -fsingle

B.2.31 -fstore

B.2.32 -ftrap=t[,t...]

B.2.33 -G

B.2.34 -g

B.2.35 -H

B.2.36 -h name

B.2.37 -I[-|dir]

B.2.38 -i

B.2.39 -include filename

B.2.40 -KPIC

B.2.41 -Kpic

B.2.42 -keeptmp

B.2.43 -Ldir

B.2.44 -lname

B.2.45 -m32|-m64

B.2.46 -mc

B.2.47 -misalign

B.2.48 -misalign2

B.2.49 -mr[,string]

B.2.50 -mt[={yes|no}]

B.2.50.1 See Also

B.2.51 -native

B.2.52 -nofstore

B.2.53 -O

B.2.54 -o filename

B.2.55 -P

B.2.56 -p

B.2.57 -Q[y|n]

B.2.58 -qp

B.2.59 -Rdir[:dir]

B.2.60 -S

B.2.61 -s

B.2.62 -traceback[={%none|common|signals_list}]

B.2.63 -Uname

B.2.64 -V

B.2.65 -v

B.2.66 -Wc,arg

B.2.67 -w

B.2.68 -X[c|a|t|s]

B.2.69 -x386

B.2.70 -x486

B.2.71 -xaddr32[=yes|no]

B.2.72 -xalias_level[=l]

B.2.73 -xannotate[=yes|no]

B.2.74 -xarch=isa

B.2.74.1 -xarch Flags for SPARC

B.2.74.2 -xarch Flags for x86

B.2.74.3 Special x86 Notes

B.2.74.4 Binary Compatibility Verification

B.2.74.5 Interactions

B.2.74.6 Warnings

B.2.75 -xautopar

B.2.76 -xbinopt={prepare|off}

B.2.77 -xbuiltin[=(%all|%none)]

B.2.78 -xCC

B.2.79 -xc99[=o]

B.2.80 -xcache[=c]

B.2.81 -xcg[89|92]

B.2.82 -xchar[=o]

B.2.83 -xchar_byte_order[=o]

B.2.84 -xcheck[=o]

B.2.84.1 Initialization Values for --xcheck=init_local

Basic Types

Initializing Structs, Unions, and Arrays

B.2.85 -xchip[=c]

B.2.86 -xcode[=v]

B.2.87 -xcrossfile

B.2.88 -xcsi

B.2.89 -xdebugformat=[stabs|dwarf]

B.2.90 -xdepend=[yes|no]

B.2.91 -xdryrun

B.2.92 -xe

B.2.93 -xF[=v[,v...]]

B.2.93.1 Values

B.2.94 -xhelp=f

B.2.95 -xhwcprof

B.2.96 -xinline=list

B.2.97 -xinstrument=[no%]datarace

B.2.98 -xipo[=a]

B.2.98.1 Examples

B.2.98.2 When Not To Use -xipo=2 Interprocedural Analysis

B.2.99 -xipo_archive=[a]

B.2.100 -xjobs=n

B.2.101 -xldscope={v}

B.2.102 -xlibmieee

B.2.103 -xlibmil

B.2.104 -xlibmopt

B.2.105 -xlic_lib=sunperf

B.2.106 -xlicinfo

B.2.107 -xlinkopt[=level]

B.2.108 -xloopinfo

B.2.109 -xM

B.2.110 -xM1

B.2.111 -xMD

B.2.112 -xMF filename

B.2.113 -xMMD

B.2.114 -xMerge

B.2.115 -xmaxopt[=v]

B.2.116 -xmemalign=ab

B.2.117 -xmodel=[a]

B.2.118 -xnolib

B.2.119 -xnolibmil

B.2.120 -xnolibmopt

B.2.121 -xnorunpath

B.2.122 -xO[1|2|3|4|5]

B.2.122.1 Explanation of SPARC Optimizations

B.2.122.2 Explanation of x86 Optimizations

B.2.123 -xopenmp[=i]

B.2.124 -xP

B.2.125 -xpagesize=n

B.2.126 -xpagesize_heap=n

B.2.127 -xpagesize_stack=n

B.2.128 -xpch=v

B.2.128.1 Creating a Precompiled-Header File Automatically

B.2.128.2 Creating a Precompiled-Header File Manually

B.2.128.3 How the Compiler Handles an Existing Precompiled-Header File

B.2.128.4 Directing the Compiler to Use a Specific Precompiled-Header File

B.2.128.5 The Viable Prefix

B.2.128.6 Screening a Header File for Problems

B.2.128.7 The Precompiled-Header File Cache

B.2.128.8 Warnings

B.2.128.9 Precompiled-Header File Dependencies and make Files

B.2.129 -xpchstop=[file|<include>]

B.2.130 -xpec[={yes|no}]

B.2.131 -xpentium

B.2.132 -xpg

B.2.133 -xprefetch[=val[,val]]

B.2.133.1 Prefetch Latency Ratio

B.2.134 -xprefetch_auto_type=a

B.2.135 -xprefetch_level=l

B.2.136 -xprofile=p

B.2.137 -xprofile_ircache[=path]

B.2.138 -xprofile_pathmap

B.2.139 -xreduction

B.2.140 -xregs=r[,r...]

B.2.141 -xrestrict[=f]

B.2.142 -xs

B.2.143 -xsafe=mem

B.2.144 -xsb

B.2.145 -xsbfast

B.2.146 -xsfpconst

B.2.147 -xspace

B.2.148 -xstrconst

B.2.149 -xtarget=t

B.2.149.1 -xtarget Values on SPARC Platforms

B.2.149.2 -xtarget Values on x86 Platforms

B.2.150 -xtemp=dir

B.2.151 -xthreadvar[=o]

B.2.152 -xtime

B.2.153 -xtransition

B.2.154 -xtrigraphs

B.2.155 -xunroll=n

B.2.156 -xustr={ascii_utf16_ushort|no}

B.2.157 -xvector[=a]

B.2.158 -xvis

B.2.159 -xvpara

B.2.160 -Yc, dir

B.2.161 -YA, dir

B.2.162 -YI, dir

B.2.163 -YP, dir

B.2.164 -YS, dir

B.2.165 -Zll

B.3 Options Passed to the Linker

C.  Implementation-Defined ISO/IEC C99 Behavior

D.  Supported Features of C99

E.  Implementation-Defined ISO/IEC C90 Behavior

F.  ISO C Data Representations

G.  Performance Tuning

H.  The Differences Between K&R Solaris Studio C and Solaris Studio ISO C

Index

B.2 The cc Options

This section describes the cc options, arranged alphabetically. These descriptions are also available in the man page, cc(1). Use the cc -flags option for a one-line summary of these descriptions.

Options noted as being unique to one or more platforms are accepted without error and ignored on all other platforms.

B.2.1 -#

Turns on verbose mode, showing how command options expand. Shows each component as it is invoked.

B.2.2 -###

Shows each component as it would be invoked, but does not actually execute it. Also shows how command options would expand.

B.2.3 -Aname[(tokens)]

Associates name as a predicate with the specified tokens as if by a #assert preprocessing directive. Preassertions:

These preassertions are not valid in -Xc mode.

If -A is followed by a dash (-) only, it causes all predefined macros (other than those that begin with __) and predefined assertions to be forgotten.

B.2.4 -B[static|dynamic]

Specifies whether bindings of libraries for linking are static or dynamic, indicating whether libraries are non-shared or shared, respectively.

–Bdynamic causes the link editor to look for files named libx.so and then for files named libx.a when given the -lx option.

–Bstatic causes the link editor to look only for files named libx.a. This option may be specified multiple times on the command line as a toggle. This option and its argument are passed to ld(1).


Note - Many system libraries, such as libc, are only available as dynamic libraries in the Solaris 64-bit compilation environment. Therefore, do not use -Bstatic as the last toggle on the command line.


This option and its argument are passed to the linker.

B.2.5 -C

Prevents the C preprocessor from removing comments, except those on the preprocessing directive lines.

B.2.6 -c

Directs the C compiler to suppress linking with ld(1) and to produce a .o file for each source file. You can explicitly name a single object file using the-o option. When the compiler produces object code for each .i or .c input file, it always creates an object (.o) file in the current working directory. If you suppress the linking step, you also suppress the removal of the object files.

B.2.7 -Dname[(arg[,arg])][=expansion]

Define a macro with optional arguments as if the macro is defined by a #define preprocessing directive. If no =expansion is specified, the compiler assumes 1.

See the cc(1) man page for a list of compiler predefined macros.

B.2.8 -d[y|n]

-dy specifies dynamic linking, which is the default, in the link editor.

-dn specifies static linking in the link editor.

This option and its arguments are passed to ld(1).


Note - This option causes fatal errors if you use it in combination with dynamic libraries. Most system libraries are only available as dynamic libraries.


B.2.9 -dalign

(SPARC) Obsolete. You should not use this option. Use -xmemalign=8s instead. See B.2.116 -xmemalign=ab for more information. For a complete list of obsolete options, see A.1.15 Obsolete Options. This option is silently ignored on x86 platforms.

B.2.10 -E

Runs the source file through the preprocessor only and sends the output to stdout. The preprocessor is built directly into the compiler, except in -Xs mode, where /usr/ccs/lib/cpp is invoked. Includes the preprocessor line numbering information. See also the– P option.

B.2.11 -errfmt[=[no%]error]

Use this option if you want to prefix the string “error:” to the beginning of error messages so they are more easily distinguishable from warning messages. The prefix is also attached to warnings that are converted to errors by -errwarn.

Table B-1 The -errfmt Flags

Flag
Meaning
error
Add the prefix “error:” to all error messages.
no%error
Do not add the prefix “error:” to any error messages.

If you do not specify this option, the compiler sets it to -errfmt=no%error. If you specify -errfmt, but do not supply a value, the compiler sets it to -errfmt=error.

B.2.12 -errhdr[=h]

Limit the warnings from header files to the group of header files indicated by the following flags:

Table B-2 The —errhdr option

Value
Meaning
%all
Check all header files used.
%none
Do not check header files.
%user
Checks all the user header files except those in /usr/include and its sub-directories. Also checks all the header files supplied by the compiler. This is the default.

B.2.13 -erroff[=t]

This command suppresses C compiler warning messages and has no effect on error messages. This option applies to all warning messages whether or not they have been designated by -errwarn to cause a non-zero exit status.

t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none. Order is important; for example, %all,no%tag suppresses all warning messages except tag. The following table lists the -erroff values:

Table B-3 The -erroff Flags

Flag
Meaning
tag
Suppresses the warning message specified by this tag. You can display the tag for a message by using the -errtags=yes option.
no%tag
Enables the warning message specified by this tag
%all
Suppresses all warning messages
%none
Enables all warning messages (default)

The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.

Only warning messages from the C compiler front-end that display a tag when the -errtags option is used can be suppressed with the -erroff option. You can achieve finer control over error message suppression. See 2.11.6 error_messages.

B.2.14 -errshort[=i]

Use this option to control how much detail is in the error message produced by the compiler when it discovers a type mismatch. This option is particularly useful when the compiler discovers a type mismatch that involves a large aggregate.

i can be one of the following:

Table B-4 The -errshort Flags

Flag
Meaning
short
Error messages are printed in short form with no expansion of types. Aggregate members are not expanded, neither are function argument and return types.
full
Error messages are printed in full verbose form showing the full expansion of the mismatched types.
tags
Error messages are printed with tag names for types which have tag names. If there is no tag name, the type is shown in expanded form.

If you do not specify -errshort, the compiler sets the option to -errshort=full. If you specify -errshort, but do not provide a value, the compiler sets the option to -errshort=tags.

This option does not accumulate, it accepts the last value specified on the command line.

B.2.15 -errtags[=a]

Displays the message tag for each warning message of the C compiler front-end that can be suppressed with the -erroff option or made a fatal error with the -errwarn option. Messages from the C compiler driver and other components of the C compilation system do not have error tags, and cannot be suppressed with -erroff and made fatal with -errwarn.

a can be either yes or no. The default is -errtags=no. Specifying -errtags is equivalent to specifying -errtags=yes.

B.2.16 -errwarn[=t]

Use the -errwarn option to cause the C compiler to exit with a failure status for the given warning messages.

t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none. Order is important; for example %all,no%tag causes cc to exit with a fatal status if any warning except tag is issued.

The warning messages generated by the C compiler change from release to release as the compiler error checking improves and features are added. Code that compiles using -errwarn=%all without error may not compile without error in the next release of the compiler.

Only warning messages from the C compiler front-end that display a tag when the -errtags option is used can be specified with the -errwarn option to cause the C compiler to exit with a failure status.

The following table details the -errwarn values:

Table B-5 The -errwarn Flags

Flag
Meaning
tag
Cause cc to exit with a fatal status if the message specified by this tag is issued as a warning message. Has no effect if tag is not issued.
no%tag
Prevent cc from exiting with a fatal status if the message specified by tag is issued only as a warning message. Has no effect if the message specified by tag is not issued. Use this option to revert a warning message that was previously specified by this option with tag or %all from causing cc to exit with a fatal status when issued as a warning message.
%all
Cause the compiler to exit with a fatal status if any warning messages are issued. %all can be followed by no%tag to exempt specific warning messages from this behavior.
%none
Prevents any warning message from causing the compiler to exit with a fatal status should any warning message be issued.

The default is -errwarn=%none. If you specify -errwarn alone, it is equivalent to -errwarn=%all.

B.2.17 -fast

This option is a macro that can be effectively used as a starting point for tuning an executable for maximum runtime performance. -fast is a macro that can change from one release of the compiler to the next and expands to options that are target platform specific. Use the -# option or -xdryrun to examine the expansion of -fast, and incorporate the appropriate options of -fast into the ongoing process of tuning the executable.

The expansion of -fast includes the -xlibmopt option, which enables the compiler to use a library of optimized math routines. For more information, see B.2.104 -xlibmopt.

The -fast option impacts the value of errno. See 2.13 Preserving The Value of errno for more information.

Modules that are compiled with -fast must also be linked with -fast. For a complete list of all compiler options that must be specified at both compile time and at link time, see A.1.2 Compile-Time and Link-Time Options.

The –fast option is unsuitable for programs intended to run on a different target than the compilation machine. In such cases, follow -fast with the appropriate -xtarget option. For example:

cc -fast -xtarget=generic ...

For C modules that depend on exception handling specified by SUID, follow -fast by -xnolibmil:

% cc -fast -xnolibmil

With -xlibmil, exceptions cannot be noted by setting errno or calling matherr(3m).

The –fast option is unsuitable for programs that require strict conformance to the IEEE 754 Standard.

The following table lists the set of options selected by -fast across platforms.

Table B-6 The -fast Expansion Flags

Option
SPARC
x86
-fns
X
X
-fsimple=2
X
X
-fsingle
X
X
-nofstore
-
X
-xalias_level=basic
X
X
-xbuiltin=%all
X
X
-xlibmil
X
X
-xlibmopt
X
X
-xmemalign=8s
X
-
-xO5
X
X
-xprefetch=auto,explicit
X
-
-xregs=frameptr
-
X
-xtarget=native
X
X

Note - Some optimizations make certain assumptions about program behavior. If the program does not conform to these assumptions, the application may crash or produce incorrect results. Please refer to the description of the individual options to determine if your program is suitable for compilation with -fast.


The optimizations performed by these options may alter the behavior of programs from that defined by the ISO C and IEEE standards. See the description of the specific option for details.

–fast acts like a macro expansion on the command line. Therefore, you can override the optimization level and code generation option aspects by following -fast with the desired optimization level or code generation option. Compiling with the -fast -xO4 pair is like compiling with the -xO2 -xO4 pair. The latter specification takes precedence.

On x86 the —fast option includes —xregs=frameptr. See the discussion of this option for details, especially when compiling mixed C, Fortran, and C++ source codes.

Do not use this option for programs that depend on IEEE standard exception handling; you can get different numerical results, premature program termination, or unexpected SIGFPE signals.

To see the actual expansion of —fast on a running platform, use

% cc -fast -xdryrun

B.2.18 -fd

Reports K&R-style function definitions and declarations.

B.2.19 -features=[v]

The following table lists the values you can use in place of v.

Table B-7 The -features Flags

Value
Meaning
[no%]conststrings
Enables or disables the placement of string literals in read-only memory. The default is -features=conststrings which places string literals into the read-only data section. Note that compiling a program that attempts to write to the memory location of a string literal will now cause a segmentation fault when compiled with this option.
extensions
Allows zero-sized struct/union declarations and void functions with return statements returning a value to work.
extinl
Generates extern inline functions as global functions. This is the default, which conforms to the 1999 C standard. Compile new codes with -features=no%extinl to obtain the same treatment of extern inline functions as provided by older versions of the C and C++ compilers.
no%extinl
Generates extern inline functions as static functions.
%none
The option is disabled.

Old C and C++ objects (created with Solaris Studio compilers prior to this release) can be linked with new C and C++ objects with no change of behavior for the old objects. To get standard conforming behavior, you must recompile old code with the current compiler.

If you do not specify a setting for -features, the compiler sets it to -features=extinl.

B.2.20 -flags

Prints a brief summary of each available compiler option.

B.2.21 -flteval[={any|2}]

(x86) Use this option to control how floating point expression are evaluated.

Table B-8 The -flteval Flags

Flag
Meaning
2
Floating point expressions are evaluated as long double.
any
Floating point expressions are evaluated depending on the combination of the types of the variables and constants that make up an expression.

If you do not specify -flteval, the compiler sets it to -flteval=any. If you do specify -flteval, but do not provide a value, the compiler sets it to -flteval=2.

You must not specify the following options in combination with -flteval=2:

See also D.1.1 Precision of Floating Point Evaluators.

B.2.22 -fma[={none|fused}]

(SPARC) Enables automatic generation of floating-point, fused, multiply-add instructions. -fma=none disables generation of these instructions. -fma=fused allows the compiler to attempt to find opportunities to improve the performance of the code by using floating-point, fused, multiply-add instructions.

The default is -fma=none.

The minimum requirements are -xarch=sparcfmaf and an optimization level of at least -xO2 for the compiler to generate fused multiply-add instructions. The compiler marks the binary program if fused multiply-add instructions are generated in order to prevent the program from executing on platforms that do not support them.

Fused multiply-adds eliminate the intermediate rounding step between the multiply and the add. Consequently, programs may produce different results when compiled with -fma=fused, although precision will tend to be increased rather than decreased.

B.2.23 -fnonstd

(SPARC) This option is a macro for -fns and -ftrap=common.

B.2.24 -fns[={no|yes}]

B.2.25 -fPIC

Equivalent to -KPIC

B.2.26 -fpic

Equivalent to -Kpic

B.2.27 -fprecision=p

(x86) -fprecision={single, double, extended}

Initializes the rounding-precision mode bits in the Floating-point Control Word to single (24 bits), double (53 bits), or extended (64 bits), respectively. The default floating-point rounding-precision mode is extended.

Note that on x86, only the precision, not exponent, range is affected by the setting of floating-point rounding precision mode.

This option is effective only on x86 systems and only if used when compiling the main program, but is ignored if compiling for 64–bit (-m64) or SSE2–enabled (-xarch=sse2) processors. It is also ignored on SPARC systems.

B.2.28 -fround=r

Sets the IEEE 754 rounding mode that is established at runtime during the program initialization.

r must be one of: nearest, tozero, negative, positive.

The default is -fround=nearest.

The meanings are the same as those for the ieee_flags subroutine.

When r is tozero, negative, or positive, this flag sets the rounding direction mode to round-to-zero, round-to-negative-infinity, or round-to-positive-infinity respectively when a program begins execution. When r is nearest or the -fround flag is not used, the rounding direction mode is not altered from its initial value (round-to-nearest by default).

This option is effective only if used when compiling the main program.

B.2.29 -fsimple[=n]

Allows the optimizer to make simplifying assumptions concerning floating-point arithmetic.

The compiler defaults to -fsimple=0. Specifying -fsimple, is equivalent to -fsimple=1.

If n is present, it must be 0, 1, or 2.

Table B-9 The -fsimple Flags

Value
Meaning
-fsimple=0
Permits no simplifying assumptions. Preserve strict IEEE 754 conformance.
-fsimple=1
Allows conservative simplifications. The resulting code does not strictly conform to IEEE 754, but numeric results of most programs are unchanged.

With -fsimple=1, the optimizer can assume the following:

  • IEEE 754 default rounding/trapping modes do not change after process initialization.

  • Computations producing no visible result other than potential floating point exceptions may be deleted.

  • Computations with Infinity or NaNs as operands need not propagate NaNs to their results; for example, x*0 may be replaced by 0.

  • Computations do not depend on sign of zero.

    With -fsimple=1, the optimizer is not allowed to optimize completely without regard to roundoff or exceptions. In particular, a floating-point computation cannot be replaced by one that produces different results with rounding modes held constant at runtime.

-fsimple=2
Includes all the functionality of -fsimple=1 and also enables use of SIMD instructions to compute reductions when -xvector=simd is in effect.

The compiler attempts aggressive floating point optimizations that may cause many programs to produce different numeric results due to changes in rounding. For example, -fsimple=2 permits the optimizer to replace all computations of x/y in a given loop with x*z, where x/y is guaranteed to be evaluated at least once in the loop, z=1/y, and the values of y and z are known to have constant values during execution of the loop.

Even with -fsimple=2, the optimizer is not permitted to introduce a floating point exception in a program that otherwise produces none.

See Techniques for Optimizing Applications: High Performance Computing written by Rajat Garg and Ilya Sharapov for a more detailed explanation of how optimization can impact precision.

B.2.30 -fsingle

(-Xt and -Xs modes only) Causes the compiler to evaluate float expressions as single precision rather than double precision. This option has no effect if the compiler is used in either -Xa or -Xc modes, as float expressions are already evaluated as single precision.

B.2.31 -fstore

(x86) Causes the compiler to convert the value of a floating-point expression or function to the type on the left-hand side of an assignment, when that expression or function is assigned to a variable, or when the expression is cast to a shorter floating-point type, rather than leaving the value in a register. Due to rounding and truncation, the results may be different from those that are generated from the register value. This is the default mode.

To turn off this option, use the -nofstore option.

B.2.32 -ftrap=t[,t...]

Sets the IEEE trapping mode in effect at startup but does not install a SIGFPE handler. You can use ieee_handler(3M) or fex_set_handling(3M) to simultaneously enable traps and install a SIGFPE handler. If you specify more than one value, the list is processed sequentially from left to right.

t can be one of the following values.

Table B-10 The -ftrap Flags

Flag
Meaning
[no%]division
[Do not] Trap on division by zero.
[no%]inexact
[Do not] Trap on inexact result.
[no%]invalid
[Do not] Trap on invalid operation.
[no%]overflow
[Do not] Trap on overflow.
[no%]underflow
[Do not] Trap on underflow.
%all
Trap on all of the above.
%none
Trap on none of the above.
common
Trap on invalid, division by zero, and overflow.

Note that the [no%] form of the option is used only to modify the meaning of the %all and common values, 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 do not specify –ftrap, the compiler assumes –ftrap=%none.

Example: –ftrap=%all,no%inexact means to set all traps except inexact.

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=inexact trap with caution. Use of –ftrap=inexact results 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.

B.2.33 -G

Produce a shared object rather than a dynamically linked executable. This option is passed to ld(1), and cannot be used with the -dn option.

When you use the -G option, the compiler does not pass any default -l options to ld. If you want the shared library to have a dependency on another shared library, you must pass the necessary -l option on the command line.

If you are creating a shared object by specifying -G along with other compiler options that must be specified at both compile time and link time, make sure that those same options are also specified when you link with the resulting shared object.

When you create a shared object, all the object files that are compiled with -xarch=v9 must also be compiled with an explicit -xcode value as documented in B.2.86 -xcode[=v].

B.2.34 -g

Produces additional symbol table information for debugging with dbx(1) and the Performance Analyzer analyzer(1).

If you specify -g, and the optimization level is -xO3 or lower, the compiler provides best-effort symbolic information with almost full optimization. Tail-call optimization and back-end inlining are disabled.

If you specify -g and the optimization level is -xO4, the compiler provides best-effort symbolic information with full optimization.

Compile with the -g option to use the full capabilities of the Performance Analyzer. While some performance analysis features do not require -g, you must compile with -g to view annotated source, some function level information, and compiler commentary messages. See the analyzer(1) man page and the Performance Analyzer manual for more information.

The commentary messages that are generated with -g describe the optimizations and transformations that the compiler made while compiling your program. Use the er_src(1) command to display the messages, which are interleaved with the source code.


Note - In previous releases, this option forced the compiler to use the incremental linker ( ild) by default instead of the linker ( ld) for link-only invocations of the compiler. That is, with -g, the compiler’s default behavior was to automatically invoke ild in place of ld whenever you used the compiler to link object files, unless you specified -G or source files on the command line. This is no longer the case. The incremental linker is no longer available.


For more information on debugging, see the Debugging a Program With dbx manual.

B.2.35 -H

Prints to standard error, one per line, the path name of each file included during the current compilation. The display is indented so as to show which files are included by other files.

Here, the program sample.c includes the files, stdio.h and math.h; math.h includes the file, floatingpoint.h, which itself includes functions that use sys/ieeefp.h:

% cc -H sample.c
    /usr/include/stdio.h
    /usr/include/math.h
        /usr/include/floatingpoint.h
            /usr/include/sys/ieeefp.h

B.2.36 -h name

Assigns a name to a shared dynamic library as a way to have different versions of a library. In general, the name after -h should be the same as the file name given after the -o option. The space between -h and name is optional.

The linker assigns the specified name to the library and 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.

When the runtime linker loads the library into an executable file, it copies the intrinsic name from the library file into the executable, into a list of needed shared library files. Every executable has such a list. If there is no intrinsic name of a shared library, then the linker copies the path of the shared library file instead.

B.2.37 -I[-|dir]

-I dir adds dir to the list of directories that are searched for #include files with relative file names prior to /usr/include, that is, those directory paths not beginning with a / (slash).

Directories for multiple -I options are searched in the order specified.

For more information on the search pattern of the compiler, see 2.16.1 Using the -I- Option to Change the Search Algorithm.

B.2.38 -i

Passes the option to the linker to ignore any LD_LIBRARY_PATH or LD_LIBRARY_PATH_64 setting.

B.2.39 -include filename

This option causes the compiler to treat filename as if it appears in the first line of a primary source file as a #include preprocessor directive. Consider the source file t.c:

main()
{
   ...
}

If you compile t.c with the command cc -include t.h t.c, the compilation proceeds as if the source file contains the following:

#include "t.h"
main()
{
   ...
}

The first directory the compiler searches for filename is the current working directory and not the directory containing the main source file, as is the case when a file is explicitly included. For example, the following directory structure contains two header files with the same name, but at different locations:

foo/
   t.c
   t.h
   bar/
     u.c
     t.h

If your working directory is foo/bar and you compile with the command cc ../t.c -include t.h, the compiler includes t.h from foo/bar, not foo/ as would be the case with a #include directive from within the source file t.c.

If the compiler cannot find the file specified with -include in the current working directory, it searches the normal directory paths for the file. If you specify multiple -include options, the files are included in the order they appear on the command line.

B.2.40 -KPIC

(SPARC) Obsolete. You should not use this option. Use -xcode=pic32 instead.

For more information, see B.2.86 -xcode[=v]. For a complete list of obsolete options, see A.1.15 Obsolete Options.

(x86) -KPIC is identical to -Kpic.

B.2.41 -Kpic

(SPARC) Obsolete. You should not use this option. Use -xcode=pic13 instead. For more information, see B.2.86 -xcode[=v]. For a complete list of obsolete options, see A.1.15 Obsolete Options.

(x86) Generate position-independent code for use in shared libraries (small model). Permits references to, at most, 2**11 unique external symbols.

B.2.42 -keeptmp

Retains temporary files created during compilation instead of deleting them automatically.

B.2.43 -Ldir

Adds dir to the list of directories searched for libraries by ld(1). This option and its arguments are passed to ld(1).


Note - Never specify the compiler installation area, /usr/include, /lib, or /usr/lib, as search directories.


B.2.44 -lname

Links with object library libname.so, or libname.a. The order of libraries in the command-line is important, as symbols are resolved from left to right.

This option must follow the sourcefile arguments.

B.2.45 -m32|-m64

Specifies the memory model for the compiled binary object.

Use -m32 to create 32-bit executables and shared libraries. Use -m64 to create 64-bit executables and shared libraries.

The ILP32 memory model (32-bit int, long, pointer data types) is the default on all Solaris platforms and on Linux platforms that are not 64-bit enabled. The LP64 memory model (64-bit long, pointer data types) is the default on Linux platforms that are 64-bit enabled. -m64 is permitted only on platforms that are enabled for the LP64 model.

Object files or libraries compiled with -m32 cannot be linked with object files or libraries compiled with-m64.

Modules that are compiled with -m32|-m64 must also be linked with -m32|-m64. For a complete list of compiler options that must be specified at both compile time and at link time, see A.1.2 Compile-Time and Link-Time Options

When compiling applications with large amounts of static data using -m64 on x86/x64 platforms, -xmodel=medium may also be required. Be aware that some Linux platforms do not support the medium model.

Note that in previous compiler releases, the memory model, ILP32 or LP64, was implied by the choice of the instruction set with -xarch. Starting with the Solaris Studio 12 compilers, this is no longer the case. On most platforms, just adding -m64 to the command line is sufficient to create 64-bit objects.

On Solaris, -m32 is the default. On Linux systems supporting 64-bit programs, -m64 -xarch=sse2 is the default.

See also -xarch.

B.2.46 -mc

Removes duplicate strings from the .comment section of the object file. When you use the -mc flag, mcs -c is invoked.

B.2.47 -misalign

(SPARC) Obsolete. You should not use this option. Use the -xmemalign=1i option instead. For more information, see B.2.116 -xmemalign=ab. For a complete list of obsolete options, see A.1.15 Obsolete Options.

B.2.48 -misalign2

(SPARC) Obsolete. You should not use this option. Use the -xmemalign=2i option instead. For more information, see B.2.116 -xmemalign=ab. For a complete list of obsolete options, see A.1.15 Obsolete Options.

B.2.49 -mr[,string]

-mr removes all strings from the .comment section. When you use this flag, mcs -d -a is invoked.

-mr,string removes all strings from the .comment section and inserts string in that section of the object file. If string contains embedded blanks, it must be enclosed in quotation marks. A null string results in an empty .comment section. This option is passed as -d -astring to mcs.

B.2.50 -mt[={yes|no}]

Use this option to compile and link multithreaded code using the Solaris threads or POSIX threads API. The -mt=yes option assures that libraries are linked in the appropriate order.

This option passes -D_REENTRANT to the preprocessor.

To use Solaris threads, include the thread.h header file and compile with the —mt=yes option. To use POSIX threads on Solaris platforms, include the pthread.h header file and compile with the —mt=yes option.

On Linux platforms, only the POSIX threads API is available. (There is no libthread on Linux platforms.) Consequently, —mt=yes on Linux platforms adds —lpthread instead of —lthread. To use POSIX threads on Linux platforms, compile with —mt.

Note that when compiling with —G, neither —lthread nor —lpthread are automatically included by —mt=yes. You will need to explicitly list these libraries when building a shared library.

The —xopenmp option (for using the OpenMP shared-memory parallelization API) includes —mt=yes automatically.

If you compile with -mt=yes and link in a separate step, you must use the -mt=yes option in the link step as well as the compile step. If you compile and link one translation unit with -mt=yes, you must compile and link all units of the program with -mt=yes

-mt=yes is the default behavior of the compiler. If this behavior is not desired, compile with —mt=no.

The option —mt is equivalent to —mt=yes.

B.2.50.1 See Also

–xnolib, and the Solaris Multithreaded Programming Guide, and Linker and Libraries Guide

B.2.51 -native

This option is a synonym for -xtarget=native.

B.2.52 -nofstore

(x86) Does not convert the value of a floating-point expression or function to the type on the left-hand side of an assignment, when that expression or function is assigned to a variable or is cast to a shorter floating-point type; rather, it leaves the value in a register. See also B.2.31 -fstore.

B.2.53 -O

Use default optimization level -xO3. The -O macro now expands to -xO3 instead of -xO2.

The change in default yields higher run-time performance. However, -x03 may be inappropriate for programs that rely on all variables being automatically considered volatile. Typical programs that might have this assumption are device drivers and older multi-threaded applications that implement their own synchronization primitives. The work around is to compile with -xO2 instead of -O.

B.2.54 -o filename

Names the output file filename (as opposed to the default, a.out). filename cannot be the same as sourcefile, since cc does not overwrite the source file. This option and its arguments are passed to ld(1).

B.2.55 -P

Runs the source file through the C preprocessor only. It then puts the output in a file with a .i suffix. Unlike -E, this option does not include preprocessor-type line number information in the output. See also the -E option.

B.2.56 -p

Obsolete, see B.2.132 -xpg.

B.2.57 -Q[y|n]

Emits or does not emit identification information to the output file. -Qy is the default.

If -Qy is used, identification information about each invoked compilation tool is added to the .comment section of output files, which is accessible with mcs. This option can be useful for software administration.

-Qn suppresses this information.

B.2.58 -qp

Same as -p.

B.2.59 -Rdir[:dir]

Passes a colon-separated list of directories used to specify library search directories to the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker.

If both LD_RUN_PATH and the -R option are specified, the -R option takes precedence.

B.2.60 -S

Directs cc to produce an assembly source file but not to assemble the program.

B.2.61 -s

Removes all symbolic debugging information from the output object file. This option cannot be specified with -g.

Passed to ld(1).

B.2.62 -traceback[={%none|common|signals_list}]

Issue a stack trace if a severe error occurs in execution.

The -traceback option causes the executable to issue a stack trace to stderr, dump core, and exit if certain signals are generated by the program. If multiple threads generate a signal, a stack trace will only be produced for the first one.

To use traceback, add the -traceback option to the compiler command line when linking. The option is also accepted at compile-time but is ignored unless an executable binary is generated. Using -traceback with -G to create a shared library is an error.

Table B-11 -traceback Options

Option
Meaning
common
specifies that a stack trace should be issued if any of a set of common signals occurs: sigill, sigfpe, sigbus, sigsegv, or sigabrt.
signals_list
specifies a comma-separated list of names of signals that should generate a stack trace, in lower case. The following signals (those that cause the generation of a core file) can be caught: sigquit, sigill, sigtrap, sigabrt, sigemt, sigfpe, sigbus, sigsegv, sigsys, sigxcpu, sigxfsz.

Any of these can be preceeded with no% to disable catching the signal.

For example: -traceback=sigsegv,sigfpe will produce a stack trace and core dump if either sigsegv or sigfpe occurs.

%none or none
disables traceback

If the option is not specified, the default is -traceback=%none

-traceback alone, without a = sign, implies -traceback=common

Note: If the core dump is not wanted, users may set the coredumpsize limit to zero using:

% limit coredumpsize 0            

The -traceback option has no effect on runtime performance.

B.2.63 -Uname

Undefines the preprocessor symbol name. This option removes any initial definition of the preprocessor symbol name created by -D on the same command line including those placed there by the command-line driver.

-U has no effect on any preprocessor directives in source files. You can give multiple -U options on the command line.

If the same name is specified for both -D and -U on the command line, name is undefined, regardless of the order the options appear. In the following example, -U undefines __sun:

cc -U__sun text.c

Preprocessor statements of the following form in test.c will not take effect because __sun is undefined.

#ifdef(__sun)

See B.2.7 -Dname[(arg[,arg])][=expansion] for a list of predefined symbols.

B.2.64 -V

Directs cc to print the name and version ID of each component as the compiler executes.

B.2.65 -v

Directs the compiler to perform stricter semantic checks and to enable other lint-like checks. For example, the code:

#include <stdio.h>
main(void)
{
     printf("Hello World.\n");
}

compiles and executes without problem. With -v, it still compiles; however, the compiler displays this warning:

"hello.c", line 5: warning: function has no return statement:
 main

-v does not give all the warnings that lint(1) does. Try running the above example through lint.

B.2.66 -Wc,arg

Passes the argument arg to a specified component c. See Table 1-1 for a list of components.

Each argument must be separated from the preceding only by a comma. All -W arguments are passed after the regular command-line arguments. A comma can be part of an argument by using the escape character \ (backslash) immediately before the comma. All -W arguments are passed after the regular command-line arguments.

For example, -Wa,-o,objfile passes -o and objfile to the assembler, in that order. Also, -Wl,-I,name causes the linking phase to override the default name of the dynamic linker, /usr/lib/ld.so.1.

The order in which the argument(s) are passed to a tool with respect to the other specified command line options may change.

c can be one of the following:

Table B-12 The -W Flags

Flag
Meaning
a
Assembler: (fbe); (gas)
c
C code generator: (cg) (SPARC) ;
d
cc driver
h
Intermediate code translator (ir2hf)(x86)
l
Link editor (ld)
m
mcs
O (Capital o)
Interprocedural optimizer
o (Lowercase o)
Postoptimizer
p
Preprocessor (cpp)
u
C code generator (ube) (x86)
0 (Zero)
Compiler (acomp) (ssbd, SPARC)
2
Optimizer: (iropt)

B.2.67 -w

Suppresses compiler warning messages.

This option overrides the error_messages pragma.

B.2.68 -X[c|a|t|s]

The -X (note uppercase X) options specify varying degrees of compliance to the ISO C standard. The value of -xc99 affects which version of the ISO C standard the -X option applies. The -xc99 option defaults to -xc99=all which supports the 1999 ISO/IEC C standard. -xc99=none supports the 1990 ISO/IEC C standard. See Table C-6 for a discussion of supported 1999 ISO/IEC features. See G.1 The libfast.a Library (SPARC) for a discussion of differences between ISO/IEC C and K&R C.

The default mode is -Xa.

-Xc

(c = conformance) Issues errors and warnings for programs that use non-ISO C constructs. This option is strictly conformant ISO C, without K&R C compatibility extensions. The predefined macro __STDC__ has a value of 1 with the-Xc option.

-Xa

This is the default compiler mode. ISO C plus K&R C compatibility extensions, with semantic changes required by ISO C. Where K&R C and ISO C specify different semantics for the same construct, the compiler uses the ISO C interpretation. If the -Xa option is used in conjunction with the -xtransition option, the compiler issues warnings about the different semantics. The predefined macro __STDC__has a value of -0 with the-Xa option.

-Xt

(t = transition) This option uses ISO C plus K&R C compatibility extensions without semantic changes required by ISO C. Where K&R C and ISO C specify different semantics for the same construct, the compiler uses the K&R C interpretation. If you use the -Xt option in conjunction with the -xtransition option, the compiler issues warnings about the different semantics. The predefined macro __STDC__ has a value of 0 with the -Xt option.

-Xs

(s = K&R C) Attempts to warn about all language constructs that have differing behavior between ISO C and K&R C. The compiler language includes all features compatible with K&R C. This option invokes cpp for preprocessing. __STDC__ is not defined in this mode.

B.2.69 -x386

(x86) Obsolete. You should not use this option. Use -xchip=generic instead. For a complete list of obsolete options, see A.1.15 Obsolete Options.

B.2.70 -x486

(x86) Obsolete. You should not use this option. Use -xchip=generic instead. For a complete list of obsolete options, see A.1.15 Obsolete Options.

B.2.71 -xaddr32[=yes|no]

(Solaris x86/x64 only) The -xaddr32=yes compilation flag restricts the resulting executable or shared object to a 32-bit address space.

An executable that is compiled in this manner results in the creation of a process that is restricted to a 32-bit address space.

When -xaddr32=no is specified a usual 64 bit binary is produced.

If the -xaddr32 option is not specified, -xaddr32=no is assumed.

If only -xaddr32 is specified -xaddr32=yes is assumed.

This option is only applicable to -m64 compilations and only on Solaris platforms supporting SF1_SUNW_ADDR32 software capability. Since Linux kernels do not support address space limitation, this option is not available on Linux.

When linking, if a single object file was compiled with -xaddr32=yes the whole output file is assumed to be compiled with -xaddr32=yes.

A shared object that is restricted to a 32-bit address space must be loaded by a process that executes within a restricted 32-bit mode address space.

For more information refer to the SF1_SUNW_ADDR32 software capabilities definition, described in the Linker and Libraries Guide.

B.2.72 -xalias_level[=l]

The compiler uses the -xalias_level option to determine what assumptions it can make in order to perform optimizations using type-based alias-analysis. This option places the indicated alias level into effect for the translation units being compiled.

If you do not specify the -xalias_level command, the compiler assumes -xalias_level=any. If you specify -xalias_level without a value, the default is -xalias_level=layout.

The -xalias_level option requires optimization level -xO3 or above. If optimization is set lower, a warning is issued and the -xalias_level option is ignored.

Remember that if you issue the -xalias_level option but you fail to adhere to all of the assumptions and restrictions about aliasing described for any of the alias levels, the behavior of your program is undefined.

Replace l with one of the terms in the following table.

Table B-13 The Levels of Alias-Disambiguation

Flag
Meaning
any
The compiler assumes that all memory references can alias at this level. There is no type-based alias analysis at the level of -xalias_level=any.
basic
If you use the -xalias_level=basic option, the compiler assumes that memory references that involve different C basic types do not alias each other. The compiler also assumes that references to all other types can alias each other as well as any C basic type. The compiler assumes that references using char * can alias any other type.

For example, at the -xalias_level=basic level, the compiler assumes that a pointer variable of type int * is not going to access a float object. Therefore it is safe for the compiler to perform optimizations that assume a pointer of type float * will not alias the same memory that is referenced with a pointer of type int *.

weak
If you use the -xalias_level=weak option, the compiler assumes that any structure pointer can point to any structure type.

Any structure or union type that contains a reference to any type that is either referenced in an expression in the source being compiled or is referenced from outside the source being compiled, must be declared prior to the expression in the source being compiled.

You can satisfy this restriction by including all the header files of a program that contain types that reference any of the types of the objects referenced in any expression of the source being compiled.

At the level of -xalias_level=weak, the compiler assumes that memory references that involve different C basic types do not alias each other. The compiler assumes that references using char * alias memory references that involve any other type.

layout
If you use the -xalias_level=layout option, the compiler assumes that memory references that involve types with the same sequence of types in memory can alias each other.

The compiler assumes that two references with types that do not look the same in memory do not alias each other. The compiler assumes that any two memory accesses through different struct types alias if the initial members of the structures look the same in memory. However, at this level, you should not use a pointer to a struct to access some field of a dissimilar struct object that is beyond any of the common initial sequence of members that look the same in memory between the two structs. This is because the compiler assumes that such references do not alias each other.

At the level of -xalias_level=layout the compiler assumes that memory references that involve different C basic types do not alias each other. The compiler assumes that references using char * can alias memory references involving any other type.

strict
If you use the -xalias_level=strict option, the compiler assumes that memory references, that involve types such as structs or unions, that are the same when tags are removed, can alias each other. Conversely, the compiler assumes that memory references involving types that are not the same even after tags are removed do not alias each other.

However, any structure or union type that contains a reference to any type that is part of any object referenced in an expression in the source being compiled, or is referenced from outside the source being compiled, must be declared prior to the expression in the source being compiled.

You can satisfy this restriction by including all the header files of a program that contain types that reference any of the types of the objects referenced in any expression of the source being compiled. At the level of -xalias_level=strict the compiler assumes that memory references that involve different C basic types do not alias each other. The compiler assumes that references using char * can alias any other type.

std
If you use the -xalias_level=std option, the compiler assumes that types and tags need to be the same to alias, however, references using char * can alias any other type. This rule is the same as the restrictions on the dereferencing of pointers that are found in the 1999 ISO C standard. Programs that properly use this rule will be very portable and should see good performance gains under optimization.
strong
If you use the -xalias_level=strong option, the same restrictions apply as at the std level, but additionally, the compiler assumes that pointers of type char * are used only to access an object of type char. Also, the compiler assumes that there are no interior pointers. An interior pointer is defined as a pointer that points to a member of a struct.

B.2.73 -xannotate[=yes|no]

(Solaris) Instructs the compiler to create binaries that can later be transformed by binary modification tools like binopt(1). Use the -xannotate=no option to prevent the modification of the binary file by these tools. The -xannotate=yes option must be used with optimization level -xO1 or higher to be effective.

This option is not available on Linux platforms.

B.2.74 –xarch=isa

Specifies the target instruction set architecture (ISA).

This option limits the code generated by the compiler to the instructions of the specified instruction set architecture. This option does not guarantee use of any target–specific instructions. However, use of this option may affect the portability of a binary program.


Note - Use the -m64 or -m32 option to specify the intended memory model, LP64 (64-bits) or ILP32 (32-bits) respectively. The -xarch option no longer indicates the memory model, except for compatibility with previous releases, as indicated below.


If you compile and link in separate steps, make sure you specify the same value for -xarch in both steps.

B.2.74.1 -xarch Flags for SPARC

The following table gives the details for each of the -xarch keywords on SPARC platforms.

Table B-14 The -xarch Flags for SPARC Platforms

Flag
Meaning
generic
Uses the instruction set common to most processors. This is the default.
generic64
Compile for good performance on most 64-bit platforms. (Solaris only).

This option is equivalent to -m64 -xarch=generic and is provided for compatibility with earlier releases. Use -m64 to specify 64-bit compilation instead of -xarch=generic64.

native
Compile for good performance on this system. The compiler chooses the appropriate setting for the current system processor it is running on.
native64
Compile for good performance on this system (Solaris only). This option is equivalent to -m64 -xarch=native and is provided for compatibility with earlier releases.
sparc
Compile for the SPARC-V9 ISA, but without the Visual Instruction Set (VIS), and without other implementation-specific ISA extensions. This option enables the compiler to generate code for good performance on the V9 ISA.
sparcvis
Compile for SPARC-V9 plus the Visual Instruction Set (VIS) version 1.0, and with UltraSPARC extensions. This option enables the compiler to generate code for good performance on the UltraSPARC architecture.
sparcvis2
Enables the compiler to generate object code for the UltraSPARC architecture, plus the Visual Instruction Set (VIS) version 2.0, and with UltraSPARC III extensions.
sparcvis3
Compile for the SPARC VIS version 3 of the SPARC-V9 ISA. Enables the compiler to use instructions from the SPARC-V9 instruction set, plus the UltraSPARC extensions, including the Visual Instruction Set (VIS) version 1.0, the UltraSPARC-III extensions, including the Visual Instruction Set (VIS) version 2.0, the fused multiply-add instructions, and the Visual Instruction Set (VIS) version 3.0
sparcfmaf
Enables the compiler to use instructions from the SPARC-V9 instruction set, plus the UltraSPARC extensions, including the Visual Instruction Set (VIS) version 1.0, the UltraSPARC-III extensions, including the Visual Instruction Set (VIS) version 2.0, and the SPARC64 VI extensions for floating-point multiply-add.

You must use -xarch=sparcfmaf in conjunction with fma=fused and some optimization level to get the compiler to attempt to find opportunities to use the multiply-add instructions automatically.

sparcima
Compile for the sparcima version of the SPARC-V9 ISA. Enables the compiler to use instructions from the SPARC-V9 instruction set, plus the UltraSPARC extensions, including the Visual Instruction Set (VIS) version 1.0, the UltraSPARC-III extensions, including the Visual Instruction Set (VIS) version 2.0, the SPARC64 VI extensions for floating-point multiply-add, and the SPARC64 VII extensions for integer multiply-add.
v9
Is equivalent to -m64 -xarch=sparc. Legacy makefiles and scripts that use -xarch=v9 to obtain the 64-bit memory model need only use -m64.
v9a
Is equivalent to -m64 -xarch=sparcvis and is provided for compatibility with earlier releases.
v9b
Is equivalent to -m64 -xarch=sparcvis2 and is provided for compatibility with earlier releases.

Also note the following:

B.2.74.2 -xarch Flags for x86

The following table lists the -xarch flags on x86 platforms.

Table B-15 The -xarch Flags on x86

Flag
Meaning
amd64
Is equivalent to -m64 -xarch=sse2 (Solaris only). Legacy makefiles and scripts that use -xarch=amd64 to obtain the 64-bit memory model need only use -m64.
amd64a
Is equivalent to -m64 -xarch=sse2a (Solaris only).
generic
Uses the instruction set common to most processors. This is the default, and is equivalent to pentium_pro when compiling with —m32, and sse2 with —m64.
generic64
Compile for good performance on most 64-bit platforms. (Solaris only). This option is equivalent to -m64 -xarch=generic and is provided for compatibility with earlier releases. Use -m64 to specify 64-bit compilation instead of -xarch=generic64.
native
Compile for good performance on this system. The compiler chooses the appropriate setting for the current system processor it is running on.
native64
Compile for good performance on this system (Solaris only). This option is equivalent to -m64 -xarch=native and is provided for compatibility with earlier releases.
pentium_pro
Limits the instruction set to the 32–bit pentium_pro architecture.
pentium_proa
Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the 32-bit pentium_pro architecture.
sse
Adds the SSE instruction set to the pentium_pro architecture.
ssea
Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the 32-bit SSE architecture.
sse2
Adds the SSE2 instruction set to the pentium_pro architecture.
sse2a
Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the 32-bit SSE2 architecture.
sse3
Adds the SSE3 instruction set to SSE2 instruction set.
ssse3
Supplements the pentium_pro, SSE, SSE2, and SSE3 instruction sets with the SSSE3 instruction set.
sse4_1
Supplements the pentium_pro, SSE, SSE2, SSE3, and SSSE3 instruction sets with the SSE4.1 instruction set.
sse4_2
Supplements the pentium_pro, SSE, SSE2, SSE3,SSSE3, and SSE4.1 instruction sets with the SSE4.2 instruction set.
amdsse4a
Uses the AMD SSE4a Instruction set.
B.2.74.3 Special x86 Notes

There are some important issues to be aware of when compiling for x86 Solaris platforms.

Programs compiled with -xarch set to sse, sse2, sse2a, sse3, or beyond must be run only on platforms that provide these extensions and features.

Solaris OS releases are SSE/SSE2-enabled on Pentium 4-compatible platforms. Earlier versions of Solaris OS are not SSE/SSE2-enabled. If an instruction set selected by -xarch is not enabled in the running Solaris OS, the compiler will not be able to generate or link code for that instruction set.

If you compile and link in separate steps, always link using the compiler and using the same -xarch setting to ensure that the correct startup routine is linked.

Numerical results on x86 may differ from results on SPARC due to the x86 80-bit floating-point registers. To minimize these differences, use the -fstore option or compile with -xarch=sse2 if the hardware supports SSE2.

Numerical results can also differ between Solaris and Linux because the intrinsic math libraries (for example, sin(x)) are not the same.

B.2.74.4 Binary Compatibility Verification

Starting with Solaris Studio 11 and the Solaris 10 OS, program binaries compiled and built using these specialized -xarch hardware flags are verified that they are being run on the appropriate platform.

On systems prior to Solaris 10, no verification is done and it is the user's responsibility to ensure objects built using these flags are deployed on suitable hardware.

Running programs compiled with these -xarch options on platforms that are not enabled with the appropriate features or instruction set extensions could result in segmentation faults or incorrect results occurring without any explicit warning messages.

This warning extends also to programs that employ .il inline assembly language functions or __asm() assembler code that utilize SSE, SSE2, SSE2a, and SSE3 instructions and extensions.

B.2.74.5 Interactions

Although this option can be used alone, it is part of the expansion of the -xtarget option and may be used to override the –xarch value that is set by a specific -xtarget option. For example, -xtarget=ultra2 expands to -xarch=sparcvis -xchip=ultra2 -xcache=16/32/1:512/64/1. In the following command -xarch=generic overrides the -xarch=sparcvis that is set by the expansion of -xtarget=ultra2.

example% cc -xtarget=ultra2 -xarch=generic foo.c
B.2.74.6 Warnings

If you use this option 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.

If you compile and link in separate steps, make sure you specify the same value for -xarch in both steps.

B.2.75 -xautopar


Note - This option does not enable OpenMP parallelization directives.


Turns on automatic parallelization for multiple processors. Does dependence analysis (analyze loops for inter-iteration data dependence) and loop restructuring. If optimization is not at-xO3 or higher, optimization is raised to-xO3 and a warning is emitted.

Avoid-xautopar if you do your own thread management.

To achieve faster execution, this option requires a multiple processor system. On a single-processor system, the resulting binary usually runs slower.

To run a parallelized program in a multithreaded environment, you must set the OMP_NUM_THREADS environment variable prior to execution. See the Solaris Studio OpenMP API User's Guide for more information.

If you use-xautopar and compile and link in one step, then linking automatically includes the microtasking library and the threads-safe C runtime library. If you use-xautopar and compile and link in separate steps, then you must also link with-xautopar. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

B.2.76 -xbinopt={prepare|off}

(SPARC) Instructs the compiler to prepare the binary for later optimizations, transformations and analysis, see binopt(1). This option may be used for building executables or shared objects. This option must be used with optimization level -xO1 or higher to be effective. There is a modest increase in size of the binary when built with this option.

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

example% cc -c -xO1 -xbinopt=prepare a.c b.c
example% cc -o myprog -xbinopt=prepare a.o

If some source code is not available for compilation, this option may still be used to compile the remainder of the code. It should then be used in the link step that creates the final binary. In such a situation, only the code compiled with this option can be optimized, transformed or analyzed.

Compiling with -xbinopt=prepare and -g increases the size of the executable by including debugging information. The default is -xbinopt=off.

B.2.77 -xbuiltin[=(%all|%none)]

Use the -xbuiltin[=(%all|%none)] command when you want to improve the optimization of code that calls standard library functions. Many standard library functions, such as the ones defined in math.h and stdio.h, are commonly used by various programs. This command lets the compiler substitute intrinsic functions or inline system functions where profitable for performance. See the er_src(1) man page for an explanation of how to read compiler commentary in object files to determine for which functions the compiler actually makes a substitution.

However, these substitutions can cause the setting of errno to become unreliable. If your program depends on the value of errno, avoid this option. See also 2.13 Preserving The Value of errno.

If you do not specify -xbuiltin, the default is -xbuiltin=%none, which means no functions from the standard libraries are substituted or inlined. If you specify -xbuiltin, but do not provide any argument, the default is -xbuiltin=%all, which means the compiler substitutes intrinsics or inlines standard library functions as it determines the optimization benefit.

If you compile with -fast, then -xbuiltin is set to %all.


Note - -xbuiltin only inlines global functions defined in system header files, never static functions defined by the user.


B.2.78 -xCC

When you specify -xc99=none and -xCC, the compiler accepts the C++-style comments. In particular, // can be used to indicate the start of a comment.

B.2.79 -xc99[=o]

The -xc99 option controls compiler recognition of the implemented features from the C99 standard (ISO/IEC 9899:1999, Programming Language - C).

o can be a comma separated list comprised of the following:

Table B-16 The -xc99 Flags

Flag
Meaning
[no]_lib
[Do not] Enable the 1999 C standard library semantics of routines that appeared in both the 1990 and 1999 C standard.
all
Turn on recognition of supported C99 language features and enable the 1999 C standard library semantics of routines that appear in both the 1990 and 1999 C standard.
none
Turn off recognition of C99 language features, and do not enable the 1999 C standard library semantics of routines that appeared in both the 1990 and 1999 C standard.

If you do not specify -xc99, the compiler defaults to -xc99=all,no_lib. If you specify -xc99 without any values, the option is set to-xc99=all.


Note - Though the compiler support-level defaults to the language features of the C99 standard, the standard headers provided by the Solaris 8 and Solaris 9 operating systems in /usr/include do not conform with the 1999 ISO/IEC C standard. If you encounter error messages, try specifying -xc99=none to obtain the 1990 ISO/IEC C standard behavior for these headers.


The 1999 C standard library semantics of routines that appeared in both the 1990 and 1999 C standard are not available and therefore cannot be enabled on Solaris 8 and Solaris 9 software. The compiler issues an error message when you specify -xc99=lib directly or indirectly on Solaris 8 or Solaris 9 software.

B.2.80 -xcache[=c]

Defines cache properties for use by the optimizer. This option 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 -xtarget option; its primary use is to override a value supplied by the -xtarget option.


This release introduces an optional property [/ti] which sets the number of threads that can share the cache. If you do not specify a value for t, the default is 1.

c must be one of the following:

The s/l/a/t properties are defined 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
ti
The number of hardware threads sharing the cache at level i

The following table lists the-xcache values.

Table B-17 The -xcache Flags

Flag
Meaning
generic
This is the default value which directs the compiler to use cache properties for good performance on most x86 and SPARC processors, without major performance degradation on any of them.

With each new release, these best timing properties will be adjusted, if appropriate.

native
Set the parameters for the best performance on the host environment.
s1/l1/a1[/t1]
Define level 1 cache properties.
s1/l1/a1[/t1]:s2/l2/a2[/t2]
Define levels 1 and 2 cache properties.
s1/l1/a1[/t1]:s2/l2/a2[/t2]:s3/l3/a3[/t3]
Define levels 1, 2, and 3 cache properties.

Example:-xcache=16/32/4:1024/32/1 specifies the following:

Level 1 cache has:

16K bytes

32 bytes line size

4-way associativity

Level 2 cache has:

1024K bytes

32 bytes line size

Direct mapping associativity

B.2.81 –xcg[89|92]

(SPARC) Obsolete. You should not use this option. Current Solaris operating systems no longer support SPARC V7 architecture. Compiling with this option generates code that runs slower on current SPARC platforms. Use -O instead and take advantage of compiler defaults for -xarch, -xchip, and -xcache.

B.2.82 -xchar[=o]

The option is provided solely for the purpose of easing the migration of code from systems where the char type is defined as unsigned. Unless you are migrating from such a system, do not use this option. Only code that relies on the sign of a char type needs to be rewritten to explicitly specify signed or unsigned.

You can substitute one of the following for o:

Table B-18 The -xchar Flags

Flag
Meaning
signed
Treat character constants and variables declared as char as signed. This impacts the behavior of compiled code, it does not affect the behavior of library routines.
s
Equivalent to signed
unsigned
Treat character constants and variables declared as char as unsigned. This impacts the behavior of compiled code, it does not affect the behavior of library routines.
u
Equivalent to unsigned

If you do not specify -xchar, the compiler assumes -xchar=s.

If you specify -xchar, but do not specify a value, the compiler assumes -xchar=s.

The -xchar option changes the range of values for the type char only for code compiled with -xchar. This option does not change the range of values for type char in any system routine or header file. In particular, the value of CHAR_MAX and CHAR_MIN, as defined by limits.h, do not change when this option is specified. Therefore, CHAR_MAX and CHAR_MIN no longer represent the range of values encodable in a plain char.

If you use -xchar, be particularly careful when you compare a char against a predefined system macro because the value in the macro may be signed. This is most common for any routine that returns an error code which is accessed through a macro. Error codes are typically negative values so when you compare a char against the value from such a macro, the result is always false. A negative number can never be equal to any value of an unsigned type.

It is strongly recommended that you never use -xchar to compile routines for any interface exported through a library. The Solaris ABI specifies type char as signed, and system libraries behave accordingly. The effect of making char unsigned has not been extensively tested with system libraries. Instead of using this option, modify your code so that it does not depend on whether type char is signed or unsigned. The sign of type char varies among compilers and operating systems.

B.2.83 -xchar_byte_order[=o]

Produce an integer constant by placing the characters of a multi-character character-constant in the specified byte order. You can substitute one of the following values for o:

B.2.84 -xcheck[=o]

Add runtime checks for stack overflow and initialize local variables.

You can substitute one of the following values for o:

Table B-19 The -xcheck Flags

Flag
Meaning
%none
Perform none of the -xcheck checks.
%all
Perform all of the -xcheck checks.
stkovf
Turns on stack-overflow checking.-xcheck=stkovf adds a runtime check for stack overflow of the main thread in a singly-threaded program as well as slave-thread stacks in a multithreaded program. If a stack overflow is detected, a SIGSEGV is generated. If your application needs to handle a SIGSEGV caused by a stack overflow differently than it handles other address-space violations, see sigaltstack(2).
no%stkovf
Turns off stack-overflow checking.
init_local
Initialize local variables. See discussion below for details.
no%init_local
Do not initialize local variables.

If you do not specify -xcheck, the compiler defaults to-xcheck=%none. If you specify -xcheck without any arguments, the compiler defaults to-xcheck=%all.

The -xcheck option does not accumulate on the command line. The compiler sets the flag in accordance with the last occurrence of the command.

B.2.84.1 Initialization Values for —xcheck=init_local

With —xcheck=init_local, the compiler initializes local variable declared without an initializer to a pre-defined value as shown in the table below. (Note that these values may change and should not be relied upon.)

Basic Types

Table B-20 init_local Initialization for Basic Types

Type
Initialization Value
char, _Bool
0x85
short
0x8001
int, long, enum     (-m32)
0xff80002b
long    (-m64)
0xfff00031ff800033
long long
0xfff00031ff800033
pointer
0x00000001 (-m32)

0x0000000000000001 (-m64)

float, float _Imaginary
0xff800001
float _Complex
0xff80000fff800011
double
SPARC: 0xfff00003ff800005

x86: 0xfff00005ff800003

double _Imaginary
0xfff00013ff800015
long double, long double _Imaginary
SPARC: 0xffff0007ff800009 / 0xfff0000bff80000d

x86: 12 bytes (-m32): 0x80000009ff800005 / 0x0000ffff

x86 - 16 bytes (-m64): 0x80000009ff800005 / 0x0000ffff00000000

double _Complex
0xfff00013ff800015 / 0xfff00017ff800019
long double _Complex
SPARC: 0xffff001bff80001d / 0xfff0001fff800021 / 0xffff0023ff800025 / 0xfff00027ff800029

x86 - 12 bytes (-m32): 0x7fffb01bff80001d / 0x00007fff / 0x7fffb023ff800025 / 0x00007fff

x86 - 16 bytes (-m64): 0x00007fff00080000 / 0x1b1d1f2100000000 / 0x00007fff00080000 / 0x2927252300000000

Note that local variables declared for use with the computed goto, which are simple void * pointers, will be initialized according to the description for pointers shown in the table above.

The following local variable types are never initialized: const qualified, register, label numbers for computed goto's, local labels, variable length arrays (VLAs)

Initializing Structs, Unions, and Arrays

Fields in a struct that are basic types are initialized as described in the table above, as is the first declared pointer or float field in a union. This maximizes the likelihood that an uninitialized reference generates a visible error.

Array elements are also initialized as described in the table above.

Nested struct, union, array fields are initialized as described above, except for the following cases: a struct containing bit-fields, a union without a pointer or float field, or an array of types that cannot be fully initialized. These will be initialized with the value used for local variables of type double. Variable length arrays are not initialized.

B.2.85 -xchip[=c]

Specifies the target processor for use by the optimizer.

c must be one of the following: generic, old, super, super2, micro, micro2, hyper, hyper2, powerup, ultra, ultra2, ultra2e, ultra2i, ultra3, ultra3cu, pentium, pentium_pro.

Although this option can be used alone, it is part of the expansion of the-xtarget option; its primary use is to override a value supplied by the-xtarget option.

This option specifies timing properties by specifying the target processor. Some effects are:

The following table lists the -xchip values for SPARC platforms:

Table B-21 The SPARC -xchip Flags

Flag
Meaning
generic
Use timing properties for good performance on most SPARC architectures.

This is the default value that directs the compiler to use the best timing properties for good performance on most processors, without major performance degradation on any of them.

native
Set the parameters for the best performance on the host environment.
old
Uses timing properties of pre-SuperSPARC processors.
sparc64vi
Optimize for the SPARC64 VI processor.
sparc64vii
Optimize for the SPARC64 VII processor
super
Uses timing properties of the SuperSPARC processors.
super2
Uses timing properties of the SuperSPARC II processors.
micro
Uses timing properties of the microSPARC processors.
micro2
Uses timing properties of the microSPARC II processors.
hyper
Uses timing properties of the hyperSPARC processors.
hyper2
Uses timing properties of the hyperSPARC II processors.
powerup
Uses timing properties of the Weitek PowerUp processors.
ultra
Uses timing properties of the UltraSPARC processors.
ultra2
Uses timing properties of the UltraSPARC II processors.
ultra2e
Uses timing properties of the UltraSPARC IIe processors.
ultra2i
Uses timing properties of the UltraSPARC IIi processors.
ultra3
Uses timing properties of the UltraSPARC III processors.
ultra3cu
Uses timing properties of the UltraSPARC III Cu processors.
ultra3i
Uses the timing properties of the UltraSPARC IIIi processors.
ultra4
Uses timing properties of the UltraSPARC IV processors.
ultra4plus
Uses the timing properties of the UltraSPARC IVplus processor.
ultraT1
Uses the timing properties of the UltraSPARC T1 processor.
ultraT2
Uses the timing properties of the UltraSPARC T2 processor.
ultraT2plus
Uses the timing properties of the UltraSPARC T2+ processor.
ultraT3
Uses the timing properties of the UltraSPARC T3 processor.

The following table lists the -xchip values for the x86 platforms:

Table B-22 The x86 -xchip Flags

Flag
Meaning
generic
Use timing properties for good performance on most x86 architectures.

This is the default value that directs the compiler to use the best timing properties for good performance on most processors, without major performance degradation on any of them.

native
Set the parameters for the best performance on the host environment.
core2
Optimize for the Intel Core2 processor.
nehalem
Optimize for the Intel Nehalem processor.
opteron
Optimize for the AMD Opteron processor.
penryn
Optimize for the Intel Penryn processor.
pentium
Uses timing properties of the x86 pentium architecture
pentium_pro
Uses timing properties of the x86 pentium_pro architecture
pentium3
Uses the timing properties of the x86 Pentium 3 architecture.
pentium4
Uses the timing properties of the x86 Pentium 4 architecture.
amdfam10
Optimize for the AMD AMDFAM10 processor.

B.2.86 -xcode[=v]

(SPARC) Specify code address space.


Note - It is highly recommended that you build shared objects by specifying -xcode=pic13 or -xcode=pic32. It is possible to build workable shared objects with -xarch=v9 -xcode=abs64 and with -xarch=v8 -xcode=abs32, but these will be inefficient. Shared objects built with -xarch=v9, -xcode=abs32, or -xarch=v9, -xcode=abs44 will not work.


v must be one of:

Table B-23 The -xcode Flags

Value
Meaning
abs32
This is the default on 32-bit architectures. Generates 32-bit absolute addresses. Code + data + bss size is limited to 2**32 bytes.
abs44
This is the default on 64-bit architectures. Generates 44-bit absolute addresses. Code + data + bss size is limited to 2**44 bytes. Available only on 64–bit architectures.
abs64
Generates 64-bit absolute addresses. Available only on 64-bit architectures.
pic13
Generates position-independent code for use in shared libraries (small model). Equivalent to -Kpic. Permits references to at most 2**11 unique external symbols on 32-bit architectures, 2**10 on 64-bit architectures.
pic32
Generates position-independent code for use in shared libraries (large model). Equivalent to -KPIC. Permits references to at most 2**30 unique external symbols on 32-bit architectures, 2**29 on 64-bit architectures.

The default is -xcode=abs32 for 32–bit architectures. The default for 64–bit architectures is-xcode=abs44.

When building shared dynamic libraries, the default -xcode values of abs44 and abs32 will not work with 64–bit architectures. Specify -xcode=pic13 or -xcode=pic32 instead. There are two nominal performance costs with– xcode=pic13 and– xcode=pic32 on SPARC.

When considering the above costs, remember that the use of -xcode=pic13 and -xcode=pic32 can significantly reduce system memory requirements, due to the effect of library code sharing. Every page of code in a shared library compiled -xcode=pic13 or– xcode=pic32 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 -xcode=pic13 or– xcode=pic32 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– xcode=pic13 or– xcode=pic32, check the size of the Global Offset Table (GOT) by using elfdump -c (see the elfdump(1) man page for more information) and to look for the section header, sh_name: .got. The sh_size value is the size of the GOT. If the GOT is less than 8,192 bytes, specify -xcode=pic13, otherwise specify -xcode=pic32.

In general, use the following guidelines to determine how you should use -xcode:

B.2.87 -xcrossfile

Obsolete, do not use. Use -xipo instead. —xcrossfile is an alias for —xipo=1.

B.2.88 -xcsi

Allows the C compiler to accept source code written in locales that do not conform to the ISO C source character code requirements. These locales include: ja_JP.PCK.

The compiler translation phases required to handle such locales may result in significantly longer compilation times. You should only use this option when you compile source files that contain source characters from one of these locales.

The compiler does not recognize source code written in locales that do not conform to the ISO C source character code requirements unless you specify -xcsi.

B.2.89 -xdebugformat=[stabs|dwarf]

Specify -xdebugformat=dwarf if you maintain software which reads debugging information in the dwarf format. This option causes the compiler to generate debugging information by using the dwarf standard format and is the default.

Table B-24 The -xdebugformat Flags

Value
Meaning
stabs
-xdebugformat=stabs generates debugging information using the stabs standard format.
dwarf
-xdebugformat=dwarf generates debugging information using the dwarf standard format (default).

If you do not specify -xdebugformat, the compiler assumes -xdebugformat=dwarf. This option requires an argument.

This option affects the format of the data that is recorded with the -g option. Some small amount of debugging information is recorded even without -g, and the format of that information is also controlled with this option. So -xdebugformat has an effect even when -g is not used.

The dbx and Performance Analyzer software understand both stabs and dwarf format so using this option does not have any effect on the functionality of either tool.

See also the dumpstabs(1) and dwarfdump(1) man pages for more information.

B.2.90 -xdepend=[yes|no]

Analyzes loops for inter-iteration data dependencies and does loop restructuring, including loop interchange, loop fusion, and scalar replacement.

-xdepend defaults to -xdepend=on for all optimization levels -xO3 and above. Specifying an explicit setting of -xdepend overrides any default setting.

Specifying -xdepend without an argument is equivalent to -xdepend=yes.

Dependency analysis may help on single-processor systems. However, if you uese -xdepend on single-processor systems, you should not also specify -xautopar , because the -xdepend optimization will be done for a multiprocessor system.

B.2.91 -xdryrun

This option is a macro for -###.

B.2.92 -xe

Performs only syntax and semantic checking on the source file, but does not produce any object or executable code.

B.2.93 -xF[=v[,v...]]

Enables optimal reordering of functions and variables by the linker.

This option instructs the compiler to place functions and/or data variables into separate section fragments, which enables the linker, using directions in a mapfile specified by the linker’s -M option, to reorder these sections to optimize program performance. Generally, this optimization is only effective when page fault time constitutes a significant fraction of program run time.

Reording of variables can help solve the following problems which negatively impact run-time performance:

Reordering variables and functions for optimal performance requires the following operations:

  1. Compiling and linking with -xF.

  2. Following the instructions in the "Program Performance Analysis" Tools manual regarding how to generate a mapfile for functions or following the instructions in the "Linker and Libraries Guide" regarding how to generate a mapfile for data.

  3. Relinking with the new mapfile by using the linker’s -M option.

  4. Re-executing under the Analyzer to verify improvement.

B.2.93.1 Values

v can be one or more of the following:

Table B-25 The -xF Values

Value
Meaning
[no%]func
[Do not] fragment functions into separate sections.
[no%]gbldata
[Do not] fragment global data (variables with external linkage) into separate sections.
[no%]lcldata
[Do not] fragment local data (variables with internal linkage) into separate sections.
%all
Fragment functions, global data, and local data.
%none
Fragment nothing.

If you do not specify -xF, the default is -xF=%none. If you specify -xF without any arguments, the default is -xF=%none,func.

Using -xF=lcldata inhibits some address calculation optimizations, so you should only use this flag when it is experimentally justified.

analyzer(1), ld(1) man pages.

B.2.94 -xhelp=f

Displays on-line help information.

f must be either flags, or readme.

-xhelp=flags displays a summary of the compiler options.

-xhelp=readme displays the README file.

B.2.95 -xhwcprof

(SPARC) Enables compiler support for hardware counter-based profiling.

When -xhwcprof is enabled, the compiler generates information that helps tools associate profiled load and store instructions with the data-types and structure members (in conjunction with symbolic information produced with -gto which they refer. It associates profile data with the data space of the target, rather than the instruction space, and provides insight into behavior that is not easily obtained from only instruction profiling.

You can compile a specified set of object files with -xhwcprof. However, -xhwcprof is most useful when applied to all object files in the application. This will provide coverage to identify and correlate all memory references distributed in the application’s object files.

If you are compiling and linking in separate steps, use -xhwcprof at link time as well. Future extensions to -xhwcprof may require its use at link time. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

An instance of -xhwcprof=enable or -xhwcprof=disable overrides all previous instances of -xhwcprof in the same command line.

-xhwcprof is disabled by default. Specifying -xhwcprof without any arguments is the equivalent to -xhwcprof=enable.

-xhwcprof requires that optimization be turned on and that the debug data format be set to DWARF (-xdebugformat=dwarf).

The combination of -xhwcprof and -g increases compiler temporary file storage requirements by more than the sum of the increases due to -xhwcprof and -g specified alone.

The following command compiles example.c and specifies support for hardware counter profiling and symbolic analysis of data types and structure members using DWARF symbols:

example% cc -c -O -xhwcprof -g -xdebugformat=dwarf example.c

For more information on hardware counter-based profiling, see the Program Performance Analysis Tools manual.

B.2.96 -xinline=list

The format of the list for -xinline is as follows: [{%auto,func_name,no%func_name}[,{%auto,func_name,no%func_name}]...]

-xinline tries to inline only those functions specified in the optional list. The list is either empty, or comprised of a comma-separated list of func_name, no%func_name, or %auto, where func_name is a function name. -xinline only has an effect at -xO3 or higher.

Table B-26 The -xinline Flags

Flag
Meaning
%auto
Specifies that the compiler is to attempt to automatically inline all functions in the source file. %auto only takes effect at -xO4 or higher optimization levels. %auto is silently ignored at -xO3 or lower optimization levels.
func_name
Specifies that the compiler is to attempt to inline the named function.
no%func_name
Specifies that the compiler is not to inline the named function.

The list of values accumulates from left to right. So for a specification of -xinline=%auto,no%foo the compiler attempts to inline all functions except foo. For a specification of -xinline=%bar,%myfunc,no%bar the compiler only tries to inline myfunc.

When you compile with optimization set at -xO4 or above, the compiler normally tries to inline all references to functions defined in the source file. You can restrict the set of functions the compiler attempts to inline by specifying the -xinline option. If you specify only -xinline=, that is you do not name any functions or %auto, this indicates that none of the routines in the source files are to be inlined. If you specify a list of func_name and no%func_name without specifying %auto, the compiler only attempts to inline those functions specified in the list. If %auto is specified in the list of values with the -xinline option at optimization level set at -xO4 or above, the compiler attempts to inline all functions that are not explicitly excluded by no%func_name.

A function is not inlined if any of the following conditions apply. No warning is issued.

If you specify multiple -xinline options on the command line, they do not accumulate. The last -xinline on the command line specifies what functions the compiler attempts to inline.

See also -xldscope.

B.2.97 -xinstrument=[no%]datarace

Specify this option to compile and instrument your program for analysis by the Thread Analyzer. For more information on the Thread Analyzer, seetha(1) for details.

You can then use the Performance Analyzer to run the instrumented program with collect -r races to create a data-race-detection experiment. You can run the instrumented code standalone but it runs more slowly.

You can specify -xinstrument=no%datarace to turn off preparation of source code for the thread analyzer. This is the default.

It is illegal to specify -xinstrument without an argument.

If you compile and link in separate steps, you must specify -xinstrument=datarace in both the compilation and linking steps.

This option defines the preprocessor token __THA_NOTIFY. You can specify #ifdef __THA_NOTIFY to guard calls to libtha(3) routines.

This option also sets -g.

B.2.98 -xipo[=a]

Replace a with 0, 1, or 2. -xipo without any arguments is equivalent -xipo=1. -xipo=0 is the default setting and turns off -xipo. With -xipo=1, the compiler performs inlining across all source files.

With -xipo=2, the compiler performs interprocedural aliasing analysis as well as optimizations of memory allocation and layout to improve cache performance.

The compiler performs partial-program optimizations by invoking an interprocedural analysis component. It performs optimizations across all object files in the link step, and is not limited to just the source files of the compile command. However, whole-program optimizations performed with -xipo do not include assembly (.s) source files.

You must specify -xipo both at compile time and at link time. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

The -xipo option generates significantly larger object files due to the additional information needed to perform optimizations across files. However, this additional information does not become part of the final executable binary file. Any increase in the size of the executable program is due to the additional optimizations performed. The object files created in the compilation steps have additional analysis information compiled within them to permit crossfile optimizations to take place at the link step.

-xipo is particularly useful when compiling and linking large multi-file applications. Object files compiled with this flag have analysis information compiled within them that enables interprocedural analysis across source and pre-compiled program files.

However, analysis and optimization is limited to the object files compiled with -xipo, and does not extend to object files or libraries.

-xipo is multiphased, so you need to specify -xipo for each step if you compile and link in separate steps.

Other important information about -xipo:

B.2.98.1 Examples

In this example, compilation and linking occur in a single step:

cc -xipo -xO4 -o prog part1.c part2.c part3.c

The optimizer performs crossfile inlining across all three source files. This is done in the final link step, so the compilation of the source files need not all take place in a single compilation and could take place over a number of separate compilations, each specifying -xipo.

In this example, compilation and linking occur in separate steps:

cc -xipo -xO4 -c part1.c part2.c
cc -xipo -xO4 -c part3.c
cc -xipo -xO4 -o prog part1.o part2.o part3.o

A restriction is that libraries, even if compiled with -xipo, do not participate in crossfile interprocedural analysis, as this example shows:

cc -xipo -xO4 one.c two.c three.c
ar -r mylib.a one.o two.o three.o
...
cc -xipo -xO4 -o myprog main.c four.c mylib.a

Here interprocedural optimizations are performed between one.c, two.c and three.c, and between main.c and four.c, but not between main.c or four.c and the routines on mylib.a. (The first compilation may generate warnings about undefined symbols, but the interprocedural optimizations are performed because it is a compile and link step.)

B.2.98.2 When Not To Use -xipo=2 Interprocedural Analysis

The compiler tries to perform whole-program analysis and optimizations as it works with the set of object files in the link step. The compiler makes the following two assumptions for any function (or subroutine) foo() defined in this set of object files:

Do not compile with either -xipo=1 or -xipo=2, if assumption 2 is not true.

As an example, consider interposing on the function malloc() with your own version and compiling with -xipo=2. Consequently, all the functions in any library that reference malloc() that are linked with your code have to be compiled with -xipo=2 also and their object files need to participate in the link step. Since this might not be possible for system libraries, do not compile your version of malloc with -xipo=2.

As another example, suppose that you build a shared library with two external calls, foo() and bar() inside two different source files. Furthermore, suppose that bar() calls foo(). If there is a possibility that foo() could be interposed at runtime, then do not compile the source file for foo() or for bar() with -xipo=1 or -xipo=2. Otherwise, foo() could be inlined into bar(), which could cause incorrect results.

B.2.99 -xipo_archive=[a]

The -xipo_archive option enables the compiler to optimize object files that are passed to the linker with object files that were compiled with -xipo and that reside in the archive library (.a) before producing an executable. Any object files contained in the library that were optimized during the compilation are replaced with their optimized version.

a is one of the following:

Table B-27 The -xipo_archive Flags

Value
Meaning
writeback
The compiler optimizes object files passed to the linker with object files compiled with -xipo that reside in the archive library (.a) before producing an executable. Any object files contained in the library that were optimized during the compilation are replaced with an optimized version.

For parallel links that use a common set of archive libraries, each link should create its own copy of archive libraries to be optimized before linking.

readonly
The compiler optimizes object files passed to the linker with object files compiled with -xipo that reside in the archive library (.a) before producing an executable.

The option -xipo_archive=readonly enables cross-module inlining and interprocedural data flow analysis of object files in an archive library specified at link time. However, it does not enable cross-module optimization of the archive library's code except for code that has been inserted into other modules by cross module inlining.

To apply cross-module optimization to code within an archive library, -xipo_archive=writeback is required. Note that doing so modifies the contents of the archive library from which the code was extracted.

none
This is the default. There is no processing of archive files. The compiler does not apply cross-module inlining or other cross-module optimizations to object files compiled using -xipo and extracted from an archive library at link time. To do that, both -xipo and either -xipo_archive=readonly or -xipo_archive=writeback must be specified at link time.

If you do not specify a setting for -xipo_archive, the compiler sets it to -xipo_archive=none.

It is illegal to specify -xipo_archive without a flag.

B.2.100 -xjobs=n

Specify the -xjobs option to set how many processes the compiler creates to complete its work. This option can reduce the build time on a multi-cpu machine. Currently, -xjobs works only with the -xipo option. When you specify -xjobs=n, the interprocedural optimizer uses n as the maximum number of code generator instances it can invoke to compile different files.

Generally, a safe value for n is 1.5 multiplied by the number of available processors. Using a value that is many times the number of available processors can degrade performance because of context switching overheads among spawned jobs. Also, using a very high number can exhaust the limits of system resources such as swap space.

You must always specify -xjobs with a value. Otherwise an error diagnostic is issued and compilation aborts.

Multiple instances of -xjobs on the command line override each other until the right-most instance is reached.

The following example compiles more quickly on a system with two processors than the same command without the -xjobs option.

 example% cc -xipo -xO4 -xjobs=3 t1.c t2.c t3.c

It is illegal to specify -xipo_archive without a flag.

B.2.101 -xldscope={v}

Specify the -xldscope option to change the default linker scoping for the definition of extern symbols. Changing the default can result in faster and safer shared libraries because the implementation is better hidden.

v must be one of the following:

Table B-28 The -xldscope Flags

Flag
Meaning
global
Global linker scoping is the least restrictive linker scoping. All references to the symbol bind to the definition in the first dynamic module that defines the symbol. This linker scoping is the current linker scoping for extern symbols.
symbolic
Symbolic linker scoping and is more restrictive than global linker scoping. All references to the symbol from within the dynamic module being linked bind to the symbol defined within the module. Outside of the module, the symbol appears as though it were global. This linker scoping corresponds to the linker option -Bsymbolic. See ld(1) for more information on the linker.
hidden
Hidden linker scoping is more restrictive than symbolic and global linker scoping. All references within a dynamic module bind to a definition within that module. The symbol will not be visible outside of the module.

If you do not specify -xldscope, the compiler assumes -xldscope=global. The compiler issues an error if you specify -xldscope without an argument. Multiple instances of this option on the command line override each other until the rightmost instance is reached.

If you intend to allow a client to override a function in a library, you must be sure that the function is not generated inline during the library build. The compiler inlines a function if you specify the function name with -xinline, if you compile at -xO4 or higher in which case inlining can happen automatically, if you use the inline specifier, if you use the inline pragma, or if you are using cross-file optimization.

For example, suppose library ABC has a default allocator function that can be used by library clients, and is also used internally in the library:

void* ABC_allocator(size_t size) { return malloc(size); }

If you build the library at -xO4 or higher, the compiler inlines calls to ABC_allocator that occur in library components. If a library client wants to replace ABC_allocator with a customized version, the replacement will not occur in library components that called ABC_allocator. The final program will include different versions of the function.

Library functions declared with the __hidden or __symbolic specifiers can be generated inline when building the library. They are not supposed to be overridden by clients. See 2.2 Linker Scoping Specifiers.

Library functions declared with the __global specifier, should not be declared inline, and should be protected from inlining by use of the -xinline compiler option.

See also -xinline, -xO, -xcrossfile, #pragma inline

B.2.102 -xlibmieee

Forces IEEE 754 style return values for math routines in exceptional cases. In such cases, no exception message is printed, and you should not rely on errno.

B.2.103 -xlibmil

Inlines some library routines for faster execution. This option selects the appropriate assembly language inline templates for the floating-point option and platform for your system.

-xlibmil inlines a function regardless of any specification of the function as part of the -xinline flag.

However, these substitutions can cause the setting of errno to become unreliable. If your program depends on the value of errno, avoid this option. See also 2.13 Preserving The Value of errno.

B.2.104 -xlibmopt

Enables the compiler to use a library of optimized math routines. You must use default rounding mode by specifying -fround=nearest when you use this option.

The math routine library is optimized for performance and usually generates faster code. The results may be slightly different from those produced by the normal math library. If so, they usually differ in the last bit.

However, these substitutions can cause the setting of errno to become unreliable. If your program depends on the value of errno, avoid this option. See also 2.13 Preserving The Value of errno.

The order on the command line for this library option is not significant.

This option is set by the -fast option.

See also: -fast -xnolibmopt

B.2.105 -xlic_lib=sunperf

Links in the Solaris Studio supplied performance libraries.

B.2.106 -xlicinfo

This option is silently ignored by the compiler.

B.2.107 -xlinkopt[=level]

(SPARC) Instructs the compiler to perform link-time optimizations on relocatable 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 ).

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

Table B-29 The -xlinkopt Flags

Flag
Meaning
0
The post-optimizer is disabled. (This is the default.)
1
Perform optimizations based on control flow analysis, including instruction cache coloring and branch optimizations, at link time.
2
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

For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

Note that the level parameter is only used when the compiler is linking. In the example above, the post- optimization level used is 2 even though the object binaries were 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 B.2.136 -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.

B.2.108 -xloopinfo

Shows which loops are parallelized and which are not. Gives a short reason for not parallelizing a loop. The -xloopinfo option is valid only if -xautopar is specified; otherwise, the compiler issues a warning.

To achieve faster execution, this option requires a multiprocessor system. On a single-processor system, the generated code usually runs slower.

B.2.109 -xM

Runs only the C preprocessor on the named C programs, requesting that the preprocessor generate makefile dependencies and send the result to the standard output (see make(1) for details about make files and dependencies).

For example:

#include <unistd.h>
void main(void)
{}

generates this output:

e.o: e.c
e.o: /usr/include/unistd.h
e.o: /usr/include/sys/types.h
e.o: /usr/include/sys/machtypes.h
e.o: /usr/include/sys/select.h
e.o: /usr/include/sys/time.h
e.o: /usr/include/sys/types.h
e.o: /usr/include/sys/time.h
e.o: /usr/include/sys/unistd.h

If you specify -xM and -xMF, the compiler appends all makefile dependency information to the file specified with -xMF.

B.2.110 -xM1

Generates makefile dependencies like -xM, but excludes /usr/include files. For example:

more hello.c
#include<stdio.h>
main()
{
    (void)printf(“hello\n”);
}
cc– xM hello.c
hello.o: hello.c
hello.o: /usr/include/stdio.h

Compiling with -xM1 does not report header file dependencies:

cc– xM1 hello.c
hello.o: hello.c

-xM1 is not available under -Xs mode.

If you specify -xM1 and -xMF, the compiler appends all makefile dependency information to the file specified with -xMF.

B.2.111 -xMD

Generates makefile dependencies like -xM but compilation continues. -xMD generates an output file for the makefile-dependency information derived from the -o output filename, if specified, or the input source filename, replacing (or adding) the filename suffix with .d . If you specify -xMD and -xMF, the preprocessor writes all makefile dependency information to the file specified with -xMF. Compiling with -xMD -xMF or -xMD -o filename with more than one source file is not allowed and generates an error. The dependency file is overwritten if it already exists.

B.2.112 -xMF filename

Use this option to specify a file for the makefile- dependency output. There is no way to specify individual filenames for multiple input files with -xMF on one command line. Compiling with -xMD -xMF or -xMMD -xMF with more than one source file is not allowed and generates an error. The dependency file is overwritten if it already exists.

B.2.113 -xMMD

Use this option to generate makefile dependencies excluding system header files. This is the same functionality as -xM1, but compilation continues. -xMMD generates an output file for the makefile-dependency information derived from the -o output filename, if specified, or the input source filename, replacing (or adding) the filename suffix with .d . If you specify -xMF, the compiler uses the filename you provide instead. Compiling with -xMMD -xMF or -xMMD -o filename with more than one source file is not allowed and generates an error. The dependency file is overwritten if it already exists.

B.2.114 -xMerge

Merges data segments into text segments. Data initialized in the object file produced by this compilation is read-only and (unless linked with ld -N) is shared between processes.

The three options -xMerge -ztext -xprofile=collect should not be used together. While -xMerge forces statically initialized data into read-only storage, -ztext prohibits position-dependent symbol relocations in read-only storage, and -xprofile=collect generates statically initialized, position-dependent symbol relocations in writable storage.

B.2.115 -xmaxopt[=v]

This command limits the level of pragma opt to the level specified. v is one of off, 1, 2, 3, 4, 5. The default value is -xmaxopt=off which causes pragma opt to be ignored. If you specify -xmaxopt without supplying an argument, that is the equivalent of specifying -xmaxopt=5.

If you specify both -xO and -xmaxopt, the optimization level set with -xO must not exceed the -xmaxopt value.

B.2.116 -xmemalign=ab

(SPARC) Use the -xmemalign option to control the assumptions the compiler makes about the alignment of data. By controlling the code generated for potentially misaligned memory accesses and by controlling program behavior in the event of a misaligned access, you can more easily port your code to SPARC.

Specify the maximum assumed memory alignment and behavior of misaligned data accesses. There must be a value for both a (alignment) and b (behavior). a specifies the maximum assumed memory alignment and b specifies the behavior for misaligned memory accesses. The following table lists the alignment and behavior values for -xmemalign.

Table B-30 The -xmemalign Alignment and Behavior Flags

a
b
1
Assume at most 1 byte alignment.
i
Interpret access and continue execution.
2
Assume at most 2 byte alignment.
s
Raise signal SIGBUS.
4
Assume at most 4 byte alignment.
f
For variants of -xarch=v9 only:

Raise signal SIGBUS for alignments less or equal to 4,otherwise interpret access and continue execution. For all other -xarch values, the f flag is equivalent to i.

8
Assume at most 8 byte alignment.
16
Assume at most 16 byte alignment

You must specify -xmemalign whenever you want to link to an object file that was compiled with the value of b set to either i or f. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

For memory accesses where the alignment is determinable at compile time, the compiler generates the appropriate load/store instruction sequence for that alignment of data.

For memory accesses where the alignment cannot be determined at compile time, the compiler must assume an alignment to generate the needed load/store sequence.

The -xmemalign option allows you to specify the maximum memory alignment of data to be assumed by the compiler in these indeterminable situations. It also specifies the error behavior to be followed at run time when a misaligned memory access does take place.

If actual data alignment at runtime is less than the specified alignment, the misaligned access attempt (a memory read or write) generates a trap. The two possible responses to the trap are

The following default values only apply when no -xmemalign option is present:

Here is the default when -xmemalign option is present but no value is given:

The following table shows how you can use -xmemalign to handle different alignment situations.

Table B-31 Examples of -xmemalign

Command
Situation
-xmemalign=1s
There are many misaligned accesses so trap handling is too slow.
-xmemalign=8i
There are occasional, intentional, misaligned accesses in code that is otherwise correct.
-xmemalign=8s
There should be no misaligned accesses in the program.
-xmemalign=2s
You want to check for possible odd-byte accesses.
-xmemalign=2i
You want to check for possible odd-byte access and you want the program to work.

B.2.117 -xmodel=[a]

(x86) The -xmodel option enables the compiler to modify the form of 64-bit objects for the Solaris x86 platforms and should only be specified for the compilation of such objects.

This option is valid only when -m64 is also specified on 64–bit enabled x64 processors.

a must be one of the following:

Table B-32 The -xmodel Flags

Value
Meaning
small
This option generates code for the small model in which the virtual address of code executed is known at link time and all symbols are known to be located in the virtual addresses in the range from 0 to 2^31 - 2^24 - 1.
kernel
Generates code for the kernel model in which all symbols are defined to be in the range from 2^64 - 2^31 to 2^64 - 2^24.
medium
Generates code for the medium model in which no assumptions are made about the range of symbolic references to data sections. Size and address of the text section have the same limits as the small code model. Applications with large amounts of static data might require -xmodel=medium when compiling with -m64.

This option is not cumulative so the compiler sets the model value according to the rightmost instance of -xmodel on the command-line.

If you do not specify -xmodel, the compiler assumes -xmodel=small. Specifying -xmodel without an argument is an error.

It is not necessary to compile all translation units with this option. You can compile select files as long as you ensure the object you are accessing is within reach.

Be aware that not all Linux system support the medium model.

B.2.118 -xnolib

Does not link any libraries by default; that is, no -l options are passed to ld(1). Normally, the cc driver passes -lc to ld.

When you use -xnolib, you have to pass all the -l options yourself.

B.2.119 -xnolibmil

Does not inline math library routines. Use it after the –fast option. For example:

% cc– fast– xnolibmil....

B.2.120 -xnolibmopt

Prevents the use of an optimized math library by the compiler by turning off any previously specified -xlibmopt option. Use this option after -fast which enables use of the optimized math library by setting -xlibmopt:

% cc -fast -xnolibmopt ...

B.2.121 -xnorunpath

Do not build a runtime search path for shared libraries into the executable.

Normally cc does not pass any -R path to the linker. There are a few options that do pass -R path to the linker such as -xliclib=sunperf and -xopenmp. The -xnorunpath option can be used to prevent this.

This option is recommended for building executables that will be shipped to customers who may have a different path for the shared libraries that are used by the program.

B.2.122 -xO[1|2|3|4|5]

Optimizes the object code; note the uppercase letter O followed by the digit 1, 2, 3, 4, or 5. Generally, the higher the level of optimization, the better the run-time performance. However, higher optimization levels can result in longer compilation time and larger executable files.

In a few cases,– xO2 might perform better than the others, and– xO3 might 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 and resumes subsequent procedures at the original level specified in the command-line option.

The default is no optimization. However, this is only possible if you do not specify an optimization level. If you specify an optimization level, there is no option for turning optimization off.

If you are trying to avoid setting an optimization level, be sure not to specify any option that implies an optimization level. For example, -fast is a macro option that sets optimization at -xO5. All other options that imply an optimization level give a warning message that optimization has been set. The only way to compile without any optimization is to delete all options from the command line or make file that specify an optimization level.

If you use -g and the optimization level is -xO3 or lower, the compiler provides best-effort symbolic information with almost full optimization. Tail-call optimization and back-end inlining are disabled.

If you use -g and the optimization level is -xO4 or higher, the compiler provides best-effort symbolic information with full optimization.

Debugging with -g does not suppress -xOn, but -xOn limits -g in certain ways. For example, the optimization options reduce the utility of debugging so that you cannot display variables from dbx, but you can still use the dbx where command to get a symbolic traceback. For more information, see “Debugging Optimized Code” in Chapter 1 of Debugging a Program With dbx.

If you specify both -xO and -xmaxopt, the optimization level set with -xO must not exceed the -xmaxopt value.

If you optimize at -xO3 or -xO4 with very large procedures (thousands of lines of code in the same procedure), the optimizer may require a large amount of virtual memory. In such cases, machine performance may degrade.

B.2.122.1 Explanation of SPARC Optimizations

The following table describes how they operate on the SPARC platform.

Table B-33 The -xO Flags on SPARC Platforms

Value
Meaning
-xO1
Does basic local optimization (peephole).
-xO2
Does basic local and global optimization. This is 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, and complex expression expansion.

The -xO2 level does not assign global, external, or indirect references or definitions to registers. It treats these references and definitions as if they were declared volatile. In general, the -xO2 level results in minimum code size.

-xO3
Performs like -xO2, but also optimizes references or definitions for external variables. Loop unrolling and software pipelining are also performed. This level does not trace the effects of pointer assignments. When compiling either device drivers, or programs that modify external variables from within signal handlers, you may need to use the volatile type qualifier to protect the object from optimization. In general, the -xO3 level results in increased code size.
-xO4
Performs like -xO3, but also automatically inlines functions contained in the same file; this usually improves execution speed. If you want to control which functions are inlined, see B.2.96 -xinline=list.

This level traces the effects of pointer assignments, and usually results in increased code size.

-xO5
Attempts to generate the highest level of optimization. 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 B.2.136 -xprofile=p.
B.2.122.2 Explanation of x86 Optimizations

The following table describes how the optimization levels work on the x86 platform.

Table B-34 The -xO Flags on x86 Platforms

Value
Meaning
-xO1
Preloads arguments from memory, cross-jumping (tail-merging), as well as the single pass of the default optimization.
-xO2
Schedules both high- and low-level instructions and performs improved spill analysis, loop memory-reference elimination, register lifetime analysis, enhanced register allocation, and elimination of global common subexpressions.
-xO3
Performs loop strength reduction, induction variable elimination, as well as the optimization done by level 2.
-xO4
Preforms automatic inlining of functions contained in the same file in addition to performing -xO3 optimizations. This automatic inlining usually improves execution speed, but sometimes makes it worse. In general, this level results in increased code size.
-xO5
Generates the highest level of optimization. Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Some of these include generating local calling convention entry points for exported functions, further optimizing spill code and adding analysis to improve instruction scheduling.

For more information on debugging, see the Solaris Studio: Debugging a Program With dbx manual. For more information on optimization, see the Solaris Studio 12: Performance Analyzer manual.

See also -xldscope and -xmaxopt.

B.2.123 -xopenmp[=i]

Use the -xopenmp option to enable explicit parallelization with OpenMP directives. To run a parallelized program in a multithreaded environment, you must set the OMP_NUM_THREADS environment variable prior to execution.

To enable nested parallelism, you must set the OMP_NESTED environment variable to TRUE. Nested parallelism is disabled by default.

The following table lists the values for i:

Table B-35 The -xopenmp Flags

Value
Meaning
parallel
Enables recognition of OpenMP pragmas. The optimization level under -xopenmp=parallel is -x03. The compiler changes the optimization level to-x03 if necessary and issues a warning.

This flag also defines the preprocessor token _OPENMP.

noopt
Enables recognition of OpenMP pragmas. The compiler does not raise the optimization level if it is lower than -O3.

If you explicitly set the optimization lower than -O3, as in cc -O2 -xopenmp=noopt, the compiler issues an error. If you do not specify an optimization level with -xopenmp=noopt, the OpenMP pragmas are recognized, the program is parallelized accordingly, but no optimization is done.

This flag also defines the preprocessor token _OPENMP.

none
This flag is the default and disables recognition of OpenMP pragmas, makes no change to the optimization level of your program, and does not predefine any preprocessor tokens.

If you specify -xopenmp, but do not include a value, the compiler assumes -xopenmp=parallel. If you do not specify -xopenmp, the compiler assumes -xopenmp=none.

If you are debugging an OpenMP program with dbx, compile with -g and -xopenmp=noopt so you can breakpoint within parallel regions and display the contents of variables.

The default for -xopenmp might change in future releases. You can avoid warning messages by explicitly specifying an appropriate optimization.

If you use -xopenmp while building any .so, you must use -xopenmp when linking the executable, and the compiler of the executable must not be any older than the compiler that built the .so with -xopenmp. This is especially important when you compile libraries that contain OpenMP directives. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

Make sure that the latest patch of the OpenMP runtime library, libmtsk.so, is installed on the system for best performance.

For more information that is specific to the C implementation of OpenMP, see 3.2 Parallelizing for OpenMP.

For information on OpenMP, see the Solaris Studio OpenMP API User's Guide.

B.2.124 -xP

The compiler performs only syntax and semantic checking on the source file in order to print prototypes for all K&R C functions. This option does not produce any object or executable code. For example, specifying -xP with the following source file,

f()
{
}

main(argc,argv)
int argc;
char *argv[];
{
}

produces this output:

int f(void);
int main(int, char **);

B.2.125 -xpagesize=n

Sets the preferred page size for the stack and the heap.

The following values are valid on SPARC: 4k, 8K, 64K, 512K, 2M, 4M, 32M, 256M, 2G, 16G, or default.

The following values are valid on x86: 4K, 2M. 4M, 1G, or default.

If you do not specify a valid page size, the request is silently ignored at run-time. You must specify a valid page size for the target platform.

Use the getpagesize(3C) command on the Solaris operating system to determine the number of bytes in a page. The Solaris operating system offers no guarantee that the page size request will be honored. You can use pmap(1) or meminfo(2) to determine page size of the target platform.

You can use pmap(1) or meminfo(2) to determine page size of the target platform.

The -xpagesize option has no effect unless you use it at compile time and at link time. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

If you specify -xpagesize=default, the Solaris operating system sets the page size.

Compiling with this option has the same effect as setting the LD_PRELOAD environment variable to mpss.so.1 with the equivalent options, or running the Solaris command ppgsz(1) with the equivalent options before running the program. See the Solaris man pages for details.

This option is a macro for -xpagesize_heap and -xpagesize_stack. These two options accept the same arguments as -xpagesize. You can set them both with the same value by specifying -xpagesize or you can specify them individually with different values.

B.2.126 -xpagesize_heap=n

Set the page size in memory for the heap.

This option accepts the same values as —xpagesize. If you do not specify a valid page size, the request is silently ignored at run-time.

Use the getpagesize(3C) command on the Solaris operating system to determine the number of bytes in a page. The Solaris operating system offers no guarantee that the page size request will be honored. You can use pmap(1) or meminfo(2) to determine page size of the target platform.

You can use pmap(1) or meminfo(2) to determine page size at the target platform.

If you specify -xpagesize_heap=default, the Solaris operating system sets the page size.

Compiling with this option has the same effect as setting the LD_PRELOAD environment variable to mpss.so.1 with the equivalent options, or running the Solaris command ppgsz(1) with the equivalent options before running the program. See the Solaris man pages for details.

The -xpagesize_heap option has no effect unless you use it at compile time and at link time. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

B.2.127 -xpagesize_stack=n

Set the page size in memory for the stack.

This option accepts the same values as —xpagesize. If you do not specify a valid page size, the request is silently ignored at run-time.

Use the getpagesize(3C) command on the Solaris operating system to determine the number of bytes in a page. The Solaris operating system offers no guarantee that the page size request will be honored. You can use pmap(1) or meminfo(2) to determine page size of the target platform.

If you specify -xpagesize_stack=default, the Solaris operating system sets the page size.

Compiling with this option has the same effect as setting the LD_PRELOAD environment variable to mpss.so.1 with the equivalent options, or running the Solaris command ppgsz(1) with the equivalent options before running the program. See the Solaris man pages for details.

The -xpagesize_stack option has no effect unless you use it at compile time and at link time. For a complete list of all compiler options that must be specified at both compile time and at link time, see Table A-2.

B.2.128 -xpch=v

This compiler option activates the precompiled-header feature. v can be auto, autofirst, collect:pch_filename, or use:pch_filename. You can take advantage of this feature through the -xpch (detailed in B.2.128 -xpch=v) and -xpchstop (detailed in B.2.129 -xpchstop=[file|<include>]) options in combination with the #pragma hdrstop directive (detailed under 2.11.8 hdrstop).

Use the -xpch option to create a precompiled-header file and improve your compilation time. The precompiled-header file is designed to reduce compile time for applications whose source files share a common set of include files containing a large amount of source code. A precompiled header works by collecting information about a sequence of header files from one source file, and then using that information when recompiling that source file, and when compiling other source files that have the same sequence of headers. The information that the compiler collects is stored in a precompiled-header file.

See Also:

B.2.128.1 Creating a Precompiled-Header File Automatically

You can let the compiler generate the precompiled- header file for you automatically. Choose between one of the following two ways to do this. One way is for the compiler to create the precompiled-header file from the first include file it finds in the source file. The other way is for the compiler to select from the set of include files found in the source file starting with the first include file and extending through a well- defined point that determines which include file is the last one. Use one of the following two flags to determine which method the compiler uses to automatically generate a precompiled header:

Table B-36 The -xpch Flags

Flag
Meaning
-xpch=auto
The contents of the precompiled-header file is based on the longest viable prefix (see the following section for an explanation of how a viable prefix is identified) that the compiler finds in the source file. This flag produces a precompiled header file that consists of the largest possible number of header files.
-xpch=autofirst
This flag produces a precompiled-header file that contains only the first header found in the source file.
B.2.128.2 Creating a Precompiled-Header File Manually

If you decide to create your precompiled-header file manually, you must start by first using -xpch, and specifying the collect mode. The compilation command that specifies -xpch=collect must only specify one source file. In the following example, the -xpch option creates a precompiled-header file called myheader.cpch based on the source file a.c:

cc -xpch=collect:myheader a.c

A valid precompiled-header filename always has the suffix .cpch. When you specify pch_filename, you can add the suffix or let the compiler add it for you. For example, if you specify cc -xpch=collect:foo a.c, the precompiled-header file is called foo.cpch.

B.2.128.3 How the Compiler Handles an Existing Precompiled-Header File

If the compiler cannot use the precompiled-header file, under -xpch=auto and -xpch=autofirst, it generates a new precompiled-header file. If the compiler cannot use the precompiled-header file under -xpch=use, a warning is issued and the compilation is done using the real headers.

B.2.128.4 Directing the Compiler to Use a Specific Precompiled-Header File

You can also direct the compiler to use a specific precompiled header. Specify -xpch=use:pch_filename to do this. You can specify any number of source files with the same sequence of include files as the source file that was used to create the precompiled-header file. For example, your command in use mode could look like this: cc -xpch=use:foo.cpch foo.c bar.c foobar.c.

You should only use an existing precompiled-header file if the following are true. If any of the following is not true, you should recreate the precompiled-header file:

B.2.128.5 The Viable Prefix

In order to share a precompiled-header file across multiple source files, those source files must share a common set of include files as their initial sequence of tokens. A token is a keyword, name or punctuation mark. Comments and code that is excluded by #if directives are not recognized by the compiler as tokens. This initial sequence of tokens is known as the viable prefix. In other words, the viable prefix is the top portion of the source file that is common to all source files. The compiler uses this viable prefix as the basis for creating a precompiled-header file and thereby determining which header files from the source are pre-compiled.

The viable prefix that the compiler finds during the current compilation must match the viable prefix that it used to create the precompiled-header file. In other words, a viable prefix must be interpreted consistently across all the source files that use the same precompiled-header file.

The viable prefix of a source file can only be comprised of comments and any of the following pre-processor directives:

#include
#if/ifdef/ifndef/else/elif/endif
#define/undef
#ident (if identical, passed through as is)
#pragma (if identical)

Any of these may reference macros. The #else, #elif, and #endif directives must match within the viable prefix. Comments are ignored.

The compiler determines the end point of the viable prefix automatically when you specify -xpch=auto or -xpch=autofirst and is defined as follows.

For -xpch=collect or -xpch=use, the viable prefix ends with a #pragma hdrstop.

Within the viable prefix of each file that shares a precompiled-header file, each corresponding #define and #undef directive must reference the same symbol (in the case of #define, each one must reference the same value). Their order of appearance within each viable prefix must be the same as well. Each corresponding pragma must also be the same and appear in the same order across all the files sharing a precompiled header.

B.2.128.6 Screening a Header File for Problems

What makes a header file precompilable? A header file is precompilable when it is interpreted consistently across different source files. Specifically, when it contains only complete declarations. That is, a declaration in any one file must stand alone as a valid declaration. Incomplete type declarations, such as struct S;, are valid declarations. The complete type declaration can appear in some other file. Consider these example header files:

file a.h
struct S {
#include "x.h" /* not allowed */
};

file b.h
struct T; // ok, complete declaration
struct S {
   int i;
[end of file, continued in another file] /* not allowed*/

A header file that is incorporated into a precompiled-header file must not violate the following. The results of compiling a program that violates any of these constraints is undefined.

A header is also precompilable if it contains variable and function definitions. as well.

B.2.128.7 The Precompiled-Header File Cache

When the compiler creates a precompiled-header file automatically, the compiler writes it to the SunWS_cache directory. This directory always resides in the location where the object file is created. Updates to the file are preformed under a lock so that it works properly under dmake.

If you need to force the compiler to rebuild automatically-generated precompiled-header files, you can clear the precompiled-header file cache-directory with the CCadmin tool. See the CCadmin(1) man page for more information.

B.2.128.8 Warnings
B.2.128.9 Precompiled-Header File Dependencies and make Files

The compiler generates dependency information for precompiled-header files when you specify -xpch=collect. You need to create the appropriate rules in your make files to take advantage of these dependencies. Consider this sample make file:

%.o : %.c shared.cpch
         $(CC) -xpch=use:shared -xpchstop=foo.h -c $<
default : a.out

foo.o + shared.cpch : foo.c
         $(CC) -xpch=collect:shared -xpchstop=foo.h foo.c -c

a.out : foo.o bar.o foobar.o
         $(CC) foo.o bar.o foobar.o

clean :
         rm -f *.o shared.cpch .make.state a.out

These make rules, along with the dependencies generated by the compiler, force a manually created precompiled- header file to be recreated if any source file you used with -xpch=collect, or any of the headers that are part of the precompiled-header file, have changed. This prevents the use of an out of date precompiled-header file.

You do not have to create any additional make rules in your makefiles for -xpch=auto or -xpch=autofirst.

B.2.129 -xpchstop=[file|<include>]

Use the -xpchstop=file option to specify the last include file of the viable prefix for the precompiled-header file. Using -xpchstop on the command line is equivalent to placing a hdrstop pragma after the first include-directive that references file in each of the source files that you specify with the cc command.

Use -xpchstop=<include> with -xpch-auto to create a precompiled-header file that is based on header files up through and including <include>. This flag overrides the default -xpch=auto behavior of using all header files that are contained in the entire viable prefix.

In the following example, the -xpchstop option specifies that the viable prefix for the precompiled-header file ends with the include of projectheader.h. Therefore, privateheader.h is not a part of the viable prefix.

example% cat a.c
     #include <stdio.h>
     #include <strings.h>
     #include "projectheader.h"
     #include "privateheader.h"
     .
     .
     .
example% cc -xpch=collect:foo.cpch a.c -xpchstop=projectheader.h -c

See also -xpch.

B.2.130 -xpec[={yes|no}]

Generates a Portable Executable Code (PEC) binary. PEC binaries can be used with the Automatic Tuning System (ATS) which works by rebuilding the compiled PEC binary for tuning and troubleshooting - the original source code is not required. More information about the ATS is available at http://www.opensparc.net/sunsource/cooltools/www/ats/.

A binary that is built with -xpec is usually five to ten times larger than if it is built without -xpec.

If you do not specify -xpec, the compiler sets it to -xpec=no. If you specify -xpec, but do not supply a flag, the compiler sets it to -xpec=yes.

B.2.131 -xpentium

(x86) Generates code for the Pentium processor.

B.2.132 -xpg

Prepares the object code to collect data for profiling with gprof(1). It invokes a runtime recording mechanism that produces a gmon.out file at normal termination.


Note - There is no advantage for -xprofile if you specify -xpg. The two do not prepare or use data provided by the other.


Profiles are generated by using prof(1) or gprof(1) on 64 bit Solaris platforms or just gprof on 32 bit Solaris platforms and include approximate user CPU times. These times are derived from PC sample data (see pcsample(2)) for routines in the main executable and routines in shared libraries specified as linker arguments when the executable is linked. Other shared libraries (libraries opened after process startup using dlopen(3DL)) are not profiled.

On 32 bit Solaris systems, profiles generated using prof(1) are limited to routines in the executable. 32 bit shared libraries can be profiled by linking the executable with -xpg and using gprof(1).

On x86 systems, -xpg is incompatible with -xregs=frameptr, and these two options should not be used together. Note also that -xregs=frameptr is included in -fast.

The Solaris 10 software does not include system libraries compiled with -p. As a result, profiles collected on Solaris 10 platforms do not include call counts for system library routines.

If you specify -xpg at compile time, you must also specify it at link time. See A.1.2 Compile-Time and Link-Time Options for a complete list of options that must be specified at both compile time and link time.

B.2.133 -xprefetch[=val[,val]]

Enable prefetch instructions on those architectures that support prefetch.

Explicit prefetching should only be used under special circumstances that are supported by measurements.

val must be one of the following:

Table B-37 The -xprefetch Flags

Flag
Meaning
latx:factor
Adjust the compiler’s assumed prefetch-to-load and prefetch-to-store latencies by the specified factor. You can only combine this flag with -xprefetch=auto. See B.2.133.1 Prefetch Latency Ratio
[no%]auto
[Disable] Enable automatic generation of prefetch instructions
[no%]explicit
[Disable] Enable explicit prefetch macros
yes
Obsolete - do not use. Use -xprefetch=auto,explicit instead.
no
Obsolete - do not use. Use -xprefetch=no%auto,no%explicit instead.

The default is -xprefetch=auto,explicit. This default adversely affects applications that have essentially non-linear memory access patterns. Specify -xprefetch=no%auto,no%explicit to override the default.

The sun_prefetch.h header file provides the macros that you can use to specify explicit prefetch instructions. The prefetches are approximately at the place in the executable that corresponds to where the macros appear.

B.2.133.1 Prefetch Latency Ratio

The prefetch latency is the hardware delay between the execution of a prefetch instruction and the time the data being prefetched is available in the cache.

The factor must be a positive number of the form n.n.

The compiler assumes a prefetch latency value when determining how far apart to place a prefetch instruction and the load or store instruction that uses the prefetched data. The assumed latency between a prefetch and a load may not be the same as the assumed latency between a prefetch and a store.

The compiler tunes the prefetch mechanism for optimal performance across a wide range of machines and applications. This tuning may not always be optimal. For memory-intensive applications, especially applications intended to run on large multiprocessors, you may be able to obtain better performance by increasing the prefetch latency values. To increase the values, use a factor that is greater than 1 (one). A value between .5 and 2.0 will most likely pro vide the maximum performance.

For applications with data sets that reside entirely within the external cache, you may be able to obtain better performance by decreasing the prefetch latency values. To decrease the values, use a factor that is less than one.

To use the latx:factor suboption, start with a factor value near 1.0 and run performance tests against the application. Then increase or decrease the factor, as appropriate, and run the performance tests again. Continue adjusting the factor and running the performance tests until you achieve optimum performance. When you increase or decrease the factor in small steps, you will see no performance difference for a few steps, then a sudden difference, then it will level off again.

B.2.134 -xprefetch_auto_type=a

Where a is [no%]indirect_array_access.

Use this option to determine whether or not the compiler generates indirect prefetches for the loops indicated by the option -xprefetch_level in the same fashion the prefetches for direct memory accesses are generated.

If you do not specify a setting for -xprefetch_auto_type, the compiler sets it to -xprefetch_auto_type=no%indirect_array_access.

Options such as -xalias_level can affect the aggressiveness of computing the indirect prefetch candidates and therefore the aggressiveness of the automatic indirect prefetch insertion due to better memory alias disambiguation information.

B.2.135 -xprefetch_level=l

Use the -xprefetch_level option to control the aggressiveness of automatic insertion of prefetch instructions as determined with -xprefetch=auto. l must be 1, 2, or 3. The compiler becomes more aggressive, or in other words, introduces more prefetches with each, higher, level of -xprefetch_level.

The appropriate value for the -xprefetch_level depends on the number of cache misses the application may have. Higher -xprefetch_level values have the potential to improve the performance of applications.

This option is effective only when it is compiled with -xprefetch=auto, with optimization level 3 or greater, and generate code for a platform that supports prefetch (v8plus, v8plusa, v9, v9a, v9b, generic64, native64).

-xprefetch_level=1 enables automatic generation of prefetch instructions. -xprefetch_level=2 enables additional generation beyond level 1 and -xprefetch_level=3 enables additional generation beyond level 2.

The default is -xprefetch_level=1 when you specify -xprefetch=auto.

B.2.136 –xprofile=p

Collects data for a profile or uses a profile to optimize.

p must be collect[:profdir], use[:profdir], or tcov[:profdir].

This option causes execution frequency data to be collected and saved during execution, then the data can be used in subsequent runs to improve performance. Profile collection is safe for multithreaded applications. That is, profiling a program that does its own multitasking ( -mt ) produces accurate results. This option is only valid when you specify -xO2 or greater level of optimization. If compilation and linking are performed in separate steps, the same -xprofile option must appear on the link step as well as the compile step.

collect[:profdir]

Collects and saves execution frequency for later use by the optimizer with -xprofile=use. The compiler generates code to measure statement execution-frequency.

-xMerge, -ztext, and -xprofile=collect should not be used together. While -xMerge forces statically initialized data into read-only storage, -ztext prohibits position-dependent symbol relocations in read-only storage, and -xprofile=collect generates statically initialized, position-dependent symbol relocations in writable storage.

The profile directory name profdir, if specified, is the pathname of the directory where profile data are to be stored when a program or shared library containing the profiled object code is executed. If the profdir pathname is not absolute, it is interpreted relative to the current working directory when the program is compiled with the option -xprofile=use:profdir. If no profile directory name is specified, profile data are stored in a directory named program.profile where program is the basename of the profiled process's main program.

Example[1]: to collect and use profile data in the directory myprof.profile located in the same directory where the program is built:

demo: cc -xprofile=collect:myprof.profile -xO5 prog.c -o prog  
demo: ./prog        
demo: cc -xprofile=use:myprof.profile -xO5 prog.c -o prog

Example[2]: to collect profile data in the directory /bench/myprof.profile and later use the collected profile data in a feedback compilation at optimization level -xO5:

demo: cc -xprofile=collect:/bench/myprof.profile \ -xO5 prog.c -o prog  
...run prog from multiple locations..
demo: cc -xprofile=use:/bench/myprof.profile \ -xO5 prog.c -o prog

You can set the environment variables SUN_PROFDATA and SUN_PROFDATA_DIR to control where a program compiled with -xprofile=collect stores the profile data. If set, the -xprofile=collect data is written to $SUN_PROFDATA_DIR/$SUN_PROFDATA.

These environment variables similarly control the path and names of the profile data files written by tcov , as described in the tcov(1) man page. If these environment variables are not set, the profile data is written to the directory profdir.profile in the current directory, where profdir is the name of the executable or the name specified in the -xprofile=collect:profdir flag. -xprofile does not append .profile to profdir if profdir already ends in .profile. If you run the program several times, the execution frequency data accumulates in the profdir.profile directory; that is output from prior executions is not lost.

If you are compiling and linking in separate steps, make sure that any object files compiled with -xprofile=collect are also linked with -xprofile=collect.

use[:profdir]

Uses execution frequency data collected from code compiled with -xprofile=collect[:profdir] to optimize for the work performed when the profiled code was executed. profdir is the pathname of a directory containing profile data collected by running a program that was compiled with -xprofile=collect[:profdir].

The profdir pathname is optional. If profdir is not specified, the name of the executible binary is used. a.out is used if -o is not specified. The compiler looks for profdir.profile/feedback, or a.out.profile/feedback when profdir is not specified. For example:

demo: cc -xprofile=collect -o myexe prog.c          
demo: cc -xprofile=use:myexe -xO5 -o myexe prog.c

The program is optimized by using the execution frequency data previously generated and saved in the feedback files written by a previous execution of the program compiled with -xprofile=collect.

Except for the -xprofile option, the source files and other compiler options must be exactly the same as those used for the compilation that created the compiled program that generated the feedback file. The same version of the compiler must be used for both the collect build and the use build as well.

If compiled with -xprofile=collect:profdir, the same profile directory name profdir must be used in the optimizing compilation: -xprofile=use:profdir.

See also -xprofile_ircache for speeding up compilation between collect and use phases.

tcov[:profdir]

Instrument object files for basic block coverage analysis using tcov(1).

If the optional profdir argument is specified, the compiler will create a profile directory at the specified location The data stored in the profile directory can be used either by tcov(1) or by the compiler with -xprofile=use:profdir. If the optional profdir pathname is omitted, a profile directory will be created when the profiled program is executed. The data stored in the profile directory can only be used by tcov(1). The location of the profile directory can be controlled using environment variables SUN_PROFDATA and SUN_PROFDATA_DIR.

If the location specified by profdir is not an absolute pathname, it is interpreted at compilation time relative to the directory in which the current object file is to be written. If profdir is specified for any object file, the same location must be specified for all object files in the same program. The directory whose location is specified by profdir must be accessible from all machines where the profiled program is to be executed. The profile directory should not be deleted until its contents are no longer needed, because data stored there by the compiler cannot be restored except by recompilation.

Example [1]: if object files for one or more programs are compiled with -xprofile=tcov:/test/profdata, a directory named /test/profdata.profile will be created by the compiler and used to store data describing the profiled object files. The same directory will also be used at execution time to store execution data associated with the profiled object files.

Example [2]: if a program named myprog is compiled with -xprofile=tcov and executed in the directory /home/joe, the directory /home/joe/myprog.profile will be created at run time and used to store runtime profile data.

B.2.137 -xprofile_ircache[=path]

(SPARC) Use -xprofile_ircache[=path] with -xprofile=collect|use to improve compilation time during the use phase by reusing compilation data saved from the collect phase.

With large programs, compilation time in the use phase can improve significantly because the intermediate data is saved. Note that the saved data could increase disk space requirements considerably.

When you use -xprofile_ircache[=path], path overrides the location where the cached files are saved. By default, these files are saved in the same directory as the object file. Specifying a path is useful when the collect and use phases happen in two different directories. Here’s a typical sequence of commands:

example% cc -xO5 -xprofile=collect -xprofile_ircache t1.c t2.c
example% a.out    // run collects feedback data
example% cc -xO5 -xprofile=use -xprofile_ircache t1.c t2.c

B.2.138 -xprofile_pathmap

(SPARC) Use the -xprofile_pathmap=collect_prefix:use_prefix option when you are also specifying the -xprofile=use command. Use -xprofile_pathmap when both of the following are true and the compiler is unable to find profile data for an object file that is compiled with -xprofile=use.

The collect-prefix is the prefix of the UNIX pathname of a directory tree in which object files were compiled using -xprofile=collect.

The use-prefix is the prefix of the UNIX pathname of a directory tree in which object files are to be compiled using -xprofile=use.

If you specify multiple instances of -xprofile_pathmap, the compiler processes them in the order of their occurrence. Each use-prefix specified by an instance of -xprofile_pathmap is compared with the object file pathname until either a matching use-prefix is identified or the last specified use-prefix is found not to match the object file pathname.

B.2.139 -xreduction

Turns on reduction recognition during automatic parallelization. -xreduction must be specified with -xautopar, otherwise the compiler issues a warning.

When reduction recognition is enabled, the compiler parallelizes reductions such as dot products, maximum and minimum finding. These reductions yield different roundoffs than obtained by unparallelized code.

B.2.140 -xregs=r[,r…]

Specifies the usage of registers for the generated code.

r is a comma-separated list that consists of one or more of the following suboptions: appl, float,frameptr.

Prefixing a suboption with no% disables that suboption.

Note that —xregs suboptions are restricted to specific hardware platforms.

Example: -xregs=appl,no%float

Table B-38 The -xregs Suboptions

Value
Meaning
appl
(SPARC) Allow the compiler to generate code using the application registers as scratch registers. The application registers are:

g2, g3, g4 (on 32–bit platforms)

g2, g3 (on 64–bit platforms)

It is strongly recommended that all system software and libraries be compiled using -xregs=no%appl. System software (including shared libraries) must preserve these registers’ values for the application. Their use is intended to be controlled by the compilation system and must be consistent throughout the application.

In the SPARC ABI, these registers are described as application registers. Using these registers can improve performance because fewer load and store instructions are needed. However, such use can conflict with some old library programs written in assembly code.

float
(SPARC) Allow the compiler to generate code by using the floating-point registers as scratch registers for integer values. Use of floating-point values may use these registers regardless of this option. If you want your code to be free of all references to floating point registers, you need to use -xregs=no%float and also make sure your code does not in any way use floating point types.
frameptr
(x86) Allow the compiler to use the frame-pointer register (%ebp on IA32, %rbp on AMD64) as a general-purpose register.

The default is -xregs=no%frameptr

The C++ compiler ignores —xregs=frameptr unless exceptions are also disabled with —features=no%except. Note that —xregs=frameptr is part of —fast, but is ignored by the C++ compiler unless —features=no%except is also specified.

With -xregs=framptr the compiler is free to use the frame-pointer register to improve program performance. However, some features of the debugger and performance measurement tools may be limited as a result. Stack tracing, debuggers, and performance anayzers cannot report on functions compiled with —xregs=frameptr

Also, C++ calls to Posix pthread_cancel() will fail to find cleanup handers.

Mixed C, Fortran, and C++ code should not be compiled with —xregs=frameptr if a C++ function, called directly or indirectly from a C or Fortran function, can throw an exception. If compiling such mixed source code with —fast, add —xregs=no%frameptr after the —fast option on the command line.

With more available registers on 64–bit platforms, compiling with —xregs=frameptr has a better chance of im proving 32–bit code performance than 64–bit code.

The compiler ignores -xregs=frameptr and issues a warning if you also specify -xpg.

The SPARC default is -xregs=appl,float.

The x86 default is -xregs=no%frameptr.

On x86 systems, -xpg is incompatible with -xregs=frameptr, and these two options should not be used together. Note also that -xregs=frameptr is included in -fast.

It is strongly recommended that you compile code intended for shared libraries that will link with applications, with -xregs=no%appl,float. At the very least, the shared library should explicitly document how it uses the application registers so that applications linking with those libraries are aware of these register assignments.

For example, an application using the registers in some global sense (such as using a register to point to some critical data structure) would need to know exactly how a library with code compiled without -xregs=no%appl is using the application registers in order to safely link with that library.

B.2.141 -xrestrict[=f]

Treats pointer-valued function parameters as restricted pointers . f is %all, %none, or a comma-separated list of one or more function names: {%all|%none|fn[,fn...]}.

If a function list is specified with this option, pointer parameters in the specified functions are treated as restricted; if -xrestrict=%all is specified, all pointer parameters in the entire C file are treated as restricted. Refer to 3.8.2 Restricted Pointers, for more information.

This command-line option can be used on its own, but it is best used with optimization. For example, the command:

%cc -xO3 -xrestrict=%all prog.c

treats all pointer parameters in the file prog.c as restricted pointers. The command:

%cc -xO3 -xrestrict=agc prog.c

treats all pointer parameters in the function agc in the file prog.c as restricted pointers.

The default is %none; specifying -xrestrict is equivalent to specifying -xrestrict=%all.

B.2.142 -xs

Allows debugging by dbx without object files.

This option causes all the debug information to be copied into the executable. This has little impact on dbx performance or the run-time performance of the program, but it does take more disk space.

B.2.143 -xsafe=mem

(SPARC) Allows the compiler to assume no memory protection violations occur.

This option grants permission to use non-faulting load instruction on the SPARC V9 architecture.


Note - Because non-faulting loads do not cause a trap when a fault such as address misalignment or segmentation violation occurs, you should use this option only for programs in which such faults cannot occur. Because few programs incur memory-based traps, you can safely use this option for most programs. Do not use this option for programs that explicitly depend on memory-based traps to handle exceptional conditions.


This option takes effect only when used with optimization level -xO5 and one of the following -xarch values: sparc, sparcvis, sparcvis2, or sparcvis3 for both -m32 and -m64.

B.2.144 -xsb

Obsolete — do not use. The source browser functionality is no longer supported.

B.2.145 -xsbfast

Obsolete — do not use. The source browser functionality is no longer supported.

B.2.146 -xsfpconst

Represents unsuffixed floating-point constants as single precision, instead of the default mode of double precision. Not valid with -Xc.

B.2.147 -xspace

Does no optimizations or parallelization of loops that increase code size.

Example: The compiler will not unroll loops or parallelize loops if it increases code size.

B.2.148 -xstrconst

This option is deprecated and might be removed in a future release. —xstrconst is an alias for —features=conststrings.

B.2.149 -xtarget=t

Specifies the target system for instruction set and optimization.

The value of t must be one of the following: native, generic, native64, generic64, system-name.

Each specific value for -xtarget expands into a specific set of values for the -xarch, -xchip, and -xcache options. Use the -xdryrun option to determine the expansion of -xtarget=native on a running system.

For example, -xtarget=sun4/15 is equivalent to: -xarch=v8a -xchip=micro -xcache=2/16/1.


Note - The expansion of -xtarget for a specific host platform might not expand to the same -xarch, -xchip, or -xcache settings as -xtarget=native when compiling on that platform.


Table B-39 -xtarget Values for All Platforms

Flag
Meaning
native
Gets the best performance on the host system.

The compiler generates code for the best performance on the host system. It determines the available architecture, chip, and cache properties of the machine on which the compiler is running.

native64
Gets the best performance for 64-bit object binaries on the host system. The compiler generates 64-bit object binaries optimized for the host system. It determines the available 64-bit architecture, chip, and cache properties of the machine on which the compiler is running.
generic
This is the default value. Gets the best performance for generic architecture, chip, and cache.
generic64
Sets the parameters for the best performance of 64-bit object binaries over most 64-bit platform architectures.
system-name
Gets the best performance for the specified system.

Select a system name from the following lists for which represents the actual system you are targeting.

The performance of some programs may 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.

B.2.149.1 -xtarget Values on SPARC Platforms

Compiling for 64-bit Solaris software on SPARC or UltraSPARC V9 is indicated by the -m64 option. If you specify -xtarget with a flag other than native64 or generic64, you must also specify the -m64 option as follows: -xtarget=ultra... -m64 otherwise the compiler uses a 32-bit memory model.

Table B-40 The -xtarget Expansions on SPARC

-xtarget=
-xarch
-xchip
-xcache
generic
generic
generic
generic
ultra
v8plusa
ultra
16/32/1:512/64/1
ultra1/140
v8plusa
ultra
16/32/1:512/64/1
ultra1/170
v8plusa
ultra
16/32/1:512/64/1
ultra1/200
v8plusa
ultra
16/32/1:512/64/1
ultra2
v8plusa
ultra2
16/32/1:512/64/1
ultra2/1170
v8plusa
ultra
16/32/1:512/64/1
ultra2/1200
v8plusa
ultra
16/32/1:1024/64/1
ultra2/1300
v8plusa
ultra2
16/32/1:2048/64/1
ultra2/2170
v8plusa
ultra
16/32/1:512/64/1
ultra2/2200
v8plusa
ultra
16/32/1:1024/64/1
ultra2/2300
v8plusa
ultra2
16/32/1:2048/64/1
ultra2e
v8plusa
ultra2e
16/32/1:256/64/4
ultra2i
v8plusa
ultra2i
16/32/1:512/64/1
ultra3
sparcvis2
ultra3
64/32/4:8192/512/1
ultra3cu
sparcvis2
ultra3cu
64/32/4:8192/512/2
ultra3i
sparcvis2
ultra3i
64/32/4:1024/64/4
ultra4
sparcvis2
ultra4
64/32/4:8192/128/2
ultra4plus
sparcvis2
ultra4plus
64/32/4:2048/64/4/2:32768/64/4
ultraT1
sparc
ultraT1
8/16/4/4:3072/64/12/32
ultraT2
sparcvis2
ultraT2
8/16/4:4096/64/16
ultraT2plus
sparcvis2
ultraT2plus
8/16/4:4096/64/16
ultraT3
sparcvis3
ultraT3
8/16/4:6144/64/24
sparc64vi
sparcfmaf
sparc64vi
128/64/2:5120/64/10
sparc64vii
sparcima
sparc64vii
64/64/2:5120/256/10
See B.2.80 -xcache[=c] for more information on the cache properties of the UltraSPARC IVplus, UltraSPARC T1, and UltraSPARC T2 chips.
B.2.149.2 -xtarget Values on x86 Platforms

Compiling for 64-bit Solaris software on 64-bit x86 platforms is indicated by the -m64 option. If you specify -xtarget with a flag other than native64 or generic64, you must also specify the -m64 option as follows: -xtarget=opteron ... -m64 otherwise the compiler uses a 32-bit memory model.

Table B-41 The -xtarget Expansions on x86

-xtarget=
-xarch
-xchip
-xcache
generic
generic
generic
generic
opteron
sse2a
opteron
64/64/2:1024/64/16
pentium
386
pentium
generic
pentium_pro
pentium_pro
pentium_pro
generic
pentium3
sse
pentium3
16/32/4:256/32/4
pentium4
sse2
pentium4
8/64/4:256/128/8
nehalem
sse4_2
nehalem
32/64/8:256/64/8:8192/64/16
penryn
sse4_1
penryn
2/64/8:6144/64/24
woodcrest
ssse3
core2
32/64/8:4096/64/16
barcelona
amdsse4a
amdfam10
64/64/2:512/64/16

B.2.150 -xtemp=dir

Sets the directory for temporary files used by cc to dir. No space is allowed within this option string. Without this option, temporary files go into /tmp. -xtemp has precedence over the TMPDIR environment variable.

B.2.151 -xthreadvar[=o]

Specify -xthreadvar to control the implementation of thread local variables. Use this option in conjunction with the __thread declaration specifier to take advantage of the compiler’s thread-local storage facility. After you declare the thread variables with the __thread specifier, specify -xthreadvar to enable the use of thread-local storage with position dependent code (non-PIC code) in dynamic (shared) libraries. For more information on how to use __thread, see 2.3 Thread Local Storage Specifier.

o must be one the following:

Table B-42 The -xthreadvar Flags

Flag
Meaning
[no%]dynamic
[[Do not] Compile variables for dynamic loading. Access to thread variables is significantly faster when -xthreadvar=no%dynamic but you cannot use the object file within a dynamic library. That is, you can only use the object file in an executable file.

If you do not specify -xthreadvar, the default used by the compiler depends upon whether or not position-independent code is enabled. If position-independent code is enabled, the option is set to -xthreadvar=dynamic. If position-independent code is disabled, the option is set to -xthreadvar=no%dynamic.

If you specify -xthreadvar, but do not specify any values, the option is set to -xthreadvar=dynamic.

If there is non-position-independent code within a dynamic library, you must specify -xthreadvar.

The linker cannot support the thread-variable equivalent of non-PIC code in dynamic libraries. Non-PIC thread variables are significantly faster, and hence should be the default for executables.

Using thread variables on different versions of Solaris software requires different options on the command line.

See Also: -xcode, -KPIC, -Kpic

B.2.152 -xtime

Reports the time and resources used by each compilation component.

B.2.153 -xtransition

Issues warnings for the differences between K&R C and Solaris Studio ISO C.

The -xtransition option issues warnings in conjunction with the -Xa and -Xt options. You can eliminate all warning messages about differing behavior through appropriate coding. The following warnings no longer appear unless you issue the -xtransition option:

B.2.154 -xtrigraphs

The -xtrigraphs option determines whether the compiler recognizes trigraph sequences as defined by the ISO C standard.

By default, the compiler assumes -xtrigraphs=yes and recognizes all trigraph sequences throughout the compilation unit.

If your source code has a literal string containing question marks (?) that the compiler is interpreting as a trigraph sequence, you can use the -xtrigraph=no suboption to turn off the recognition of trigraph sequences. The -xtrigraphs=no option turns off recognition of all trigraphs throughout the entire compilation unit.

Consider the following example source file named trigraphs_demo.c.

#include <stdio.h>

int main ()
{

  (void) printf("(\?\?) in a string appears as (??)\n");

  return 0;
}

Here is the output if you compile this code with -xtrigraphs=yes.

example% cc -xtrigraphs=yes trigraphs_demo.c
example% a.out
(??) in a string appears as (]

Here is the output if you compile this code with -xtrigraphs=no.

example% cc -xtrigraphs=no trigraphs_demo.c
example% a.out
(??) in a string appears as (??)

B.2.155 -xunroll=n

Suggests to the optimizer to unroll loops n times. n is a positive integer. When n is 1, it is a command, and the compiler unrolls no loops. When n is greater than 1, the -xunroll=n merely suggests to the compiler that it unroll loops n times.

B.2.156 -xustr={ascii_utf16_ushort|no}

Use this option if you need to support an internationalized application that uses ISO10646 UTF-16 string literals. In other words, use this option if your code contains a string literal that you want the compiler to convert to UTF-16 strings in the object file. Without this option, the compiler neither produces nor recognizes sixteen-bit character string literals. This option enables recognition of the U"ASCII_string" string literals as an array of type unsigned short int. Since such strings are not yet part of any standard, this option enables recognition of non-standard C.

You can turn off compiler recognition of U”ASCII_string” string literals by specifying -xustr=no. The right-most instance of this option on the command line overrides all previous instances.

The default is -xustr=no. If you specify -xustr without an argument, the compiler won’t accept it and instead issues a warning. The default can change if the C or C++ standards define a meaning for the syntax.

It is not an error to specify -xustr=ascii_utf16_ushort without also specifying a U"ASCII_string" string literals.

Not all files have to be compiled with this option.

The following example shows a string literal in quotes that is prepended by U. It also shows a command line that specifies -xustr.

example% cat file.c
const unsigned short *foo = U"foo";
const unsigned short bar[] = U"bar";
const unsigned short *fun() { return foo;}
example% cc -xustr=ascii_utf16_ushort file.c -c

An 8-bit character literal can be prepended with U to form a 16-bit UTF-16 character of type unsigned short. Examples:

const unsigned short x = U'x';    
const unsigned short y = U'\x79';

B.2.157 -xvector[=a]

Enable automatic generation of calls to the vector library functions and/or the generation of the SIMD (Single Instruction Multiple Data) instructions. You must use default rounding mode by specifying -fround=nearest when you use this option.

a is the equivalent of the following:

Table B-43 The -xvector Flags

Value
Meaning
[no%]lib
Does [not] enable the compiler to transform math library calls within loops into single calls to the equivalent vector math routines when such transformations are possible. This could result in a performance improvement for loops with large loop counts. (Solaris only)
[no%]simd
Does [not]direct the compiler to use the native x86 SSE SIMD instructions to improve performance of certain loops. Streaming extensions are used on x86 by default at optimization level 3 and above where beneficial. The suboption no%simd can be used to disable it.

The compiler will use SIMD only if streaming extensions exist in the target architecture; that is, if target ISA is at least SSE2. For example, you can specify -xtarget=woodcrest, —xarch=generic64, -xarch=sse2, -xarch=sse3, or -fast on a modern platform to use it. If the target ISA has no streaming extensions, the suboption will have no effect.

yes
This is deprecated, specify -xvector=lib instead.
no
This is deprecated, specify -xvector=none instead.

The default is -xvector=simd on x86 and -xvector=%none on SPARC platforms. If you specify -xvector without a suboption, the compiler assumes -xvector=simd,lib on x86, -xvector=lib on SPARC (Solaris), and -xvector=simd (Linux).

The -xvector option requires optimization level -xO3 or greater. Compilation will not proceed if the optimization level is unspecified or lower than -xO3, and a message is issued.

B.2.158 -xvis

(SPARC) Use the -xvis=[yes|no] command when you are using the assembly-language templates defined in the VIS[tm] instruction-set Software Developers Kit (VSDK). The default is -xvis=no. Specifying -xvis is equivalent to specifying -xvis=yes.

The VIS instruction set is an extension to the SPARC v9 instruction set. Even though the UltraSPARC processors are 64-bit, there are many cases, especially in multimedia applications, when the data are limited to eight or 16 bits in size. The VIS instructions can process four 16-bit data with one instruction so they greatly improve the performance of applications that handle new media such as imaging, linear algebra, signal processing, audio, video and networking.

For more information on the VSDK, see http://www.sun.com/processors/vis/.

B.2.159 -xvpara

Issues warnings about potential parallel-programming related problems that may cause incorrect results when using OpenMP. Use with -xopenmp and OpenMP API directives.

The compiler issues warnings when it detects the following situations:

No warnings appear if all parallelization directives are processed without problems.

Example:

cc -xopenmp -vpara any.c

Note - Solaris Studio compilers support OpenMP 2.5 API parallelization. Consequently, the MP pragmas directives are deprecated and are no longer supported. See the OpenMP API User’s Guide for information on migrating to the OpenMP API.


B.2.160 -Yc, dir

Specifies a new directory dir for the location of component c. c can consist of any of the characters representing components that are listed under the -W option.

If the location of a component is specified, then the new path name for the tool is dir/tool. If more than one -Y option is applied to any one item, then the last occurrence holds.

B.2.161 -YA, dir

Specifies a directory dir to search for all compiler components. If a component is not found in dir, the search reverts to the directory where the compiler is installed.

B.2.162 -YI, dir

Changes the default directory searched for include files.

B.2.163 -YP, dir

Changes the default directory for finding library files.

B.2.164 -YS, dir

Changes the default directory for startup object files.

B.2.165 -Zll

(SPARC) Creates the program database for lock_lint, but does not generate executable code. Refer to the lock_lint(1) man page for more details.