cc Compiler Options |
2 |
![]() |
If you are porting a K&R C program to ANSI C, make special note of the section on compatibility flags, "-X[a|c|s|t]" on page 23. Using them makes the migration to ANSI C easier. Also, Refer to the book titled Making the Transition to ANSI C.
Option Syntax
The syntax of the cc command is:% cc [options] filenames [libraries]...
where:
Options noted as being unique to one or more platforms are accepted without error and ignored on all other platforms. For an explanation of the typographic notations used with the options and arguments, refer to Table P-5 on page xxix.
-#
Turns on verbose mode, showing each component as it is invoked. -###
Shows each component as it would be invoked, but does not actually execute it. -Aname[(tokens)]
Associates name as a predicate with the specified tokens as if by a #assert preprocessing directive.Preassertions:
-Bdynamic causes the link editor to look for files named libx.so and then for files named libx.a when given the -lx option.
-Bstatic causes the link editor to look only for files named libx.a. This option may be specified multiple times on the command line as a toggle. This option and its argument are passed to ld.
Predefinitions (not valid in -Xc mode):
_ _sun
_ _unix
_ _SUNPRO_C=0x400
_ _`uname -s`_`uname -r` (example: _ _SunOS_5_4)
_ _sparc (SPARC)
_ _i386 (Intel)
_ _BUILTIN_VA_ARG_INCR
_ _SVR4
_ _LITTLE_ENDIAN (PowerPC)
_ _ppc (PowerPC)The following is predefined in -Xa and -Xt modes only:
_ _RESTRICTThe compiler also predefines the object-like macro
_ _PRAGMA_REDEFINE_EXTNAME,to indicate the pragma will be recognized.
-dn specifies static linking in the link editor.
This option and its arguments are passed to ld(1).
-erroff=t
Suppresses cc warning messages. Has no effect on error messages.
The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.
-errtags=a
Displays the message tag for each error message. -fast
Selects the optimum combination of compilation options for speed. This should provide close to the maximum performance for most realistic applications. Modules compiled with -fast must also be linked with -fast. -fast
with the appropriate xtarget option. For example: cc -fast -xtarget=ultra ...
For C modules that depend on exception handling specified by SVID, follow
-fast by -nolibmil: % cc -fast -nolibmil
With -xlibmil, exceptions may not be noted by setting errno or calling matherr(3m).-fast
differ across platforms:
-fast acts like a macro expansion on the command line. Therefore, the optimization level and code generation option aspects can be overridden by following -fast with the desired optimization level or code generation option. As far as optimization level is concerned, compiling with the -fast -xO4 pair is like compiling with the -xO2 -xO4 pair. The latter specification takes precedence.
-fd
Reports K&R-style function definitions and declarations. -flags
Prints a summary of each compiler option. -fnonstd
Causes nonstandard initialization of floating-point arithmetic hardware. In addition, the -fnonstd option causes hardware traps to be enabled for floating-point overflow, division by zero, and invalid operations exceptions. These are converted into SIGFPE signals; if the program has no SIGFPE handler, it terminates with a memory dump.
(SPARC) Synonym for -fns -ftrap=common.
-fns
(SPARC) Turns on the SPARC nonstandard floating-point mode. -fprecision=<p>
(Intel) -fprecision={single, double , extended} Initializes the rounding precision mode bits in the Floating-point Control Word to single (24 bits), double (53 bits), or extended (64 bits), respectively. The default floating-point rounding-precision mode is extended. -fround=r
Sets the IEEE 754 rounding mode that is established at runtime during the program initialization. -fsimple[=n]
Allows the optimizer to make simplifying assumptions concerning floating-point arithmetic.
To turn off this option, use the -nofstore option.
t is a comma-separated list that consists of one or more of the following: %all, %none, common, [no%]invalid, [no%]overflow, [no%]underflow, [no%]division, [no%]inexact.
The default is -ftrap=%none.
This option sets the IEEE 754 trapping modes that are established at program initialization. Processing is left-to-right. The common exceptions, by definition, are invalid, division by zero, and overflow.
Example: -ftrap=%all,no%inexact means set all traps, except inexact.
The meanings are the same as for the ieee_flags subroutine, except that:
This option also uses the incremental linker; see -xildon and
When used with the -O option, a limited amount of debugging is available. The combination, -xO4 -g, turns off the inlining that you usually get with
Here, the program sample.c includes the files, stdio.h and math.h; math.h includes the file, floatingpoint.h, which itself includes functions that use sys/ieeefp.h:
% cc -H sample.c |
-h name
Assigns a name to a shared dynamic library as a way to have different versions of a library. In general, the name after -h should be the same as the file name given after the -o option. The space between -h and name is optional. -Idir
Adds dir to the list of directories that are searched for #include files with relative file names, that is, those not beginning with a / (slash). -i
Passes the option to the linker to ignore any LD_LIBRARY_PATH setting. -keeptmp
Retains temporary files created during compilation instead of deleting them automatically. -KPIC
Produces position-independent code for use in shared libraries. Each reference to a global datum is generated as a dereference of a pointer in the global offset table. Each function call is generated in pc-relative addressing mode through a procedure linkage table. -Kpic
Produces position-independent code for use in shared libraries.
The easiest way to tell whether or not a .o file has been compiled with -Kpic or -KPIC is with the nm command:
% nm file.o | grep _GLOBAL_OFFSET_TABLE_ |
A .o file containing position-independent code contains an unresolved external reference to _GLOBAL_OFFSET_TABLE_, as indicated by the letter U.
-Ldir
Adds dir to the list of directories searched for libraries by ld(1). This option and its arguments are passed to ld. -lname
Links with object library libname.so, or libname.a. The order of libraries in the command-line is important, as symbols are resolved from left to right. -mc
Removes duplicate strings from the .comment section of the object file. When you use the -mc flag, mcs -c is invoked. -misalign
(SPARC, PowerPC) Informs the compiler that the data in your program is not properly aligned, as in the following code:
char b[100]; } |
Thus, very conservative loads and stores must be used for data, one byte at a time. Using this option can cause significant degradation in the performance when you run the program. If you compile and link in separate steps, compiling with the -misalign option requires the option on the link step as well.
-misalign2
(SPARC, PowerPC) Like -misalign, assumes that data is not properly aligned, but that data is at least halfword-aligned. Though conservative uses of loads and stores must be used for data, the performance degradation when running a program is less than that seen for -misalign. If you compile and link in separate steps, compiling with the -misalign2 option requires the option on the link step as well. -mr
Removes all strings from the .comment section. When you use this flag, mcs -d is invoked. -mr,string
Removes all strings from the .comment section and inserts string in that section of the object file. If string contains embedded blanks, it must be enclosed in quotation marks. A null string results in an empty .comment section. This option is passed as -d "string" to mcs. -mt
Passes -D_REENTRANT to the preprocessor. Appends
-lthread. If you are doing your own multithread coding, you must use this option in the compile and link steps. To obtain faster execution, this option requires a multiprocessor system. On a single-processor system, the resulting executable usually runs more slowly with this option. -native
Ascertains which code-generation options (SPARC) or which processor (Intel) (PowerPC) are available on the machine running the compiler, and directs the compiler to generate code targeted for that machine. -nofstore
(Intel) Does not convert the value of a floating-point expression or function to the type on the left-hand side of an assignment, when that expression or function is assigned to a variable or is cast to a shorter floating-point type; rather, it leaves the value in a register. See also "-fstore" on page 14.
-noqueue
Instructs the compiler not to queue this compile request if a license is not available. Under normal circumstances, if no license is available, the compiler waits until one becomes available. With this option, the compiler returns immediately. -O
Same as -xO2. -o filename
Names the output file filename (as opposed to the default, a.out). filename cannot be the same as sourcefile, since cc does not overwrite the source file. This option and its arguments are passed to ld(1). -P
Runs the source file through the C preprocessor only. It then puts the output in a file with a .i suffix. Unlike -E, this option does not include preprocessor-type line number information in the output. See also the -E option. -p
Prepares the object code to collect data for profiling with prof(1). This option invokes a runtime recording mechanism that produces a mon.out file at normal termination. -Q[y|n]
Emits or does not emit identification information to the output file. -Qy is the default. -qp
Same as -p. -Rdir[:dir]
Passes a colon-separated list of directories used to specify library search directories to the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker. -S
Directs cc to produce an assembly source file but not to assemble the program. -s
Removes all symbolic debugging information from the output object file. This option cannot be specified with -g. -Uname
Removes any initial definition of the preprocessor symbol name. This option is the inverse of the -D option. You can give multiple -U options. -V
Directs cc to print the name and version ID of each pass as the compiler executes. -v
Directs the compiler to perform stricter semantic checks and to enable other lint-like checks. For example, the code:
#include <stdio.h> main(void) { printf("Solipsism isn't for everybody.\n"); } |
compiles and executes without problem. With -v, it still compiles; however, the compiler displays this warning:
"solipsism.c", line 5: warning: function has no return
-v does not give all the warnings that lint(1) does. Try running the above example through lint.
statement: main
-Wc,arg
Passes the argument arg to a specified component c. Each argument must be separated from the preceding only by a comma. All -W arguments are passed after the regular command-line arguments. A comma can be part of an argument by escaping it by an immediately preceding \ (backslash) character.
-w
Suppresses compiler warning messages. -X[a|c|s|t]
The -X (note uppercase X) options specify varying degrees of compliance to the ANSI C standard. -Xa is the default mode.
Invokes a runtime recording mechanism that creates a .d file for every .c file at normal termination. The .d file accumulates execution data for the corresponding source file. tcov(1) can then be run on the source file to generate statistics about the program. Since this option entails some optimization, it is incompatible with -g.
If set at compile-time, the TCOVDIR environment variable specifies the directory where the .d files are located. If this variable is not set, the .d files remain in the same directory as the .c files.
The -xprofile=tcov and the -xa options are compatible in a single executable. That is, you can link a program that contains some files which have been compiled with -xprofile=tcov, and others with -xa. You cannot compile a single file with both options.
a must be one of: generic, v7, v8a, v8, v8plus, v8plusa, 386, pentium_pro, ppc, ppc_nofma.
Although this option can be used alone, it is part of the expansion of the
This option limits the instructions generated to those of the specified architecture, and allows the specified set of instructions. The option does not guarantee the specified set is used; however, under optimization, the set is usually used.
If this option is used with optimization, the appropriate choice can provide good performance of the executable on the specified architecture. An inappropriate choice can result in serious degradation of performance.
v7, v8, and v8a are all binary compatible. v8plus and v8plusa are binary compatible with each other and forward, but not backward. For any particular choice, the generated executable can run much more slowly on earlier architectures (to the left in the above list).
-xautopar
(SPARC) Turns on automatic parallelization for multiple processors. Does dependence analysis (analyze loops for inter-iteration data dependence) and loop restructuring. If optimization is not at -xO3 or higher, optimization is raised to -xO3 and a warning is emitted.
% psrinfo 0 on-line since 01/12/95 10:41:54 1 on-line since 01/12/95 10:41:54 2 on-line since 01/12/95 10:41:54 3 on-line since 01/12/95 10:41:54 |
To request a number of processors, set the PARALLEL environment variable. The default is 1.
c must be one of the following:
si |
The size of the data cache at level i, in kilobytes |
li |
The line size of the data cache at level i, in bytes |
ai |
The associativity of the data cache at level i |
Although this option can be used alone, it is part of the expansion of the
-xtarget option; its primary use is to override a value supplied by the
-xtarget option.
Example: -xcache=16/32/4:1024/32/1 specifies the following:
Level 1 cache has: 16K bytes 32 bytes line size 4-way associativity |
Level 2 cache has: 1024K bytes 32 bytes line size Direct mapping associativity |
-xCC
Accepts the C++-style comments. In particular, // can be used to indicate the start of a comment. -xcg[89|92]
(SPARC).
-xarch=v8 -xchip=super -xcache=16/32/4:1024/32/1. -xchip=c
Specifies the target processor for use by the optimizer. 603
, 604
.
-xtarget option; its primary use is to override a value supplied by the
-xtarget option.
Only effective with
-xO4
or -xO5
, the compiler is allowed to analyze all the files on the command line as if they had been concatenated into a single file.
Dependency analysis is also included with -xautopar or -xparallel. The dependency analysis is done at compile time.
Dependency analysis may help on single-processor systems. However, if you try -xdepend on single-processor systems, you should not use either
Parallelization options require a WorkShop license. To get faster code, this option requires a multiprocessor system. On a single-processor system, the generated code usually runs slower.
If you indentify a loop for parallelization, and the loop has dependencies, you can get incorrect results, possibly different ones with each run, and with no warnings. Do not apply an explicit parallel pragma to a reduction loop. The explicit parallelization is done, but the reduction aspect of the loop is not done, and the results can be incorrect.
In summary, to parallelize explicitly:
#pragma MP taskloop for (j=0; j<1000; j++){ ... } |
If you use -xexplicitpar and compile and link in one step, then linking automatically includes the microtasking library and the threads-safe C runtime library. If you use -xexplicitpar and compile and link in separate steps, then you must also link with -xexplicitpar.
-xF
Enables performance analysis of the executable using the Analyzer. (See the analyzer(1) man pages.) Produces code that can be reordered at the function level. Each function in the file is placed in a separate section; for example, functions foo() and bar() are placed in the sections .text%foo and .text%bar, respectively. Function ordering in the executable can be controlled by using -xF in conjunction with the -M option to ld (see ld(1)). This option also causes the assembler to generate some debugging information in the object file, necessary for data collection. -xhelp=f
Displays on-line help information. -xildoff
Turns off the incremental linker and forces the use of ld. This option is the default if you do not use the -g option, or you do use the -G option, or any source files are present on the command line. Override this default by using the -xildon option. -xildon
Turns on the incremental linker and forces the use of ild in incremental mode. This option is the default if you use the -g option, and you do not use the -G option, and there are no source files present on the command line. Override this default by using the -xildoff option. -xinline=[f1,...,fn]
Tries to inline only those named in the list f1 to fn for user-written routines. The list is a comma-separated list of functions and subroutines.
cc -o pgx pgx.c -xlic_lib=sunprefThis option, like -l, should appear at the end of the command line, after source or object filenames.
Parallelization options require a WorkShop license. To get faster code, this option requires a multiprocessor system. On a single-processor system, the generated code usually runs slower.
For example:
#include <unistd.h> void main(void) {} |
-xM1
Collects dependencies like -xM, but excludes /usr/include files.For example:
more hello.c #include<stdio.h> main() { (void)printf("hello\n"); } cc -xM hello.c hello.o: hello.c hello.o: /usr/include/stdio.h |
Compilng with -xM1 does not report header file dependencies:
cc -xM1 hello.c hello.o: hello.c |
-xMerge
Merges data segments into text segments. Data initialized in the object file produced by this compilation is read-only and (unless linked with ld -N) is shared between processes. -xnolib
Does not link any libraries by default; that is, no -l options are passed to ld. Normally, the cc driver passes -lc to ld.% cc test.c -xnolib -Bstatic -lm -Bdynamic -lc
links libm statically and the other libraries dynamically. -xnolibmil
Does not inline math library routines. Use it after the
-fast option. For example: % cc -fast -xnolibmil.... -xO[1|2|3|4|5]
Optimizes the object code. Specifying -xO is equivalent to specifying -xO2.
If you optimize at -xO3 or -xO4 with very large procedures (thousands of lines of code in the same procedure), the optimizer may require a large amount of virtual memory. In such cases, machine performance may degrade.
f() { } |
int f(void); |
-xparallel
(SPARC) Parallelizes loops both automatically by the compiler and explicitly specified by the programmer. The -xparallel option is a macro, and is equivalent to specifying all three of -xautopar, -xdepend, and
-xexplicitpar. With explicit parallelization of loops, there is a risk of producing incorrect results. If optimization is not at -xO3 or higher, optimization is raised to -xO3 and a warning is issued.
-xparallel -xpentium
(Intel) Optimizes for the PentiumTM processor. -xpg
Prepares the object code to collect data for profiling with gprof(1). It invokes a runtime recording mechanism that produces a gmon.out file at normal termination. -xprofile=p
Collects data for a profile or uses a profile to optimize.
collect:
name, the name is optional and may be used to specify the name of the program.
Code instrumentation is performed similarly to that of the -xa option, but .d files are no longer generated. Instead, a single file is generated, the name of which is based on the final executable. For example, if the program is run out of /foo/bar/myprog.profile, the data file is stored in /foo/bar/myprog.profile/myprog.tcovd.
-xreduction
(SPARC) Turns on reduction recognition during automatic parallelization.
-xreduction must be specified with -xautopar, or -xparallel. -xregs=r
(SPARC) Specifies the usage of registers for the generated code.
The default is -xregs=appl,float.
-xrestrict=f
(SPARC) Treats pointer-valued function parameters as restricted pointers. f is a comma-separated list that consists of one or more function parameters, %all, or %none.
This command-line option can be used on its own, but it is best used with optimization. For example, the command:
%cc -xO3 -xrestrict=%all prog.c
treats all pointer parameters in the file prog.c as restricted pointers. The command:%cc -xO3 -xrestrict=agc prog.c
treats all pointer parameters in the function agc in the file prog.c as restricted pointers.
-xrestrict=%all. -xs
Disables Auto-Read for dbx. Use this option in case you cannot keep the .o files around. It passes the -s option to the assembler. -xsafe=mem
(SPARC) Allows the compiler to assume no memory-based traps occur. -xsb
Generates extra symbol table information for the SourceBrowser.This option is not valid with the -Xs mode of the compiler. -xsbfast
Creates the database for the SourceBrowser. Does not compile source into an object file. This option is not valid with the -Xs mode of the compiler. -xsfpconst
Represents unsuffixed floating-point constants as single precision, instead of the default mode of double precision. Not valid with -Xc. -xspace
Does no optimizations or parallelization of loops that increase code size. -xstrconst
Inserts string literals into the read-only data section of the text segment instead of the default data segment. -xtarget=t
Specifies the target system for instruction set and optimization.
The performance of some programs may benefit by providing the compiler with an accurate description of the target computer hardware. When program performance is critical, the proper specification of the target hardware could be very important. This is especially true when running on the newer SPARC processors. However, for most programs and older SPARC processors, the performance gain is negligible and a generic specification is sufficient.
-xarch, -xchip, and -xcache options. See Table 2-8 for the values. For example:
For PowerPC: -
xtarget=
accepts generic
or native
.xtarget=
accepts:
generic
or native
386
(equivalent to -386
option) or 486
(equivalent to -486
option)
pentium
(equivalent to -pentium
option) or pentium_pro
-xunroll=n
Suggests to the optimizer to unroll loops n times. n is a positive integer. When n is 1, it is a command, and the compiler unrolls no loops. When n is greater than 1, the -xunroll=n merely suggests to the compiler that it unroll loops n times. -xvpara
(SPARC) Warns about loops that have #pragma MP directives specified when the loop may not be properly specified for parallelization. For example, when the optimizer detects data dependencies between loop iterations, it issues a warning.
-Yc, dir
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
Changes the default directory searched for components. -YI, dir
Changes the default directory searched for include files. -YP, dir
Changes the default directory for finding libraries files. -YS, dir
Changes the default directory for startup object files. -Zll
(SPARC) Creates the program database for lock_lint, but does not actually compile. Refer to the lock_lint(1) man page for more details. -Zlp
(SPARC) Prepares object files for the loop profiler, looptool. The looptool(1) utility can then be run to generate loop statistics about the program. Use this option with -xdepend; if -xdepend is not explicitly or implicitly specified, turns on -xdepend and issues a warning. If optimization is not at -xO3 or higher, optimization is raised to -xO3 and a warning is issued. Generally, this option is used with one of the loop parallelization options: -xexplicitpar, -xautopar, or -xparallel. -Ztha
(SPARC) Prepares code for analysis by the Thread Analyzer, the performance analysis tool for multithreaded code. The -Ztha instrumentation performs two actions. It inserts calls to the profiling library at all procedure entries and exits in much the same way the -p does. However, instead of linking with the profiled libraries in /usr/lib/libp, code compiled with
-Ztha links with the library libtha.so.
Options Passed to the Linker
cc recognizes -a, -e, -r, -t, -u, and -z and passes these options and their arguments to ld. cc passes any unrecognized options to ld with a warning.
Localization of Error Messages
The messages from the C compiler, and lint, can be localized using gencat. See gencat(1) and catges(3C) for more information on message catalogs.SUNW_SPRO_SC_acomp.msg (C front end components acomp and ssbd)
After translating the messages, the gencat utility can be used to create the formatted message database catfiles. The C compiler uses these catfiles when issuing messages. In order for the C compiler to use the formatted message database catfiles, they must be:
SUNW_SPRO_SC_cc.msg (cc and lint command)
SUNW_SPRO_SC_acomp.cat (c front end components acomp & ssbd)To enable all users to use the message database catfiles, they should be installed in the proper location based on the locale. For example, if the locale is French (fr), and using the default installation of the C compiler, these files must reside in the directory: /opt/SUNWspro/SC4.2/lib/locale/fr/LC_MESSAGES and the environment variable LC_MESSAGES must be set to "fr" prior to invoking the cc command:
SUNW_SPRO_SC_cc.cat (cc and lint command)
using csh shell:
% setenv LC_MESSAGES frUsing sh shell:
$ LC_MESSAGES= frAlternatively, they can be installed in a directory of choice and accessed by the C compiler by setting NLSPATH prior to invoking the C compiler. For example, if they are installed in /usr/local/MyMessDir.NLSPATH can be set as follows:
$ export LC_MESSAGES
Using csh shell:
% setenv NLSPATH /usr/local/MyMessDir/%N.cat:$NLSPATHUsing sh shell:
$ NLSPATH=/usr/local/MyMessDir/%N.cat:$NLSPATH
$ export NLSPATH
cflow(1) and cxref(1) have their own message catalogs:
Note - These formatted message database catfiles are shared between the cc and lint commands. For messages not translated, the default C locale translation is used.
SUN_SPRO_SC_cflow.msg SUNW_SPRO_SC_cflow.cat cflow command