Oracle/Sun Studio compiler suite reference card

Useful references and links

Command-line tools

Feature comparison of various releases

FAQs

Sun Studio Compiler Suite

(See this link for a complete list of command-line tools in Solaris Studio)

cc
c89
c99
C compiler.
CCC++ compiler.
f90Fortran compiler.
dbxDebugger
acompCompiler/preprocessor frontend for non -Xs (K&R) modes
iroptGlobal optimizer
ipoInter-procedural optimizer
ir2hfIntermediate code translater
lintSource code checker
ubex86 optimizer & code generator (be=backend)
cppC preprocessor
fppFortran preprocessor
fbeAssembler
ldLinker
dem
c++filt
C++ name demangler. It takes mangled names from stdin and displays their original forms.
er_srcLike objdump, which can disassemble and display source code & compiler commentary.

See here for examples and here for its man page.

collect
er_print
Thread analyzer.
dmake
rxm
rxs
Distributed make
bcheckBatch utility for Runtime Checking (RTC)

Compile

-cCompile *.c and assemble *.s. NO linking.
-IdirAlso search dir for header files.

This can also be controlled by environmental variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.

-SCompile *.c into assembly codes *.s. NO linking.
-ERun preprocessor only. The output is sent to stdout.
-CWhen running preprocessor, don't discard comments in the program.
-o filePlace output in file
-#When compiling, also display the programs invoked by the compiler.
-xdryrun
-###
Display the programs invoked by the driver, but do not compile.
-xtimeWhen compiling, display time/memory used in each stage (preprocessing/parsing etc.)
-VDisplay the version number.
-vVerbose mode

C/C++ dialect

-XaISO plus K&R standard.

This is default.

__STDC__ will be defined to be 0.

-XcISO standard only.

__STDC__ will be defined to be 1.

-XsWill emit warnings for difference between ISO standard and K&R.

__STDC__ will NOT be defined.

-xCCAccept C++ style comments.
-xc99=allAccept ISO C99 standard.
-xopenmpEnable OpenMP.

_OPENMP will be defined.

-xopenmp=noneCompile an OpenMP program into serial code. All OpenMP directives are ignored.

This is default.

-xvparaShow diagnostic information when compiling OpenMP programs.
-mtEnable multi-thread support.

_REENTRANT will be defined.

-xbuiltin=%noneDon't recognize any built-in functions.
-xchar=signed
-xchar=unsigned
Whether by default char is signed or unsigned.

Default is signed.

Preprocessor

-Dname
-Dname=value
Predefine the macro name, with value 1, or with the specified value
-UnameUn-define the (built-in or -D defined) macro name
-xM
-xM1
Output a rule (to stdout) suitable for Makefile describing the dependencies of the source file.

-xM1 only outputs header files not in the system header directories.

This option implies -E option.

-xMF fileThe output of -xM is written to file.
-xMDThe same as -xM -xMF combined, but doesn't imply -E.

*.d files will be generated.

-Wp,optPass opt to the C preprocessor.

Warning messages

-erroff=%allSuppress all warnings.
-errshort=%fullDetailed warning messages.
-errwarn=%allTreat warnings as errors.

Link

-LdirAlso search dir for library files. This can also be controlled by environmental variable LIBRARY_PATH.
-llibraryLink to liblibrary
-sRemove all symbol information from the executable

-dnProduce statically linked executable
-dyProduce dynamically linked executable
-staticlib=%allLink statically to all libraries
-staticlib=lLink statically to libl, e.g. -staticlib=sunperf for static linking to the Sun Performance Library.
-library=lLink C++ library l
-G
-fPIC
-R
Produce shared libraries.
-xnolibDon't link to the standard system libraries.
-Bstatic
-Bdynamic
For example, to link to a library statically, say libstdc++, but link to others dynamically, one can do
-Bstatic -lstdc++ -Bdynamic -lm

Debugging

-gProduce debugging information.
-xsProduce debugging information for dbx.
-keeptmpSave all temporary/intermediate files produced during compiling.
-traceback=commonAdd debug information for runtime stack trace back should error occurs.
-C[Fortran] Run-time array bounds checking and array syntax conformance checking.
-xcheck=init_local[Fortran] Run-time checking for accessing uninitialized local variables.
-xcheck=stkovf[Fortran] Run-time checking stack overflows. Usually used with -stackvar (allocating local variables on stack) option.
-xcheck=%allThe same as both -xcheck=init_local and -xcheck=stkovf

