Sun Java Solaris Communities My SDN Account Join SDN

Article

Translating gcc/g++/gfortran Options to Sun Studio Compiler Options

 
By Diane Meirowitz, January 2009  

This article explains how to translate frequently used gnu compiler options to Sun Studio compiler options. It contains examples, a command translation table, an option translation table, and links to various resources.

In addition to world class highly optimizing C, C++, and Fortran compilers, Sun Studio software includes the full-featured dbx debugger that can debug optimized and parallel code, and the complete performance analyzer.

It is easy to start enjoying the increased performance and features of Sun Studio compilers and tools. Just download the free tools which run on Solaris/Linux/SPARC/x86 from here, make some minor modifications to your makefiles, and go.

Examples

If you are just getting started with Sun Studio compilers and tools, these examples may be helpful:

% cc -fast -xautopar -g myfile.c
Compile for best performance, automatic parallelization and analyzer use
% f95 -fast -xvector=simd -g myfile.f
Compile for best x86 performance and analyzer use
% CC -fast -g0 file.c
Compile for best performance and analyzer use
% CC -g0 file.c
Compile for debugging without optimization

 
Command Name Translation

The names of the compilers are different, as shown in the table below:

gcc
cc
C compiler
g++
CC
C++ compiler
gfortran
f95
Fortran compiler

 
Compiler/Linker Option Translation

Many gcc options are exactly the same in Sun Studio compilers. Here is a list of some of those options: -c, -D, -E, -I, -L, -l, -o, -S, -w. Some options look the same but have slightly different meanings. For example, -O means high optimization for gcc, but only moderate optimization for Sun Studio compilers, because -O is equivalent to -O3 while -O5 (or -xO5) is the Sun Studio compiler's highest optimization level.

The following table translates some of the more common gcc options. If you cannot figure out how to translate a particular option, you can get some help on the Sun Studio forums. Here is a convenient way to view all Sun Studio 12 compiler options, and C, C++, and Fortran User's Guides can be found here.

-help
-help
Prints a summary of available options
-g
-g
Produces additional symbol table and optimization information for the debugger and analyzer
 
-g0
C++: Produces additional symbol table information for the debugger and analyzer, but does not disable inlining. See here for more.
-p -profile
-g
Prepares the object code to collect data for profiling
-fbounds-check
-C
Fortran: Enable array bounds checking
 
-xcheck=init_local
Initialize local variables to garbage values
 
-xcheck=stkovf
Check for stack overflow
-m64
-m64
Generate code for the 64 bit memory model
-m32
-m32
Generate code for the 32 bit memory model
-fPIC
-KPIC
Generates position-independent code
-fdefault-double-8
-xtypemap=double:64
Make the size of DOUBLEPRECISION variables be 64 bits
-fdefault-real-8
-xtypemap=real:64
Fortran: Make the size of REAL variables be 64 bits
-fdefault-integer-8
-xtypemap=integer:64
Fortran: Make the size of INTEGER variables be 64 bits
-fno-underscoring
-ext_names=plain
Fortran: Do not append underscores to external names
-fsecond-underscore
available soon
Fortran: Append 2 underscores to external names containing underscores
-fopenmp
-xopenmp
Supports the OpenMP interface for explicit parallelization
-ffree-form
-free
Fortran: Free-form source
-ffixed-form
-fixed
Fortran: Fixed-form source
-ffixed-line-length-132
-e
Fortran: Extend max line length for fixed form source
-O
-fast
Invokes a variety of options as a first guess at best run-time performance
 
-xO5
Selects a high optimization level
 
-xtarget=native
Optimize code for the host system
 
-xalias_level
CC, cc: Enables the compiler to perform type-based alias analysis and optimizations
 
-xbuiltin
Improve the optimization of code that calls standard library functions
 
-xipo=2
Performs whole-program optimizations
-ftree-vectorize
-xvector=simd
Enables automatic generation of the packed SIMD instructions
-march
-xarch
Generates code for a particular instruction set architecture
-mtune
-xchip
Tune for a particular type of hardware
-ffast-math
-fsimple=2
Selects aggressive floating-point arithmetic optimizations
-ftree-parallelize-loops
-xautopar
Enables automatic parallelization for multiple processors
-funroll-loops
-xunroll
Unroll loops (on at -xO3 in Sun Studio compilers)
-finline-functions
-xinline
Inline functions (on at -xO4 in Sun Studio compilers)
-fno-inline-functions
-xinline=
Disables automatic function inlining
-Os
-xspace
Avoids optimizations that increase code size
-fprofile-generate
-xprofile=collect
Generates code to collect profile feedback information
-fprofile-use
-xprofile=use
Uses profile feedback information for optimization
-shared
-G
Linker: Produce a shared object rather than a dynamically linked executable
-static
-Bstatic
Linker: Link with static versions (.a) of libraries (default is -Bdynamic)

 
References
Rate This Article
 
Comments
Do you have comments about this article? We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of replies - your information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Diane Meirowitz Diane Meirowitz is a senior developer tools staff engineer at Sun Microsystems, Inc., specializing in compiler optimization and High Performance Computing. She has worked on all aspects of compiler software, including front ends, middle ends, back ends, and compiler-compilers, for C, C++ and Fortran. Before joining Sun, Diane developed parallelizing compilers at Thinking Machines Corporation, Kendall Square Research, Digital Equipment Corporation, and Compass, Inc. Diane has a master's degree in computer science and a bachelor's degree in hydrology from The University of New Hampshire, Durham.