|
Topics:
Introduction
ISVs and developers can choose between multiple compilers to use on Solaris
Operating System, x86 Platform Edition. Among the most
popular options are the Sun Studio compilers and GCC. If your application is
developed primarily on the SPARC Platform Edition
using Sun Studio developer tools, it is easier to port to Solaris x86.
If you are porting your application from Linux, it is easier to use GCC, as you
can use the same build environment. There is no
need to change compiler flags as they are the same on Linux and the Solaris OS,
x86 Platform Edition.
The following figure shows different ways (with respect to compilers)
applications can be supported on the Solaris OS, x86
Platform Edition.

Figure 1: Different Compiler Options and Estimated Level of
Difficulty
(click to enlarge)
If you use multiple compilers on any platform, you are likely to run into ABI
incompatibility issues. C++ compilers are not ABI
compatible, that is, objects linked with one C++ compiler cannot be linked with
objects generated by another compiler. If you are
using Sun Studio compilers, and the dominant compiler on Solaris x86 is GCC, you
will have to ensure that all of your
application's modules are compiled with the Sun Studio compilers; otherwise you
may not be able to link your code.
If the application has been optimized for the SPARC Platform Edition using
back-end compiler flags, some flags may be incompatible
for the x86 platform. These flags need to be deleted or replaced with the flags
that are valid on the x86 platform and used for
optimization for the x86 platform. You can refer the later part of this document
for a list of flag differences.
With the release of Sun Studio 9, the Fortran 95 compiler, f95, is now available
on Solaris x86 platforms.
Back to Top
Sun Studio Developer Tools
Sun Studio software consists of C,
C++,
Fortran compilers; the Performance Analyzer; and the debugger. The
complete compilation architecture consists of a compiler, an assembler,
and a link editor. The compiler is made up of a front-end component and
a back-end component. The front end consists of syntax and semantic
analyzer modules based on the source language, while the back end
consists of code optimization and code generation modules based on the
instruction set for a particular hardware.
Sun Studio developer tools are
available for
the Solaris OS, SPARC and x86 Platform Editions. Since the compilers
share a common front end, most source code is easily ported between
platforms. Applications with platform-specific definitions (for
example, #ifdef __sparc), may require user intervention
before porting between platforms.
Performance-sensitive applications generally use
platform-specific
optimization flags to achieve good performance. These flags are
architecture dependent and are different for the SPARC and x86
platforms. This paper discusses these differences in detail.
This document focuses on the scenario where an application is
being
ported from the Solaris OS, SPARC Platform Edition, to the x86 Platform
Edition, using Sun Studio products.
Back to Top
Compiler Options for SPARC Platform Not Used on x86 Platform
The following options are used in the SPARC version of Sun Studio software; they are not present in the x86
version. When a source program is compiled using these options on the
Solaris OS, x86 Platform Edition, a warning is issued indicating an
illegal option has been used, or else the compiler ignores the option.
Table 1: Options for Sun Studio
(SPARC Version)
| Compiler Option |
Explanation |
Behavior on x86 Version |
-cg89 (C++) |
This option is the same as -xcg89 in cc.
Used for improving runtime performance for the SPARC architecture. It
compiles the C++ code for generic SPARC architecture. Equivalent to -xtarget=ss2. |
Warning issued by C++ compilers [1] |
-cg92 (C++) |
This option is the same as -xcg92 in cc.
Used for improving runtime performance for the SPARC architecture. It
compiles the C++ code for SPARC V8 architecture. Equivalent to -xtarget=ss1000. |
Warning issued by C++ compiler [1] |
-dalign (C) |
Equivalent to -xmemalign=8s. This flag
allows the user to specify the maximum memory alignment of 8 bytes to
be assumed by the compiler in indeterminable situations. It also
specifies that SIGBUS be raised when misaligned memory
access takes place. |
Option ignored [3] |
-fns |
Turns on the SPARC nonstandard floating-point mode.
When nonstandard mode is enabled, floating-point arithmetic may produce
results that do not conform to the requirements of the IEEE 754
standard. |
Option ignored [3] |
-misalign |
Equivalent to -xmemalign=1i. This flag
allows the user to specify the maximum memory alignment of 1 byte to be
assumed by the compiler in indeterminable situations. This option
specifies that access be interpreted and execution be continued, when a
misaligned memory access takes place. |
Option ignored [3] |
-misalign2 (C) |
Equivalent to -xmemalign=2i. This flag
allows the user to specify the maximum memory alignment of 2 bytes to
be assumed by the compiler in indeterminable situations. This option
specifies that SIGBUS be raised when a misaligned access
occurs. |
Option ignored [3] |
-xalias_level |
Used to determine the assumptions that can be made by
the compiler in order to perform optimizations (using the -xO
option) using type-based alias-analysis. |
Warning issued by C compiler [2] |
-xautopar (C) |
This option turns on automatic parallelization for
multiple processors used in the SPARC architecture. It also does
dependence analysis (analyzes loops for inter-iteration data
dependence) and loop restructuring. |
Option ignored [3] |
-xcache (C++) |
This option defines cache properties for use by the
optimizer. |
Warning issued by C++ compiler[1] |
-xcg89 (C) |
This option is used for improving runtime performance
for the SPARC architecture. It compiles the C++ code for generic SPARC
architecture. Equivalent to -xtarget=ss2 (-xarch=v7 -xchip=old
-xcache=64/32/1) |
Option ignored [3] |
-xcg92 (C) |
This option is used for improving runtime performance
for the SPARC architecture. It compiles the C++ code for SPARC V8
architecture. Equivalent to -xtarget=ss1000 (-xarch=v8
-xchip=super -xcache=16/32/4:1024/32/1). |
Option ignored [3] |
-xcheck |
This option adds a runtime check for stack overflow. |
Warning issued by C compiler[2] |
-xcode |
This option specifies the code address space. |
Warning issued by C compiler[2] |
-xcrossfile (C) |
This option enables optimization and inlining across
source files. |
Option ignored [3] |
-xdepend (C) |
This option analyzes loops for inter-iteration data
dependencies and does loop restructuring. |
Option ignored [3] |
-xexplicitpar (C) |
This option generates paralleled code based on
specification of #pragma MP directives. |
Option ignored [3] |
-xhwcprof (C) |
This option enables compiler support for hardware
counter-based profiling. |
Option ignored [3] |
-xia (C++) |
This option links the appropriate interval arithmetic
libraries and sets a suitable floating-point environment. |
Warning issued by C++ compiler[1] |
-xipo |
This option performs inter-procedural optimizations. |
Option ignored [3] |
-xjobs |
This option specifies the maximum number of components
the compiler will fork in parallel. |
Warning issued by C compiler[2] |
-xldscope |
This option is used to change the default linker
scoping for the definition of extern symbols. |
Warning issued by C compiler[2] |
-xlic_lib=sunperf |
This option links in the Sun-supplied performance
libraries. |
Option ignored [3] |
-xlinkopt (C) |
This option instructs the compiler to perform link-time
optimization on the resulting executable or dynamic library over and
above any optimizations in the object files. |
Warning issued by C compiler[2] |
-xloopinfo (C) |
This option shows which loops are paralleled and which
are not. |
Warning issued by C compiler[2] |
-xmemalign |
This option specifies maximum assumed memory alignment
and behavior of misaligned data accesses. |
Warning issued by C compiler[2] |
-xMerge |
This option merges data segments into text segments. |
Option ignored [3] |
-xopenmp |
This option enables explicit parallelization with
OpenMP directives. |
Warning issued by C compiler[2] |
-xpagesize |
This option sets the preferred page size for the stack
and the heap. |
Warning issued by C compiler[2] |
-xpagesize_heap |
This option sets the preferred page size for the heap. |
Warning issued by C compiler[2] |
-xpagesize_stack |
This option sets the preferred page size for the stack. |
Warning issued by C compiler[2] |
-xport64 (C++) |
This option helps to debug code being ported to a
64-bit environment. |
Warning issued by C++ compiler[1] |
-xparallel (C) |
This option parallelizes loops both automatically by
the compiler and explicitly specified by the programmer. |
Option ignored [3] |
-xprefetch |
This option enables prefetch instructions on those
architectures that support prefetch. |
Warning issued by C compiler[2] |
-xprefetch_level |
This option controls the number of pre-fetch
instructions as determined with -xprefetch=auto. |
Warning issued by C compiler[2] |
-xprofile_ircache |
This option is used with -xprofile=collect,
or -xprofile=use to improve compilation time during the
use phase by reusing compilation data saved from the collect phase. |
Warning issued by C compiler[2] |
-xprofile_pathmap |
This option is used with -xprofile=use
and it uses the prefix of the UNIX pathname of a directory tree in
which object files were compiled. |
Warning issued by C compiler[2] |
-xreduction (C) |
This option turns on reduction recognition during
automatic parallelization. |
Option ignored [3] |
-xregs |
This option specifies the usage of registers for the
generated code. |
Warning issued by C compiler[2] |
-xrestrict (C) |
This option treats pointer-valued function parameters
as restricted pointers. |
Option ignored [3] |
-xsafe=mem |
This option allows the compiler to assume no
memory-based traps occur. |
Option ignored [3] |
-xspace |
This option passes the instruction to the compiler to
not do optimizations or parallelization of loops that increase code
size. |
Option ignored [3] |
-xthreadvar |
This option controls the implementation of thread local
variables. |
Warning issued by C compiler[2] |
-xvector |
This option enables automatic generation of calls to
the vector library functions. |
Warning issued by C compiler[2] |
-xvis |
This option is used when the assembly-language
templates defined in the VIS instruction-set Software Developers Kit
(VSDK) are used. |
Option ignored [3] |
-xvpara (C) |
This option warns about loops that have #pragma
MP directives specified when the loop may not be properly specified for
parallelization. |
Option ignored [3] |
-Zll (C) |
This option creates the program database for lock_lint,
but does not generate executable code. |
Option ignored [3] |
Key: (C) denotes compiler option used by cc (C compiler).
(C++) denotes compiler option used by CC (C++ compiler). Otherwise the
option is valid for both cc and CC (C and C++ compilers).
Notes:
[1] The C++ compiler option works only for the
SPARC platform and would
give a compiler warning when used on the x86 platform. To avoid this
warning, this compiler option should not be used on the x86 platform.
[2] The C compiler option works only for the
SPARC platform and would
give a compiler warning when used on the x86 platform. To avoid this
warning, this compiler option should not be used on the x86 platform.
[3] The option is valid only on the SPARC
platform. While its use on
the x86 platform does not generate any warning, this option is ignored
during the generation of binaries on the x86 platform.
Back to Top
Compiler Options for x86 Platform Not Used on SPARC Platform
Here we explain the options that are used on the x86 version
of Sun Studio software and are not present
in the SPARC version. When a source program is compiled using these
options on the Solaris OS, SPARC Platform Edition, a warning is issued
indicating that an illegal option was used, or the compiler ignores the
option.
Table 2: Options for Sun Studio
(x86 Version)
| Compiler Option |
Explanation |
Behavior on SPARC Platform |
-386 (C++) |
Same as -xtarget=386. Specifies the
target platform as 386-based instruction set and optimization. |
Warning issued by C++ compiler[1] |
-486 (C++) |
Same as -xtarget=486. Specifies the
target platform as 486-based instruction set and optimization. |
Warning issued by C++ compiler[1] |
-fprecision |
This option initializes the rounding-precision mode
bits in the floating-point control word to single (24 bits), double (53
bits), or extended (64 bits). |
Option ignored[3] |
-fstore |
This option causes the compiler to convert the value of
a floating-point expression or function to the type on the left side of
an assignment rather than leave the value in a register when: The
expression or function is assigned to a variable. The expression is
cast to a shorter floating-point type. |
Option ignored[3] |
-nofstore |
This option disables forced precision of an expression. |
Option ignored[3] |
-x386 (C) |
This option optimizes the code for the 80386 processor. |
Option ignored[3] |
-x486 (C) |
This option optimizes the code for the 80386 processor. |
Option ignored[3] |
-xpentium |
This option optimizes the code for the Pentium
processor. |
Warning issued by C compiler[2] |
Key: (C) denotes compiler option used by cc (C compiler).
(C++) denotes compiler option used by CC (C++ compiler). Otherwise the
option is valid for both cc and CC (C and C++ compilers).
Notes:
[1] The C++ compiler option works only for the
x86 platform and would
give a compiler warning when used on the SPARC platform. To avoid this
warning, this compiler option should not be used on the SPARC platform.
[2] The C compiler option works only for the x86
platform and would
give a compiler warning when used on the SPARC platform. To avoid this
warning, this compiler option should not be used on the SPARC platform.
[3] The option is valid only on the x86
platform. While its use on the
SPARC platform does not generate any warning, this option is ignored
during generation of binaries on the SPARC platform.
Back to Top
Compiler Options Used on Both Solaris Versions But with
Different Implications
The following options in the Sun Studio developer tools are used on both SPARC and x86 versions, but
with different implications that are explained in the table. When a
source program is compiled on the Solaris OS using these options, the
values passed to the options are different on both platforms.
Table 3: Options for Sun Studio
| Compiler Option |
Explanation |
Values for SPARC |
Values for x86 |
-Aname[(tokens)] (C) |
This option associates name with the specified tokens
like a #define preprocessing directive. |
The values for preassertions are:
machine(sparc)
cpu(sparc) |
The values for preassertions are:
machine(i386)
cpu(i386) |
-Dname[=tokens] |
This option associates name with the specified tokens
like a #define preprocessing directive. |
The values are:
sparc
(not valid in-Xc mode) __sparc (valid in all modes) |
The values are:
i386
(not valid in-Xc mode) __i386 (valid in all modes) |
-fast |
This option selects a set of baseline options for
optimizing benchmark applications. |
The option expands to the following values on SPARC
platform:
-fns
-fsimple=2
-fsingle
-ftrap=%none
-xalias_level=basic
-xarch
-xbuiltin=%all
-xdepend
-xlibmil
-xmemalign=8s
-xO5
-xprefetch=
auto,explicit |
The option expands to the following values on x86
platform:
-fns
-fsimple=2
-fsingle
-ftrap=%none
-nofstore
-xarch
-xbuiltin=%all
-xdepend
-xlibmil
-xO5 |
-fnonstd |
This option causes nonstandard initialization of
floating-point arithmetic hardware. |
This option expands to:
fns
-ftrap=common |
This option expands to: ftrap=common |
-KPIC |
This option is used to compile source files when
building a shared library. |
Equivalent to: -xcode=pic32 |
Same as -Kpic |
-Kpic |
This option is used to compile source files when
building a shared library. |
Equivalent to: -xcode=pic13 |
Compiles with position-independent code. |
-PIC (C++) |
This option is used to compile source files when
building a shared library. |
Equivalent to: -xcode=pic32 |
Same as -Kpic |
-pic (C++) |
This option is used to compile source files when
building a shared library. |
Equivalent to: -xcode=pic13 |
Same as -Kpic |
-xarch |
This option specifies the instruction set architecture
(ISA). |
The values are:
generic
generic64
native
native64
v7
v8a
v8
v8plus
v8plusa
v8plusb
v9a
v9b
v9 |
The values are:
generic
386
pentium_pro |
-xchip |
This option specifies the target processor for use by
the optimizer. |
The values are:
generic
old
super
super2
micro
micro2
hyper
hyper2
powerup
ultra
ultra2
ultra2e
ultra2i
ultra3
ultra3cu |
The values are:
generic
386
486
pentium
pentium_pro |
-xO |
This option optimizes the object code depending on the
levels set. |
The values are:
xO1: Does basic local optimization
xO2: Does basic local and global optimization.
xO3: Performs like -xO2, but
also optimizes references or definitions for external variables.
xO4: Performs like -xO3, but
also automatically inlines functions contained in the same file for
faster execution.
xO5: Generates the highest level of
optimization. |
The values are:
xO1: Preloads arguments from memory and
cross-jumping, 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 sub-expressions.
xO3: Performs loop strength reduction,
induction variable elimination, on top of the functions carried out by
the -x02 option.
xO4: Performs loop unrolling, avoids creating
stack frames when possible, and automatically inlines functions
contained in the same file, on top of the functions carried out by -xO3.
xO5: Generates the highest level of
optimization. |
-xtarget |
This option specifies the target system for instruction
set and optimization. |
The values are:
native
native64
generic
generic64
<<platform-name>> |
The values are:
native
generic
386
486
pentium
pentium_pro |
Key: (C) denotes compiler option used by cc (C compiler).
(C++) denotes compiler option used by CC (C++ compiler). Otherwise the
option is valid for both cc and CC (C and C++ compilers).
Back to Top
Conclusion
Many applications can be migrated without changing source code
from the Solaris OS, SPARC Platform Edition, to the Solaris OS x86
Platform Edition. Since Sun Studio software
is supported on both the SPARC and x86 versions of the Solaris OS, you
can port applications from the Solaris OS, SPARC Platform Edition,
using the same compiler. A few compiler flags need to be replaced in
the build environment.
Similarly, applications can be ported from Linux to the
Solaris OS
using the same build environment. In this case, there is likely no need
to change any compiler flags.
Back to Top
|