Section 4.3. Compilers


4.3. Compilers

As the porting effort starts, differences in compilers, compiler options, and system libraries between Solaris and Linux become apparent. This section provides information on the GNU compiler available on Linux. It presents comparison tables of compiler options and switches between Sun's Studio and GCC.

4.3.1. C Compiler

Sun's Studio 10 C compiler conforms to the ISO/IEC 9899-1990, Programming languageC (C90). This compiler supports most of the language features specified in the ISO/IEC 9899-1999, Programming LanguageC standard (C99) on operating systems earlier than Solaris 10. It is in full compliance with the C99 standard on Solaris 10 when -xc99=all, lib is specified.

4.3.2. C Compiler Options

Table 4-2 provides a list of C compiler options for SUN Studio 10 and equivalents for the GNU GCC 3.4.2.

Table 4-2. C Compiler Options Comparison

Sun Studio 10

GNU GCC 3.4.2

Description[6]

-#

-v

Instructs the compiler to report information on the progress of the compilation. The gcc equivalent shows the invocation on standard error.

-###

-###

Traces the compilation without invoking anything.

-Aname(tokens)

-Aname=tokens

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

-Bstatic

-static

Causes the link editor to look only for files named libx.a.

-Bdynamic

Default

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

-C

-C

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

-dalign

-malign-double

Obsolete. See -xmemalign=8s.

-d[y|n]

Implicit

-dy specifies dynamic linking. -dn specifies static linking in the link editor. On Linux, if an executable is linked against any shared object, it is a dynamic binary. If it is linked without the use of any shared object, the executable is linked statically.

-errfmt[=[no%]

N/A

Prefixes the string "error" to the beginning error] of error messages so that they are more visible.

-erroff[=t]

N/A

Suppresses C compiler warning messages based on their tag number and has no effect on error messages. There is no direct equivalent in GCC, but you can inhibit all warnings completely with -w.

-errshort=[i]

N/A

Controls the detail of the error message for type mismatch.

-errtags[=a]

N/A

Displays the message tag for each warning message.

-errwarn[=t]

N/A

Causes the compiler to exit with a failure for the specified warning message.

-fast

-Ox

A macro that enables the compiler to produce optimized executable. GCC does not have this macro, but you can use a combination of -O options and others.

-fd

-Wstrict
-prototypes

Reports K&R-style function definition and declaration.

