Useful references and links
Command-line toolsFeature comparison of various releases
Sun Studio Compiler Suite
(See this link for a complete list of command-line tools in Solaris Studio)
cc c89 c99 | C compiler. |
CC | C++ compiler. |
f90 | Fortran compiler. |
dbx | Debugger |
acomp | Compiler/preprocessor frontend for non -Xs (K&R) modes |
iropt | Global optimizer |
ipo | Inter-procedural optimizer |
ir2hf | Intermediate code translater |
lint | Source code checker |
ube | x86 optimizer & code generator (be=backend) |
cpp | C preprocessor |
fpp | Fortran preprocessor |
fbe | Assembler |
ld | Linker |
dem c++filt | C++ name demangler. It takes mangled names from stdin and displays their original forms. |
er_src | Like objdump, which can disassemble and display source code & compiler commentary. |
collect er_print | Thread analyzer. |
dmake rxm rxs | Distributed make |
bcheck | Batch utility for Runtime Checking (RTC) |
Compile
-c | Compile *.c and assemble *.s. NO linking. |
-Idir | Also search dir for header files. This can also be controlled by environmental variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH. |
-S | Compile *.c into assembly codes *.s. NO linking. |
-E | Run preprocessor only. The output is sent to stdout. |
-C | When running preprocessor, don't discard comments in the program. |
-o file | Place 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. |
-xtime | When compiling, display time/memory used in each stage (preprocessing/parsing etc.) |
-V | Display the version number. |
-v | Verbose mode |
C/C++ dialect
-Xa | ISO plus K&R standard. This is default. __STDC__ will be defined to be 0. |
-Xc | ISO standard only. __STDC__ will be defined to be 1. |
-Xs | Will emit warnings for difference between ISO standard and K&R. __STDC__ will NOT be defined. |
-xCC | Accept C++ style comments. |
-xc99=all | Accept ISO C99 standard. |
-xopenmp | Enable OpenMP. _OPENMP will be defined. |
-xopenmp=none | Compile an OpenMP program into serial code. All OpenMP directives are ignored. This is default. |
-xvpara | Show diagnostic information when compiling OpenMP programs. |
-mt | Enable multi-thread support.
_REENTRANT will be defined. |
-xbuiltin=%none | Don'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 |
-Uname | Un-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 file | The output of -xM is written to file. |
-xMD | The same as -xM -xMF combined, but doesn't imply -E. *.d files will be generated. |
-Wp,opt | Pass opt to the C preprocessor. |
Warning messages
-erroff=%all | Suppress all warnings. |
-errshort=%full | Detailed warning messages. |
-errwarn=%all | Treat warnings as errors. |
Link
-Ldir | Also search dir for library files. This can also be controlled by environmental variable LIBRARY_PATH. |
-llibrary | Link to liblibrary |
-s | Remove all symbol information from the executable
|
-dn | Produce statically linked executable |
-dy | Produce dynamically linked executable |
-staticlib=%all | Link statically to all libraries |
-staticlib=l | Link statically to libl, e.g. -staticlib=sunperf for static linking to the Sun Performance Library. |
-library=l | Link C++ library l |
-G -fPIC -R |
Produce shared libraries. |
-xnolib | Don'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
-g | Produce debugging information. |
-xs | Produce debugging information for dbx. |
-keeptmp | Save all temporary/intermediate files produced during compiling. |
-traceback=common | Add 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=%all | The same as both -xcheck=init_local and -xcheck=stkovf |
Profiling
-xpg | Produce profiling information for gprof. |
-xinstrument=datarace | Produce OpenMp profiling information to be used with Thread Analyzer |
-xF | Produce profiling information to be used with Performance Analyzer. |
Optimization
-O0 | Don't optimize. |
-O1 ... -O5 | Different levels of optimization. |
-O -O3 | Optimize. This is default. |
-xspace | Optimize for code size. |
-fast | This 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=mode | Set IEEE 754 floating-point rounding mode.
mode can be nearest, tozero negative, positive. Default is nearest. |
-xunroll=n | Unroll 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. |
-xlibmieee | Forces IEEE 754 style return values for math routines when there are exceptions. |
-xautopar | Automatically paralellize loops. |
-xloopinfo | Show diagnostic information about automatic loop parallelization during compilation. |
-xinline=auto | Inline functions (enabled at -O4) |
-xarch=simd | Generate 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 -m64 | Generate code for specific 64-bit cpu, which
can be generic, pentium, pentium_pro, pentium3, pentium4, woodcrest, penryn, nehalem, opteron, barcelona
Default is generic. |
-xpagesize=size | Large page support. |
-fstore -nofstore | Never/Try to store floating-point numbers in registers. Default is -fstore. |
-xvector=no%simd | Do not use SSE/SIMD extensions. |
Interesting features
-Qy | Save 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 usecc -### -E foo.cor
CC -xdumpmacros=%all foo.cto 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
libCrun | C++ runtime support (compiler helper functions, heap memory allocation, i.e. new/delete, exception handling, and dynamic type information, i.e. RTTI) |
libCstd | C++ standard library routines (iostreams, string, etc) |
libCstdG3 | The same as libCstd, but uses GCC version 3 C++ ABI, i.e. name mangling, exception handling, etc |
libblacs_openmpi | BLACS routines. Must be used in conjuction with Sun HPC ClusterTools (which is based on Open MPI) |
libdemangle | C++ name demangling routines |
libfai libfsu libfui | Fortran runtime support |
libiostream | The classic iostreams library (built with -compat=5 command-line option) |
libmopt | Optimized math (sin, cos, etc..) routines |
libmtsk | Microtasking (OpenMP/multi-thread) runtime support |
librwtool | Rogue Wave Tool.h++ foundation class routines |
libscalapack | ScaLAPACK routines. Must be used in conjuction with Sun HPC ClusterTools (which is based on Open MPI) |
libstlport | STLport implementation of the C++ standard library. To use, add -library=stlport4command-line option |
libsunimath | Fortran 95 interval arithmetic routines. To use, add -xiacommand-line option |
libsunperf | Performance library routines. To use, add -library=sunperfcommand-line option |
libsunquad | Fortran runtime support for 128-bit (REAL(KIND=16)) quad-precision floating-point data type |
libxprof | Profiling runtime support |