cc(1) MAXION/OS cc(1)
NAME
cc - C compiler
SYNOPSIS
cc [options] file . . .
DESCRIPTION
The cc command is the interface to the C compilation system.
The compilation tools conceptually consist of a
preprocessor, a compiler, an optimizer, an assembler, and a
link editor. cc processes the supplied options and then
executes the various tools with the proper arguments. cc
accepts several types of file as arguments.
Files whose names end with .c are taken to be C source files
and may be preprocessed, compiled, optimized, instrumented
for profiling, assembled, and link-edited. The compilation
process may be stopped after the completion of any pass if
the appropriate options are supplied. If the compilation
process runs through the assembler, an object file is
produced whose name is that of the source with .o
substituted for .c. However, the .o file is normally
deleted if a single C file is compiled and then immediately
link-edited.
In the same way, files whose names end in .s are taken to be
assembly source files; they may be assembled and link-
edited.
Files whose names end in .i are taken to be preprocessed C
source files, and they may be compiled, optimized,
instrumented for profiling, assembled, and link-edited.
Files whose names do not end in .c, .s, or .i are handed to
the link editor, which by default produces a dynamically
linked executable whose name is a.out.
Since cc usually creates files in the current directory
during the compilation process, it is necessary to run cc in
a directory in which a file can be created.
cc recognizes the following options:
-A name[(tokens)]
Associates name as a predicate with the specified
tokens, as if by an #assert preprocessing directive.
Preassertions: system(unix)
cpu(mips)
machine(mips)
______________________________
1
cc(1) MAXION/OS cc(1)
If name is -, all predefined macros (other than
those that begin with ) are undefined and all
preassertions are unasserted.
-B str str can be either dynamic or static:
-B dynamic causes the link editor to look for files
named libname.so and then for files named libname.a
when given the -lname option.
-B static causes the link editor to look only for
files named libname.a.
This option may be specified several times on the
command line as a toggle.
This option and its argument are passed to ld.
-C Causes the preprocessing phase to pass along all
comments other than on preprocessing directive
lines.
-c Suppresses the link editing phase of the compilation
and does not remove any object files created during
the compilation.
-cerrs Produce error and warning messages in a terse
format, similar to that produced by the standard
ANSI C compiler cc:
"file" .line : error message
If you are using SoftBench SDE (see softbench(1)),
you must use this option to produce error and
warning messages that it can understand.
-D name[=tokens]
Associates name with the specified tokens as if by a
#define preprocessing directive.
If no =tokens is specified, the token 1 is supplied.
See also the -A, -U, and -X options, which influence
which symbols are predefined.
The names unix and mips are predefined.
-d str Determines the mode of the executable result of the
linking phase; str can be either y or n.
-dy specifies dynamic linking in the link editor
(the default).
2
cc(1) MAXION/OS cc(1)
-dn specifies static linking in the link editor.
This option and its argument are passed to ld.
-DUSEBUILTINS
Causes the compiler to use a built-in function
instead of making a UNIX library call. For
additional information on these built-in functions,
see the section titled "Built-In Functions."
-E Only preprocesses the named C files and sends the
result to the standard output. The output will
contain preprocessing directives for use by the next
pass of the compilation system.
-F il Invokes the function call inliner. The inliner
searches for suitable function calls to be replaced
by the body of the called function. -O must also be
specified.
-F gis When used with the -O option, this option enables
global instruction scheduling. See the -F maxopt
option.
-F maxopt
This option is a shorthand notation for "maximum
optimization", that is, -O -F gis.
This option also includes the performance benefits
of the -Xa and -Xc options; see the -O option.
Function call inlining may improve performance
further; see the -F il option.
-F sa When used with the -O option, this option prohibits
the compiler optimizer from deleting instructions
contained in each function prologue which copy
incoming arguments onto the stack. Without this
option, incoming arguments may be retained in
registers and the instructions which copy them to
the stack may be deleted during optimization.
-G Directs the link editor to produce a shared object
(usually a library) rather than an executable
program.
This option is passed to ld.
This option can not be used with the -dn option.
-g Causes the compiler to generate additional
information needed for the use of edb and other
3
cc(1) MAXION/OS cc(1)
debuggers. The -g and the -O options do not work
together; -O is ignored.
-H Prints on the standard error output, one per line,
the pathname of each file included during the
current compilation.
-I dir Alters the search for included files whose names do
not begin with / to look in dir prior to the usual
directories. The directories for multiple -I
options are searched in the order specified.
-K none Generates code which is neither call-pic nor
full-PIC. This option must be used with -dn, and
cannot be used with -dy.
-K pic Produces position-independent code (small model).
This option (the default) produces "call-pic" code
which is not itself position independent, but which
calls external functions in a position independent
manner.
-K PIC Produces position-independent code (large model).
This option produces "full-PIC" position independent
code, incorporating the functionality of -K pic.
-L dir Adds dir to the list of directories that ld
searches.
This option and its argument are passed to ld.
-l name Scans the library libname.so or libname.a to satisfy
unresolved references. Its placement on the common
line is significant as libraries and object files on
the command line are processed once only in
left-to-right order.
This option and its argument are passed to ld.
-O Arranges for full optimization to occur.
For .c files, this includes invoking a global
optimizer and an instruction scheduler. If the -Xa
or -Xc option is given, the global optimizer is able
to make additional assumptions about the volatile
status of non-auto data items. This may permit
further optimizations.
Due to a function call overhead when compiling with
-dy (dynamic linking, the default), additional
performance can be achieved by using the -dn (static
linking) option.
4
cc(1) MAXION/OS cc(1)
See also the -F gis, -F maxopt, and -d options.
-o outfile
Produces an output file named outfile instead of
using the name derived via the default rules. If an
executable file is produced, the default name is
a.out. Otherwise, the default name is formed by
stripping the suffix from the input filename and
appending .i (for preprocessed C output), .s (for
assembly language output), or .o (for relocatable
ELF output).
-P Only preprocesses the named C files and leaves the
result in corresponding files suffixed .i. The
output will not contain any preprocessing
directives, unlike -E.
-p Arranges for the compiler to produce code that
counts the number of times each routine is called.
Furthermore, if link editing takes place, profiled
versions of libc.a and libm.a (with the -lm option)
are linked if the -dn option is used. A mon.out
file will be produced when the object program
terminates normally. An execution profile can then
be generated by using prof(1).
-Q str Controls the inclusion of compilation tool
identification information in the output; str can be
either y or n.
If str is y (the default), identification
information about each invoked compilation tool will
be added to the output files. This can be useful
for software administration.
If str is n, the information will be suppressed.
-S Compiles, optimizes (if -O is present), but does not
assemble or link edit the named C files. The
assembler-language output is left in corresponding
files suffixed with .s.
-T x Designates how a data type should be treated, as
signed or unsigned; x can be either c or b.
-T c causes the compiler to treat "plain" char data
types as signed; they would be treated as unsigned
by default.
-T b causes the compiler to treat "plain" short,
int, and long data types as unsigned (bit fields);
they would be treated as signed by default.
5
cc(1) MAXION/OS cc(1)
Note that this option is recommended only for
porting files from RTU 6.
-U name Causes any definition of name to be forgotten, as if
by a #undef preprocessing directive. If the same
name is specified for both -D and -U, name is not
defined, regardless of the order of the options.
Note that some symbols may be predefined (see -A, -D
and -X).
-V Causes each invoked tool to print its version
information on the standard error output.
-v Causes the compiler to perform more and stricter
semantic checks, and to enable certain lint(1)-like
checks on the named C files.
-W tool,arg1[,arg2 ...]
Hands off the argument(s) argi, each as a separate
argument to tool. Each argument must be separated
from the preceding one by only a comma. (A comma
can be part of an argument by escaping it by an
immediately preceding backslash (\) character; the
backslash is removed from the resulting argument.)
tool can be one of the following:
p a synonym for 0
0 compiler
a assembler
l link editor
For example, -Wa,-o,objfile passes -o and objfile to
the assembler, in that order; and -Wl,-I,name causes
the linking phases to override the default name of
the dynamic library, /usr/lib/libc.so.
The order in which the argument(s) are passed to a
tool with respect to the other specified command
line options may change.
-X x Specifies the degree of conformance to the ANSI C
standard. x can be one of the following:
t (transition)
The compiled language includes all new features
compatible with older (pre-ANSI) C. This is the
default behavior. The compiler warns about all
language constructs that have differing behavior
between the new and old versions, and uses the
pre-ANSI C interpretation. This includes, for
example, warnings about the use of trigraphs, the
6
cc(1) MAXION/OS cc(1)
new escape sequence \a, and the changes to the
integral promotion rules.
a (ANSI)
The compiled language includes all new features
of ANSI C and uses the new interpretation of
constructs with differing behavior. The compiler
continues to warn about the integral promotion
rule changes, but does not warn about trigraph
replacements or new escape sequences.
c (conformance)
The compiled language and associated header files
are ANSI C conforming, but include all conforming
extensions of -Xa. Warnings will be produced
about some of these. Further, only ANSI defined
identifiers are visible in the standard header
files. The predefined symbols (see -D) are not
predefined in this mode.
The predefined macro STDC has the value 0 for
-Xt and -Xa, and 1 for -Xc. All warning messages
about differing behavior can be eliminated in -Xa
through appropriate coding; for example, use of
casts can eliminate the integral promotion change
warnings.
-Xcif This option performs a normal compilation, but also
generates a compressed Common Interface File (CIF),
whose name is appended with the suffix .q. This
option is intended for use with the SoftBench SDE
Static Analyzer (see static(1)).
-Xcifonly
This option is similar to -Xcif, except that only
the uncompressed CIF file, whose name is appended
with the suffix .cif, is produced. No compiler
output files are produced. This option is intended
for use with the SoftBench SDE Static Analyzer (see
static(1)).
-Y item,dir
Specifies a new directory dir for the location of
item. item can consist of any of the characters
representing tools listed under the -W option, or
the following characters representing directories
special files:
I directory searched last for include files:
INCDIR (see -I).
7
cc(1) MAXION/OS cc(1)
S directory containing the start-up object files:
LIBDIR.
L (obsolete) Use -YP instead. For this release,
-YL will be simulated using -YP. -YL will be
removed in a later release.
U (obsolete) Use -YP instead. For this release,
-YU will be simulated using -YP. -YU will be
removed in a later release.
P Changes the default directories used for
finding libraries. dir is a colon-separated
path list.
D Directory containing the default compiler
options file: ETCDIR.
In addition, item can be the word install, in which
case dir specifies the root of the directory
structure (e.g., /usr/ccs) in which products have
been installed. Use of -Yinstall causes cc to
search this directory structure first for tools,
libraries, and include files. For example, by
specifying dir as $HOME (the user's home directory),
the complete installation can be held within the
user's home directory.
If the location of a tool is being specified, then
the new pathname for the tool will be dir/tool. If
more than one -Y option is applied to any one item,
then the last occurrence holds.
-Z m Indicates that the program module contains a
misaligned struct member access using means other
than the struct.member and pointer->member
constructs. This option is used with #pragma
pack(). See the -Zpn option.
-Z pn where n can be 1, 2, 4, or omitted, in which case 1
is assumed. This option specifies the maximum
default alignment, in bytes, which the compiler
should give to any non-bitfield struct member. This
option overrides any #pragma pack() specification.
See the -Zm option.
-#[#] Prints details, on standard output, about the
invocation of each compilation tool.
A single # character causes the name of each invoked
tool to be printed together with the tool's command
line options.
8
cc(1) MAXION/OS cc(1)
Two # characters give the above information together
with the full pathname of each invoked tool, the
pathname of the default compiler options file, and
the pathname of temporary and .o files.
Three # characters (or more) result in a "dry run"
of the compilation tools; none of the tools are
actually invoked, but the names, full pathnames, and
command lines of each tool are printed in normal
compilation order.
cc recognizes -a, -B, -e, -h, -m, -o, -r, -s, -t, -u, and -z
and passes these options and their arguments to ld. cc also
passes any unrecognized options to ld without any
diagnostic.
When cc is put in a file prefixcc, the prefix will be
recognized and used to prefix the names of each tool
executed. For example, OLDcc will execute OLDacomp, OLDas,
and OLDld, and will link the object file(s) with OLDcrt1.o.
Therefore, be careful when moving cc around. The prefix
applies to the compiler, optimizer, assembler, link editor,
the start-up routines, and the default compiler options
file.
Built-In Functions
The C compiler offers several built-in functions; these
functions are:
alloca() defined in <alloca.h>
fabs() defined in <math.h>
fabsf() defined in <math.h>
abs() defined in <stdlib.h>
strlen() defined in <string.h>
strcpy() defined in <string.h>
strncpy() defined in <string.h>
_________________________________
Using one of these functions means that compiler uses its
own optimized version of the function rather than making a
UNIX library call.
You must use the -DUSEBUILTINS command line option to
access any of these functions, except for alloca().
alloca() only exists as a built-in function, so the
-DUSEBUILTINS command line option is not required.
When using a built-in function, be sure to include the
header file where it is defined, but avoid declaring it
locally. Otherwise the link editor (ld) will generate a
fatal symbol referencing error.
9
cc(1) MAXION/OS cc(1)
For example:
Wrong Right
#include <string.h> #include <string.h>
int strlen();
main() main()
{ {
strlen("Hello, world"); strlen("Hello, world");
} }
_____________________________________________________
Compiling the example on the left gives the following
results:
$ cc junk.c
Undefined first referenced
symbol in file
builtinstrlen junk.o
ld: a.out: fatal error: Symbol referencing errors.
No output written to a.out
The example on the right compiles correctly.
Files
file.c C source file
file.i preprocessed C source file
file.o object file
file.s assembly language file
a.out link-edited output
/usr/ccs/bin/cc ANSI C driver executable
/usr/ccs/bin/acomp ANSI C compiler
/usr/ccs/bin/as assembler
/usr/ccs/bin/prof profiler
/usr/ccs/lib/libc.a standard C library
/usr/ccs/lib/libm.a math library
/usr/ccs/lib/libprof.a profile library
/usr/ccs/lib/libelf.a elf access library
/usr/ccs/lib/*crt1.o start-up routine
/usr/ccs/lib/*crti.o start-up routine
/usr/ccs/lib/*crtn.o start-up routine
/usr/ccs/lib/values-X*.o ANSI conformance module
/usr/ccs/lib/eccdefaultopts default compiler options file
/usr/tmp/ctm? temporary files
____________________________________________________________
REFERENCES
as(1), edb(1), ld(1), lint(1), prof(1) in the Command
Reference Manual.
softbench(1), softbuild(1), static(1) in the SoftBench SDE
Man Pages manual.
10
cc(1) MAXION/OS cc(1)
Kernighan, B. W., and Ritchie, D. M., The C Programming
Language, Second Edition, Prentice-Hall, 1988
American National Standard for Information Systems -
Programming Language C, X3.159-1989
International Standard ISO/IEC 9899:1990, Programming
Languages - C
International Standard ISO/IEC 9945-1:1990, Information
Technology - Portable Operating System Interface (POSIX) -
Part 1: System Application Program Interface (API) [C
Language]
NOTICES
The -ql and -O options do not work together; -O will be
ignored.
The -g and -O options do not work together; -O will be
ignored.
The -F options cannot be used without -O; -F will be
ignored.
Modified in MAXION/OS 1.2.
11