-features=[[no%extinl|%none]

N/A

Generates extern inline functions as global functions or static functions.

-flags

--help, -v

Prints a summary of each available compiler flag.

-flteval [={any|2}]

-mfpmath=unit (specific to i386 and evaluated. x86-64)

Controls how floating-point expression is evaluated.

-fnonstd

N/A

A macro for -fns and -ftrap.

-fns[={no|yes}]

N/A

Turns on SPARC nonstandard floating-point mode.

-fprecision=p

-fsingle-precision-constant

Initializes the rounding-precision mode bits in the floating-point Control Word to single, double, or extended. GCC does not have a direct equivalent, but -fsingle-precision-constant forces the compiler to treat a floating-point constant as a single precision instead of converting it to a double precision constant.

-fround=r

-frounding-math

Sets the IEEE 754 rounding mode. The default IEEE mode is round-to-nearest. This is also the case on Linux, but there is no option to select the mode. Consider -frounding-math in GCC.

-fsimple[=n]

N/A

Allows the optimizer to make simplifying assumptions about floating-point arithmetic. GCC does not have the exact match. Consider these flags for floating-point optimizations not compliant with IEEE or ISO: -ffloat-store, -ffast-math, -fno-math-error, -funsafe-math-optimizations, -ffinite-math-only, -fno-trapping-math.

-fsingle

-fsingle-precision-constant

Causes the compiler to evaluate float expressions as single precision rather than double precision.

-fstore

-ffloat-store

Causes floating-point variables not to be stored in registers.

-ftrap=t[,t...]

-fno-trapping-math

Sets the IEEE trapping mode in effect at startup but does not install a SIGFPE handler. GCC does not have the direct equivalent, but -fno-trapping-math disables all user-visible traps, including division by 0, overflow, underflow, inexact result, and invalid operation.

-G

-shared

Produces a shared object rather than a dynamically linked executable.

-g

-g

Produces additional symbol table information for debugging.

-H

-H

Prints to standard error the path name of each file included during the compilation.

-hname,

-hname, -Wl, -soname, name

Gives a name to a shared dynamic library to have different versions of a library.

-I[-|dir]

-I[-|dir]

Adds dir to the list of directories searched for include files.

-i

N/A

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

-KPIC

-fPIC

Generates position-independent code for use in shared libraries (large model).

-Kpic

-fpic

Same as -fPIC except that the size of the global offset table is limited to 8K on the SPARC and 32K on the m68k and PPC (32, 64). This limit does not exist on the 386. Code generated for the IBM PowerPC-based architecture is always position-independent.

-keeptmp

-save-temps

Keeps temporary files created during compilation instead of removing them automatically.

-Ldir

-Ldir

Adds directory dir to the list of directories to be searched for archive libraries by ld. The directories are searched in the order in which they are specified on the command line.

-lname

-lname

Adds archive file name to the list of files to link. ld will search a directory for a library with an extension of .so before searching for one with an extension of .a. The linker will search an archive only once, at the location that it is specified on the command line. An undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

-mc

N/A

Removes duplicate strings from the .comment section of the object file.

-misalign

Implicit

Obsolete. Look at -xmemalign=1i. This option is not necessary for the IA-32 because the processor handles alignment by itself.

-misalign2

Implicit

Obsolete. Look at -xmemalign=2i. This option is not necessary for the IA-32 because the processor handles alignment by itself.

-mr[, string]

N/A

Removes all strings from the .comment section.

-mt

-pthread-D_REENTRANT

Macro option that expands to -D_REENTRANT -lthread. On Linux, -pthread adds support for multithreading with the pthreads library.

-native

-mcpu=cpu_type

Synonym for -xtarget=native. Produces code that performs best on the host system. GCC does not have the direct equivalent, but you can use -mcpu to specify the type of your host system.

-nofstore

Implicit

Has the opposite effect of -fstore. GCC has the option -ffloat-store, which has the opposite meaning of -nofstore.

-O

-O3

Uses default optimization level -xO3.

-o filename

-o filename

Assigns the name filename to the output file.

-P

-E

Runs the source file through the C preprocessor only. This option does not include preprocessor-type line number information in the output.

-p

-p

Generates extra code to write profile information suitable for the analysis program prof.

-Q[y|n]

-Q

Emits or does not emit identification information to the output file. GCC only has -Q.

-qp

-p

Same as -p.

-Rdir[:dir]

-wl,-rpathdir

Passes a colon-separated list of directories used to specify library search directories to the runtime linker.

-S

-S

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

-s

-s

Removes all symbolic debugging information from the output object file. Passed to ld.

-Uname

-Uname

Undefines the preprocessor symbol name.

-V

-v, --version

Prints the name and version ID of each component as the compiler executes.

-v

-Wall

Directs the compiler to perform stricter semantic checks and to enable other lint-like checks.

-Wc, arg

-Wc, arg

Passes the argument arg to a specified tool c. This option is available on GCC in the same format, but not all tools are supported by gcc. The tools that have equivalents in GCC are Assembler, Linker, and Preprocessor.

-w

-w

Suppresses compiler warning messages.

-X[c|a|t|s]

N/A

Specifies varying degrees of compliance to the ISO C standard. There is no exact match in GCC, but the -pedantic option issues all the warnings demanded by strict ISO C and ISO C++.

-x386

-mcpu=i386, -march=i386,

Obsolete. Use -xchip=generic.

-x486

-mcpu=i486, -march=i486,

Obsolete. Use -xchip=generic.

-xa

-fprofile-arcs -ftest-coverage

Obsolete. Use -xprofile=tcov.

-xalias_level [=l]

N/A

The compiler uses this option to determine what assumptions it can make to perform optimizations using type-based alias analysis.

-xarch=isa

-march=isa

Specifies instruction set architecture.

-xautopar

N/A

Turns on automatic parallelization for multiple processors.

-xbuiltin [=(%all|%none)]

N/A

Substitutes intrinsic functions or inline system functions where profitable for performance.

-xCC

N/A

When -xc99=none and -xCC are specified, the compiler accepts the C++-style comments.

-xc99[=o]

N/A

Controls compiler recognition of the implemented features from the C99 standard. There is no exact match in GCC, but the option -std=c99 is available.

-xcache[=c]

N/A

Defines the cache properties for use by the optimizer.

-xchar[=o]

-funsigned-char or -fsigned-char

Treats the char type as signed or unsigned.

-xchar_byte_order[=o]

N/A

Produces an integer constant by placing the characters of a multicharacter character-constant in the specified byte order.

-xcheck[=o]

N/A

Adds a runtime check for stack overflow.

-xchip[=c]

-march

Specifies the target processor for use by the optimizer.

-xcode[=v]

N/A

Specifies code address space. There is no exact match in GCC. However, -xcode=pic13 is equivalent to -fpic. -xcode=pic32 is equivalent to -fPIC.

-xcrossfile[=n]

-funit-at-a-time

Enables optimization and inlining across source files.

-xcsi

N/A

Allows the C compiler to accept source code written in locales that do not conform to the ISO C source character code requirements.

-xdebugformat =[stabs|dwarf]

-gstabs, -gstab+, -gdwarf-2, -ggdb

Allows the C compiler to choose the formats of debugger information.

-xdepend=[yes|no]

-floop-optimize, -falign-loops

Analyzes loops for inter-iteration data dependencies and does loop restructuring.

-xdryrun

-###

Macro for -###.

-xe

-fsyntax-only

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

-xexplicitpar

N/A

Generates parallelized code based on specification of #pragma MP directives.

-xF

-freorder-functions, -freorder-blocks, -freorder-blocks -and-partition

Enables optimal reordering of functions and variables by the linker.

-xhelp=f

--help -v

Displays online help information.

-xhwcprof

N/A

Enables compiler support for hardware counter-based profiling.

-xildoff

N/A

Turns off the incremental linker and forces the use of ld.

-xildon

N/A

Turns on the incremental linker and forces the use of ild in incremental mode.

-xinline=list

N/A

Attempts to inline only those functions specified in the optional list.

-xipo[=a]

-funit-at-a-time

With -xipo=1, the compiler performs inlining across all source files. With -xipo=2, the compiler performs interprocedural aliasing analysis and optimizations of memory allocation and layout to improve cache performance.

-xipo_archive=[a]

N/A

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.

-xjobs=n

N/A

Sets how many processes the compiler creates to complete its work.

-xldscope={v}

N/A

Changes the default linker scoping for the definition of extern symbols.

-xlibmieee

N/A

Forces IEEE 754-style return values for math routines in exceptional cases.

-xlibmil

N/A

Inlines some library routines for faster execution.

-xlibmopt

N/A

Enables the compiler to use a library of optimized math routines.

-xlic_lib=sunperf

N/A

Links in the Sun-supplied performance libraries.

-xlicinfo

N/A

Returns information about the licensing system.

-xlinkopt[=level]

N/A

Instructs the compiler to perform link-time optimizations on relocatable object files.

-xloopinfo

N/A

Shows information about loops that are parallelized.

-xM

-M

Displays makefile dependencies.

-xM1

(-MM)

Shows dependencies such as -xM, but excludes /usr/include files. The option -MM does something similar for GCC, but GCC avoids dependencies for files from the system directories, or header files that are included, directly or indirectly, from such a header.

-xMerge

N/A

Merges data segments into text segments.

-xmaxopt[=v]

N/A

Limits the level of pragma opt to the level specified.

-xmemalign=ab

N/A

Specifies max assumed memory alignment and behavior of misaligned data accesses. GCC does not have the exact match, but has multiple options regarding memory alignment for various supported platforms. For i386 and x86-64, GCC provides, for example, -malign-double, -m96bit-long-double, m128bit-long-double, mpreferred-stack-boundary=num.

-xnativeconnect=v

N/A

Enables the shared library to interface with Java code.

-xnolib

-nostdlib

Does not link any libraries by default.

-xnolibmil

N/A

Does not inline math library routines. GCC does not have the exact match, but there are -fno-default-inline and -fno-inline.

-xnolibmopt

N/A

Prevents the use of an optimized math library by the compiler.

-xO[1|2|3|4|5]

-O1, -O2, -O3

Selects the optimization levels. GCC does not have the fourth and fifth optimization levels.

-xopenmp[=i]

N/A

Enables explicit parallelization with OpenMP directives. The implementation of OpenMP for GNU C, C++, and FORTRAN compilers is under development.

-xP

N/A

Prints prototypes for all K&R C functions.

-xpagesize=n

N/A

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

-xpagesize_heap=n

N/A

Sets the page size in memory for the heap.

-xpagesize_stack=n

N/A

Sets the page size in memory for the stack.

-xparallel

N/A

A macro equivalent to -xautopar, -xdepend, -xexplicitpar.

-xpch=v

Default

Activates the precompiled header feature. To create a precompiled header file with GCC, you simply have to compile it as you would any other file. GCC will search for the precompiled header with .gch appended.

-xpchstop=[file|<include>]

N/A

Specifies the last include file of the viable prefix for the precompiled header file.

-xpentium

-mtune=cpu-type

Generates code for the Pentium processor.

-xpg

-pg

Prepares the object code to collect data for profiling with gprof.

-xprefetch[=val[,val]]

N/A

Enables prefetch instructions on those architectures that support prefetch.

-xprefetch_auto_type=a

N/A

Determines whether 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.

-xprefetch_level=l

N/A

Controls the aggressiveness of automatic insert of prefetch instructions as determined with -xprefetch=auto.

-xprofile=collect

-fprofile-generate

Collects and saves execution-frequency data to use in subsequent runs to improve performance.

-xprofile=use

-fprofile-use

Uses the execution-frequency data generated and saved from a previous execution.

-xprofile=tcov

-fprofile-arcs-ftest-coverage

Emits information for the tcov tool. On Linux, use GNU version gcov to process the output.

-xprofile_ircache[=path]

N/A

Improves compilation time during the use phase.

-xprofile_pathmap

N/A

Locates profile data for an object file that is compiled with -xprofile=use.

-xreduction

N/A

Turns on reduction recognition during automatic parallelization.

-xregs=r[,r ...]

-ffixed-reg-fcall-used-reg-fcall-saved-reg

Specifies the usage of registers for the generated code.

-xrestrict[=f]

-fargument-alias-fargument-noalias-fargument-noalias-global

Treats pointer-valued function parameters as restricted pointers. Note that GCC recognizes the ISO C99 keyword restrict and performs appropriate optimizations.

-xs

N/A

Allows debugging by dbx without object files. This option causes all the debug information to be copied into the executable.

-xsafe=mem

N/A

Grants permission to use the speculative load instruction. The i386 processors do not provide such a feature.

-xsb

N/A

Creates extra symbol information for the source browser. This is specific to Sun's IDE.

-xsbfast

N/A

Creates the database for the source browser.

-xsfpconst

(-fshort-double)

Represents unsuffixed floating-point constants as single precision, instead of the default mode of double precision. GCC does not have the exact match, but -fshort-double makes double and float the same size.

-xspace

-Os

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

-xstrconst

Default

Inserts string literals into the read-only data section of the text segment instead of the default data segment. This is the default with GCC. To get the default behavior of the Sun compiler, use -fwritable-strings.

-xtarget=t

-march=cpu_type-mtune=cpu_type

Specifies the target system for instruction set and optimization.

-xtemp=dir

N/A

Sets the directory for temporary files used by the compiler. GCC uses the environment variable TMPDIR to set the directory name for temporary files.

-xtHReadvar[=o]

N/A (see comments)

Controls the implementation of thread local variables. GCC supports thread-local storage using keyword __tHRead.

-xtime

-Q, -ftime-report

Reports the time and resources used by each compilation component.

-xtransition

N/A

Issues a warning for the differences between K&R C and Sun ISO C.

-xtrigraphs

-trigraphs

Determines whether the compiler recognizes trigraph sequences as defined by the ISO C standard.

-xunroll=n

-funroll-loops-funroll-all-loops-floop-optimize

Suggests to the optimizer to unroll loops n times.

-xustr=charset

-fexec-charset=s-fwide-exec-charset=s-finput-charset=s

Supports an internationalized application that uses ISO10646 UTF-16 string literals.

-xvector[={yes|no}]

-maltivec

Enables automatic generation of calls to the vector library functions. On a PowerPC platform, GCC supports the Altivec instruction set with the option -maltivec.

-xvis

N/A

Enables the assembly language templates defined in the VIS instruction set software developer kit. This is Sun's specific feature.

-xvpara

N/A

Warns about loops that have #pragma MP directives specified when the loop may not be parallelization.

-Yc, dir

N/A

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.

-YA, dir

-Bprefix

Specifies a directory dir to search for all compiler components.

-YI, dir

-Idir
-I-

Changes the default directory searched for include files.

-YP, dir

-Ldir

Changes the default directory for finding library files.

-YS, dir

-B

Changes the default directory for startup object files.

-Zll

N/A

Creates the program database for lock_lint, but does not generate executable code.


[6] http://docs.sun.com/source/819-0494/cc_ops.app.html

4.3.3. C++ Compiler Options

Table 4-3 compares Sun Studio 10's C++ options and G++ 3.4.2's C++ options.

Table 4-3. C++ Compiler Options Comparison

Sun Studio 10 C++

GCC C++ 3.4.2

Description[7]

-386

-march=i386

Same as -xtarget=386.

-486

-march=i486

Same as -xtarget=486.

-a

N/A

Same as -xa.

-Bbinding

-Wl,-Bstatic-Wl,-dn-Wl,-non-shared-Wl,-static

Specifies whether a library binding for linking is symbolic, dynamic (shared), or static (nonshared).

-cg{89|92}

N/A

Same as -xcg{89|92}.

-compat[={4|5}]

N/A

Sets the major release compatibility mode of the compiler.

+d

-fno-default-inline

Prevents expansion of C++ inline inline functions.

-d{y|n}

-Wl,-Bstatic-Wl,-static

Specifies dynamic linking (default) or static linking.

-dalign

Several align options available; refer to the GNU GCC manual.[8]

Controls the assumptions the compiler makes about the alignment of data.

-dryrun

-###

Prints options passed but does not compile.

+e{0|1}

N/A

Controls virtual table generation.

-erroff[=t]

See -W option in GNU GCC for requesting or suppressing warnings.

Suppresses C++ compiler warning messages and has no effect on error messages.

-errtags[=a]

See -W option in GNU GCC for requesting or suppressing warnings.

Displays the message tag for each warning message of the C++ compiler front end that can be suppressed.

-errwarn[=t]

See -pedantic option in GNU GCC for requesting or suppressing warnings.

Causes the C++ compiler to exit with a failure status for the given warning messages.

-fast

-Ox

A starting point for tuning an executable for maximum runtime performance.

-features=a[,a...]

N/A

Enables/disables various C++ language features named in a comma-separated list.

-filt[=filter[,filter..]]

N/A

Controls the filtering that the compiler normally applies to linker and compiler error messages.

-flags

--help

Displays a brief description of each compiler option.

-fnonstd

N/A

Causes hardware traps to be enabled for floating-point overflow, division by 0, and invalid operations exceptions.

-fns[={yes|no}]

N/A

Turns on SPARC nonstandard floating-point mode.

-fprecision=p

-fsingle-precision-constant (see comment)

Initializes the rounding-precision mode bits in the floating-point Control Word to single, double, or extended. GCC does not have a direct equivalent, but -fsingle-precision-constant forces the compiler to treat floating-point constant as single precision instead of convert-converting it to double precision constant.

-fround=r

-frounding-math (see comment)

Sets the IEEE 754 rounding mode. The default IEEE mode is round-to-nearest. This is also the case on Linux, but there is no option to select mode. Consider -frounding-math in GCC.

-fsimple[=n]

N/A

Allows the optimizer to make simplifying assumptions about floating-point arithmetic. GCC does not have the exact match. Consider these flags for floating-point optimizations not compliant with IEEE or ISO: -ffloat-store, -ffast-math, -fno-math-error, -funsafe-math-optimizations, -ffinite-math-only, -fno-trapping-math.

-fstore

-ffloat-store

Causes floating-point variables not to be stored in registers.

-ftrap=t[,t...]

-fno-trapping-math (see comment)

Sets the IEEE trapping mode in effect at startup but does not install a SIGFPE handler. GCC does not have the direct equivalent, but -fno-trapping-math disables all user-visible traps, including division by 0, overflow, underflow, inexact result, and invalid operation.

-G

-Wl,-shared

Builds a dynamic shared library instead of an executable file.

-g

-g

Generates debug info, disables inlining.

-g0

N/A

Generates debug info, does not disable inlining.

-H

-H

Prints to standard error the path name of each file included during the compilation.

-h[ ]name

-hname, -Wl,-soname, name

Gives a name to a shared dynamic library to have different versions of a library.

-help

--help -v

Displays online help information.

-I-

-I-

Changes the include file search rules.

-i

N/A

Ignores any LD_LIBRARY_PATH setting.

-inline

N/A

Same as -xinline. Attempts to inline only those specified functions.

-instances=a

-fno-implicit-templates, -fno-implicit-inline-templates, -frepo

Controls the placement and linkage of template instances.

-instlib=filename

N/A

Inhibits the generation of template instances that are duplicated in a library.

-KPIC

-fPIC

Generates position-independent code (large model).

-Kpic

-fpic

Generates position-independent code (small model).

-keeptmp

-save-temps

Keeps temporary files created during compilation.

-libmieee

N/A

Same as -xlibmieee. Forces IEEE 754-style return values for math routines in exceptional cases.

-libmil

N/A

Same as -xlibmil. Inlines some library routines for faster execution.

-library=l[,l...]

-nodefaultlibs, -nostdlib (see comment)

Incorporates specified CC-provided libraries into compilation and linking.

-mc

N/A

Removes duplicate strings from the .comment section of the object file.

-migration

N/A

Explains where to get information about migrating source code that was built for earlier versions of the compiler.

-misalign

(implicit) (see comment)

Assumes only byte alignment. This option is not necessary for the IA-32 because the processor handles alignment by itself.

-mr[, string]

N/A

Removes all strings from the .comment section of the object file and, if string is supplied, places string in that section.

-mt

-D_REENTRANT-pthread

Compiles and links for multithreaded code. On Linux, -pthread adds support for multithreading with the pthreads library.

-native

-march=cpu-type

Optimizes code using host-specific code.

-noex

-fno-enforce-eh-specs (see comment)

Same as -features=no%except. Does not allow C++ exceptions. g++ does not have the exact match, but consider -fno-enforce-eh-specs.

-nofstore

(implicit) (see comment)

Disables forced precision of an (see comment) expression. GCC has the option -ffloat-store, which has the opposite meaning of -nofstore.

-nolib

-nostdlib

Same as -xnolib. Disables linking with default system libraries.

-nolibmil

N/A (see comment)

Same as -xnolibmil. Cancels -xlibmil on the command line. GCC does not have the exact match, but there are -fno-default-inline and -fno-inline.

-noqueue

N/A (see comment)

Disables license queuing. This is not necessary for GCC.

-norunpath

N/A (see comment)

Does not build a runtime search path for shared libraries into the executable. In Linux, if -rpath is not used when building an executable, the variable LD_RUN_PATH will be used if it is defined.

-O

-O3

The macro expanding to -xO3.

-Olevel

-Olevel

Optimizes to yield higher application performance.

-o filename

-o filename

Sets the name of the output file or the executable file to filename.

+p

N/A

Ignores nonstandard preprocessor asserts.

-P

-E

Only preprocesses source; does not compile.

-p

-p

Prepares object code to collect data for profiling with prof.

-pentium

-march=cpu-type

Replace with -xtarget=Pentium.

-pg

-pg

Compiles self-profiling code to collect data for profiling with gprof.

-PIC

-fPIC

Generates position-independent code (large model).

-pic

-fpic

Generates position-independent code (small model).

-pta

See comment

Same as -template=wholeclass. Instantiates a whole template class, rather than only those functions that are used.

-ptipath

N/A

Specifies an additional search directory for template source.

-pto

See comment

Same as -instances=static. This option is already deprecated.

-ptr

See comment

Obsolete. Ignored by the compiler.

-ptv

N/A

Same as -verbose=template. Turns on the template instantiation verbose mode.

-Qoption

N/A

Passes option to the compilation phase.

-qoption

N/A

Same as -Qoption.

-qp

-p/-profile

Same as -p.

-Qproduce sourcetype

-E, -c, -S

Causes the CC driver to produce output of the type sourcetype (.i, .o, .s).

-qproduce sourcetype

-E, -c, -S

Same as -Qproduce.

-Rpathname [:pathname...]

-Wl, -rpath

Builds dynamic library search paths into the executable file. This option is passed to ld.

-readme

N/A

Same as -xhelp=readme.

-S

-S

Compiles and generates only assembly code.

-s

-s

Strips the symbol table from the executable file.

-sb

N/A

Replace with -xsb. Creates extra symbol for the source browser. This is specific to Sun's IDE.

-sbfast

N/A

Same as -xsbfast. Produces only source browser info; no compilation.

-staticlib=l [,l...]

-static (see comment)

Indicates which C++ libraries are to be linked statically. There is no exact match in g++, but there is -static, which is equivalent to -staticlib=all.

-sync_stdio=[yes|no]

N/A

Turn on/off the synchronization between iostreams and stdio.

-temp=path

-save-temps

Defines the directory for temporary files.

-template=opt[opt...]

N/A (see comment)

Enables/disables various template options. There is no exact match in g++, but there are -frepo, -fno-implicit-templates.

-time

-Q, -ftime-report

Reports the time and resources used by each compilation component.

-Uname

-Uname

Deletes initial definition of the preprocessor symbol name.

-unroll=n

-funroll-loops (see comment)

Same as -xunroll=n. Unrolls loop n times. g++ has no exact match, but there is -funroll-loops.

-V

--version

Same as -verbose=version. Prints the name and version number.

-v

-v

Same as -verbose=diags. Prints the command line for each compilation pass.

-vdelx

N/A

Generates a call to _vector_deletex_ instead of _vector_delete_. This option is deprecated.

-verbose=v[,v...]

--version, -v

Controls compiler verbosity. g++ does not have the exact match, but -v and --version partially give the same functionality.

+w

-Wabi, -Wctor-dtor-privacy, -Wnon-virtual-dtor, …
(see comments)

Identifies code that might have unintended consequences. g++ provides various options for warning specifically for C++.

+w2

See comment

Emits warnings by +w plus warning about technical violation that reduces portability. See comments in +w for g++.

-w

-w

Suppresses most warning messages.

-Xm

N/A

Same as -features=iddollar. Allow a $ symbol as a noninitial identifier character.

-xa

-fprofile-arcs-ftest-coverage

Emits information for tcov tool. On Linux, use GNU version gcov to process the output.

-xalias_level[=n]

N/A

Compiler uses this option to determine what assumptions it can make to perform optimizations using type-based alias analysis.

-xar

N/A

Creates archive libraries.

-xarch=isa

-march=isa

Specifies the target instruction set architecture.

-xautopar

N/A

Turns on automatic parallelization for multiple processors.

-xbuiltin[={%all | %none}]

N/A

Substitutes intrinsic functions or inline system functions where profitable for performance.

-xcache=c

N/A

Defines the cache properties for use by the optimizer.

-xcg89

N/A

Same as -xtarget=ss2.

-xcg92

N/A

Same as -xtarget=ss1000.

-xchar[=o]

-funsigned-char or -fsigned-char

Treats the char type as signed or unsigned.

-xcheck[=i]

N/A

Adds a runtime check for stack overflow.

-xchip=c

-march

Specifies the target processor for use by the optimizer.

-xcode=a

N/A

Specifies code address space. There is no exact match in GCC. However, -xcode=pic13 is equivalent to -fpic. -xcode=pic32 is equivalent to -fPIC.

-xcrossfile[=n]

-funit-at-a-time

Enables optimization and inlining across source files.

-xdepend=[yes|no]

-floop-optimize, -falign-loops

Analyzes loops for inter-iteration data dependencies and does loop restructuring.

-xdumpmacros[=value[,value...]]

-gvms3, -dD

Provides information such as macro defines, undefines, and instances of usage.

-xe

-fsyntax-only

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

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

N/A

Enables optimal reordering of functions and variables by the linker.

-xhelp=flags

--help -v

Displays online help information.

-xhelp=readme

N/A

Displays contents of the online readme file.

-xia

N/A

Links the appropriate interval arithmetic libraries and sets a suitable floating-point environment.

-xildoff

N/A

Turns the incremental linker off.

-xildon

N/A

Turns the incremental linker on.

-xinline[=func_spec[,func_spec...]]

N/A

Specifies which user-written routines can be inlined by the optimizer at -x03 levels or higher.

-xipo[={0|1|2}]

-funit-at-a-time

Performs interprocedural optimizations.

-xjobs=n

N/A

Sets how many processes the compiler creates to complete its work.

-xlang=[language[,language]]

N/A

Includes the appropriate runtime libraries and ensures the proper runtime environment for the specified language.

-xldscope={v}

N/A

Changes the default linker scoping for the definition of extern symbols.

-xlibmieee

N/A

Forces IEEE 754-style return values for math routines in exceptional cases.

-xlibmil

N/A

Inlines some library routines for faster execution.

-xlibmopt

N/A

Enables the compiler to use a library of optimized math routines.

-xlic_lib=sunperf

N/A

Links in the Sun-supplied performance libraries.

-xlicinfo

N/A

Returns information about the licensing system.

-xlinkopt[=level]

N/A

Instructs the compiler to perform link-time optimizations on relocatable object files.

-xM

-M

Displays makefile dependencies.

-xM1

-MM (see comment)

Shows dependencies like -xM, but excludes /usr/include files. The option -MM does something similar for GCC, but GCC avoids dependencies for files from the system directories, or header files that are included, directly or indirectly, from such a header.

-xMerge

N/A

Merges data segments into text segments.

-xmaxopt[=v]

N/A

Limits the level of pragma opt to the level specified.

-xmemalign=ab

N/A

Specifies max assumed memory alignment and behavior of misaligned data accesses.

-xnativeconnect[=i]

N/A

Enables the shared library to interface with Java code.

-xnolib

-nostdlib

Does not link any default libraries.

-xnolibmil

N/A

Does not inline math library routines. GCC does not have the exact match, but there are -fno-default-inline and -fno-inline.

-xnolibmopt

N/A

Prevents the use of an optimized math library by the compiler.

-xOlevel

-O1, -O2, -O3

Selects the optimization levels. GCC does not have the fourth and fifth optimization levels.

-xopenmp[=i]

N/A

Enables explicit parallelization with OpenMP directives. The implementation of OpenMP for GNU C, C++, and FORTRAN compilers is under development.

-xpagesize=n

N/A

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

-xpagesize_heap=n

N/A

Sets the page size in memory for the heap.

-xpagesize_stack=n

N/A

Sets the page size in memory for the stack.

-xpch=v

Default (see comment)

Activates the precompiled header feature. (see comment) To create a precompiled header file with GCC, you simply have to compile it as you would with any other file. GCC will search for the precompiled header with .gch appended.

-xpchstop=file

N/A

Specifies the last include file of the viable prefix for the precompiled header file.

-xpg

-pg

Prepares the object code to collect data for profiling with gprof.

-xport64[=(v)]

N/A

Warns against problems common when code is ported from 32-bit to 64-bit architecture.

-xprefetch[=a[,a...]]

N/A

Enables prefetch instructions on those architectures that support prefetch.

-xprefetch_auto_type=a

N/A

Determines whether 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.

-xprefetch_level[=i]

N/A

Controls the aggressiveness of automatic insert of prefetch instructions as determined with -xprefetch=auto.

-xprofile=collect

-fprofile-generate

Collects and saves execution-frequency data to use in subsequent runs to improve performance.

-xprofile=use

-fprofile-use

Uses the execution-frequency data generated and saved from a previous execution.

-xprofile_ircache[=path]

N/A

Improves compilation time during the use phase.

-xprofile_pathmap

N/A

Locates profile data for an object file that is compiled with -xprofile=use.

-xregs=r[, r ...]

-ffixed-reg-fcall-used-reg-fcall-saved-reg

Specifies the usage of registers for the generated code.

-xrestrict[=t]

-fargument-alias-fargument-noalias-fargument-noalias-global

Treats pointer-valued function parameters as restricted pointers. Note that GCC recognizes the ISO C99 keyword restrict and performs appropriate optimizations.

-xs

N/A

Allows debugging by dbx without object files. This option causes all the debug information to be copied into the executable.

-xsafe=mem

N/A

Grants permission to use the speculative load instruction. The i386 processors do not provide such a feature.

-xsb

N/A

Creates extra symbol information for the source browser. This is specific to Sun's IDE.

-xsbfast

N/A

Creates the database for the source browser.

-xspace

-Os

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

-xtarget=t

-march=cpu-type-mtune=cpu-type

Specifies the target platform for instruction set and optimization.

-xtHReadvar[=o]

N/A (see comment)

Controls the implementation of thread local variables. GCC supports thread-local storage using keyword __tHRead.

-xtime

-Q, -ftime-report

Reports the time and resources used by each compilation component.

-xtrigraphs[={yes|no}]

-trigraphs

Determines whether the compiler recognizes trigraph sequences as defined by the ISO C standard.

-xunroll=n

-funroll-loops-funroll-all-loops-floop-optimize (see comment)

Suggests to the optimizer to unroll loops n times. G++ does not have the exact match, but there are -funroll-loops, -funroll-all-loops, -floop-optimize.

-xustr={ascii_utf16_ushort|no}

-fexec-charset=s-fwide-exec-charset=s
-finput-charset=s

Supports an internationalized application that uses ISO10646 UTF-16 string literals.

-xvector[={yes|no}]

-maltivec (see comment)

Enables automatic generation of calls to the vector library functions. On a PowerPC platform, GCC supports the Altivec instruction set with the option -maltivec.

-xvis[={yes|no}]

N/A

Enables the assembly language templates defined in the VIS instruction set software developer kit. This is Sun's specific feature.

-xwe

-pedantic-errors

Converts warnings to errors.

-Yc, path

N/A

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.

-z[ ]arg

-Wl, option, -Xlinker option

Link editor option.


[7] This description is based on Sun Studio 10 C++ users guide unless otherwise stated.

[8] http://gcc.gnu.org/onlinedocs/

4.3.4. Template Instantiation in GNU g++

According to the document "Using the GNU Compiler Collection,"[9] the GNU g++ compiler provides two automated approaches to template instantiationthe Borland or Cfront model. When used with GNU ld version 2.8 or later on an ELF system such as GNU/Linux or Solaris, g++ supports the Borland model. On other systems, g++ implements neither automatic instantiation approach. For all applications that use template instantiation, the best approach is to modify the code to include template definitions to make them available at one or more points of instantiation; usually this is a simple as adding #include <temp_methods.c> to the end of each template header.

[9] http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Template-Instantiation.html#Template-Instantiation

Example 4-1 shows a sample code using this method.

Example 4-1. Template Instantiation in GNU G++

main.C

#include "stack.h" int main() {     Stack<int, 60> s;     int j;     int i;     s >> j;     s << j;     i = j;     return (0); } 


stack.h

#ifndef STACK_INCLUDED #define STACK_INCLUDED typedef enum{tr, fl} Bool; template<class Item, int size> class Stack {     public:         int operator << (Item item);         int operator >> (Item& item);         Stack(Bool p=fl) {top = 0;}     private:         Item stack[size];         int top; }; #endif /* STACK_INCLUDED */ 


stack.C

#include "stack.h" template<class Item, int size> int Stack<Item, size>::operator << (Item item) {     if (top >= size) return 0;     stack[top++] = item;     return 1; } template <class Item, int size> int Stack<Item, size>::operator >> (Item& item) {     if(top<=0) return 0;     item = stack[--top];     return 1; } 


When compiled with the Sun Studio's CC compiler, the files main.C, stack.C, and stack.h produce an executable without any error:

$ CC -o main main.C $ ./main 


When compiled on Linux using g++, it results in the following compiler error:

$ g++ -o main main.C /tmp/ccicEJmr.o(.text+0x45): In function 'main': : undefined reference to 'Stack<int, 60>::operator>>(int&)' /tmp/ccicEJmr.o(.text+0x5d): In function 'main': : undefined reference to 'Stack<int, 60>::operator<<(int)' collect2: ld returned 1 exit status 


The preceding g++ compiler error is corrected by modifying stack.h to include stack.C, as in the following code listing:

#ifndef STACK_INCLUDED #define STACK_INCLUDED typedef enum{tr, fl} Bool; template<class Item, int size> class Stack {     public:         int operator << (Item item);         int operator >> (Item& item);         Stack(Bool p=fl) {top = 0;}     private:         Item stack[size];         int top; }; #include "stack.C"             /* include stack.C */ #endif /* STACK_INCLUDED */ 


Then compile with g++:

$ g++ -o main main.C 


4.3.5. Building 32- or 64-bit Objects

To build a 64-bit object in GCC, use the compiler flag -m64. On the IA-32 platform, GCC produces the 32-bit objects by default. For other platforms, use the -m32 flag to instruct GCC to build the 32-bit object.

4.3.6. Compiler Optimization and Performance Options

Table 4-4 compares compiler optimization and performance options between Solaris and Linux.

Table 4-4. Compiler OptimizationLevels and Descriptions

Solaris Level

Solaris Description[10]

GCC Level

GCC Description[11]

-xO1

Performs basic local optimization.

-O or -O1

Tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.

-xO2

Does basic local and global optimization. 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.

-O2

Performs nearly all supported optimizations that do not involve a space-speed trade-off. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.

-xO3 (-O)

Performs like -xO2, but also optimizes reference or definition for external variables.

-O3

Turns on all optimizations specified by -O2 and also turns on the -finline-functions, -fweb, and -frename-registers options.

-xO4

Performs like -xO3, but also automatically inline functions contained in the same file.

N/A

N/A

-xO5

Attempts to generate the highest level of optimization.

N/A

N/A


[10] Sun Studio 10: User's Guide

[11] GCC 3.4.2 manual

4.3.7. Name Space Selection on Linux Platform

Linux header files and libraries offer support for several name spaces. They are described in Table 4-5.

Table 4-5. Linux Name Space Table

Linux Definitions[12]

Description

__STRICT_ANSI__

ISO Standard C.

_ISOC99_SOURCE

Extensions to ISO C89 from ISO C99.

_POSIX_SOURCE

IEEE Std 1003.1.

_POSIX_C_SOURCE

If ==1, like _POSIX_SOURCE;
if >=2, add IEEE Std 1003.2;
if >=199309L, add IEEE Std 1003.1b-1993;
if >=199506L, add IEEE Std 1003.1c-1995;
if >=200112L, all of IEEE 1003.1-2001.

_XOPEN_SOURCE

Includes POSIX and XPG things.
Set to 500 if Single UNIX Specification version 2 onformance is wanted, to 600 for the SUSv3.

_XOPEN_SOURCE_EXTENDED

XPG things and X/Open UNIX extensions.

_LARGEFILE_SOURCE

Some more functions for correct standard I/O.

_LARGEFILE64_SOURCE

Additional functionality from LFS for large files.

_FILE_OFFSET_BITS=N

Select default filesystem interface.

_BSD_SOURCE

ISO C, POSIX, and 4.3BSD things.

_SVID_SOURCE

ISO C, POSIX, and SVID things.

_GNU_SOURCE

All of the above, plus GNU extensions.

_REENTRANT

Select additionally reentrant object.

_ThrEAD_SAFE

Same as _REENTRANT; often used by other systems.

_FORTIFY_SOURCE

If set to numeric value > 0, additional security measures are defined, according to level.


[12] From /usr/include/features.h in Linux




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net