Profiling

-xpgProduce profiling information for gprof.
-xinstrument=dataraceProduce OpenMp profiling information to be used with Thread Analyzer
-xFProduce profiling information to be used with Performance Analyzer.

Optimization

-O0Don't optimize.
-O1
...
-O5
Different levels of optimization.
-O
-O3
Optimize.

This is default.

-xspaceOptimize for code size.
-fastThis is actually a macro. It implies -O5 and other optimization flags.

To see what it expands, use it in conjuction with -xdryrun

-xlibmopt
-xnolibmopt
Whether to use optimized math library routines or not.
-xlic_lib=sunperf
-library=sunperf
Use Sun Studio performance library routines.

See user's guide, FAQ, and reference manual for more info.

-fsimple=lvl Set the accuracy level of floating-point operations.

lvl can be 0,1,2, where 0 is strict, 1 is conservative and , 2 is relaxed (which allows aggressive optimizations at cost in accuracy or consistency, like GCC's -ffast-math option)

Default is 0.

-fround=modeSet IEEE 754 floating-point rounding mode.

mode can be nearest, tozero negative, positive.

Default is nearest.

-xunroll=nUnroll the loop at most n times.

To disable, use n=1.

-xprofile
-xprofile_ircache
-xprofile_pathmap
Profile guided optimization (PGO).
-xipo[=n]Link time/Inter-procedural optimization.

n can be 0,1,2. Default is 1.

-xlibmieeeForces IEEE 754 style return values for math routines when there are exceptions.
-xautoparAutomatically paralellize loops.
-xloopinfoShow diagnostic information about automatic loop parallelization during compilation.
-xinline=autoInline functions (enabled at -O4)
-xarch=simdGenerate code for specific SSE/SIMD extensions or new instructions.

simd can be generic, native, sse, sse2, sse3, ssse3, sse4_1, sse4_2, amdsse4a

Default is generic.

-xtarget=cpu -m64Generate code for specific 64-bit cpu, which can be generic, pentium, pentium_pro, pentium3, pentium4, woodcrest, penryn, nehalem, opteron, barcelona

Default is generic.

-xpagesize=sizeLarge page support.
-fstore
-nofstore
Never/Try to store floating-point numbers in registers.

Default is -fstore.

-xvector=no%simdDo not use SSE/SIMD extensions.

Interesting features

-QySave compiler version number and compiler options in the binary executable. This is default.

To see them, use the following commands

    objdump -sj .comment a.out
    objdump -sj .debug_info a.out
    readelf -p .comment a.out
    readelf -p .debug_info a.out
    

OpenMP environmental variables

The following environmental variables will affect OpenMP programs. For more info, see here.

OMP_NUM_THREADS
OMP_SET_NUM_THREADS
PARALLEL
Number of threads.
SUNW_MP_PROCBIND
MT_BIND_PROCESSOR
SUNW_MP_THR_AFFINITY
Set the threads' CPU affinity.

Default is FALSE

SUNW_MP_MAX_POOL_THREADS Maximum number of simultaneously executing threads.

Default is 1023.

SUNW_MP_MAX_NESTED_LEVELS Maximum depth of active nested parallel regions.

Default is 4.

SUNW_MP_GUIDED_WEIGHT Size of chunks assigned to threads in loops with GUIDED scheduling.

Default is 2.0

SUNW_MP_THR_IDLE Set to SPIN to spin (busy-wait) indefinitely after completing a parallel region.

Set to SLEEP(nms) for some n to spin for n ms before sleeping.

Default is SLEEP

SUNW_MP_WAIT_POLICY Specify how to wait for work (idle), wait at barrier, and wait at TASKWAIT OpenMP construct.

Default is IDLE=SLEEP:TASKWAIT=SLEEP:BARRIER=SLEEP.

See here for details.

SUNW_MP_WARN Set to TRUE to enable runtime warning messages.
STACKSIZE The number of bytes allocated for each OpenMP thread to use as the private stack for the thread.

Default is 8M

Sun Studio Compiler built-in macros

One can use
cc -### -E foo.c
or
CC -xdumpmacros=%all foo.c
to see all built-in macros and their values.

__cplusplus Is defined if C++ compiler is in use.
__FILE__
__BASE_FILE__
Name of the current input file (as a C string constant)

This is ANSI C standard macro.

__LINE__ Current input line number (as an integer constant)

This is ANSI C standard macro

__FUNCTION__
__func__
If inside a function, the current function name (as a C string constant)

This is ANSI C99 standard macro

__PRETTY_FUNCTION__ If inside a function, the complete type signature and name of the current function (as a C string constant).

For C++ code, this also contains the class name (i.e. the decorated name.)

__DATE__
__TIME__
Date & time on which the preprocessor is run. (as C string constants)

These are ANSI C standard macros.

__TIMESTAMP__ Last modification time of the input file (as a C string constant)
__STDC__
__STDC_VERSION__
Evaluate to 1 to mean the compiler is ISO standard conformant.

__STDC_VERSION__ evaluates to a C string constant of the form of the form yyyymmL.

__STDC__ is an ANSI C standard macro.

__SUNPRO_C
__SUNPRO_CC
__SUNPRO_F90
__SUNPRO_F95
Evaluate to integer constant 0xXXXX representing the C/C++/Fortran compiler version number.
_OPENMP Is defined if OpenMP is in effect.
_REENTRANT Is defined if -mt option is in effect.

Sun Studio Compiler #pragma directives

#pragma align n (var1,var2...) Specify alignment of n bytes for the variable var1,var2...
#pragma does_not_write_global_data (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions do not write to global variables.
#pragma no_side_effect (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions have no side effects; no access to global variables and no file I/O.
#pragma does_not_return (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions will not return (such as abort or exit)
#pragma rarely_called (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions are rarely called.
#pragma inline (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions should be inlined.
#pragma no_inline (fun1,fun2...) Provide hint to the compiler that fun1,fun2... functions should not be inlined.
#pragma unroll (n) Specify the how many times a loop to be unrolled.
#pragma init (fun1,fun2...) Declare fun1,fun2... functions to be called before main is invoked.
#pragma fini (fun1,fun2...) Declare fun1,fun2... functions to be called after exit is invoked.
#pragma weak symbol Declare symbol as a weak symbol.

A better way to achieve this is through function attribute "weak".

#pragma weak symbol1=symbol2 Declare symbol1 as a weak alias of symbol2.

A better way to achieve this is through function attributes "weak, alias".

Sun Studio C/C++ Compiler extension

&&label1 Get the address of label1 (defined in the current function.) The value has type void *. For example:
int value=1;
const void *labels[] = {&&val_0, &&val_1};
goto *labels[value];

val_0:
  printf("The value is 0\n");
  goto end;
val_1:
  printf("The value is 1\n");
  goto end;
end:
See here for more "labels as values" examples.
case ranges Specify a range of consecutive values in a single case label, as below:
int value = 7;

switch(value) {
case 0 ... 5:
  printf("The value is 0 - 5\n");
  break;
case 6 ... 10:
  printf("The value is 6 - 10\n");
  break;
default:
  printf("The value is ?\n");
}
Note that there must be spaces around the ... otherwise it may be parsed wrong when one uses it with integer values.
__thread Specify a variable to be stored in the thread-local storage
__typeof__
typeof
Get the type of an expression.

typeofis an ISO C99 standard. See here for examples.

Sun Studio C/C++ Compiler supplied libraries

libCrunC++ runtime support (compiler helper functions, heap memory allocation, i.e. new/delete, exception handling, and dynamic type information, i.e. RTTI)
libCstdC++ standard library routines (iostreams, string, etc)
libCstdG3The same as libCstd, but uses GCC version 3 C++ ABI, i.e. name mangling, exception handling, etc
libblacs_openmpiBLACS routines. Must be used in conjuction with Sun HPC ClusterTools (which is based on Open MPI)
libdemangleC++ name demangling routines
libfai
libfsu
libfui
Fortran runtime support
libiostreamThe classic iostreams library (built with -compat=5 command-line option)
libmoptOptimized math (sin, cos, etc..) routines
libmtskMicrotasking (OpenMP/multi-thread) runtime support
librwtoolRogue Wave Tool.h++ foundation class routines
libscalapackScaLAPACK routines. Must be used in conjuction with Sun HPC ClusterTools (which is based on Open MPI)
libstlportSTLport implementation of the C++ standard library.

To use, add

-library=stlport4
command-line option
libsunimathFortran 95 interval arithmetic routines.

To use, add

-xia
command-line option
libsunperfPerformance library routines.

To use, add

-library=sunperf
command-line option
libsunquadFortran runtime support for 128-bit (REAL(KIND=16)) quad-precision floating-point data type
libxprofProfiling runtime support