C H A P T E R  1

Introduction to the C Compiler

This chapter provides information about the C compiler, including new features provided with this release, standards conformance, documentation formats, organization of the compiler, and C-related programming tools.


1.1 New Features and Functionality

This section provides a brief overview of the new C compiler features and functionality introduced in this release. For specific explanations, follow the cross references provided for each item.

1.1.1 Improved Performance

Improved performance through new defaults for the -xarch, -xcode, -xmemalign, and -xprefetch options and through new expansions for the -fast and -O options.

The default architecture for which the C compiler produces code is now v8plus (UltraSPARC). Support for v7 will be dropped in a future release.

The new default yields higher run-time performance for nearly all machines in current use. However, applications that are intended for deployment on pre-UltraSPARC computers no longer execute by default on those computers. Compile with -xarch=v8 to ensure that the applications execute on those computers.

If you want to deploy on v8 systems, you must specify the option -xarch=v8 explicitly on every compiler command line as well as any link-time commands. The provided system libraries run on v8 architectures.

If you want to deploy on v7 systems, you must specify the option -xarch=v7 explicitly on every compiler command line as well as any link-time commands. The provided system libraries use the v8 instruction set. For this release, the only supported operating system for v7 is the Solaris 8 release. When a v8 instruction is encountered, the Solaris 8 operating system interprets the instruction in software. The program runs, but performance is degraded.

For x86, -xarch defaults to generic. Note that -fast on x86 expands to -xarch=native.

For more information on -xarch, see Section B.2.66, -xarch=isa.

(SPARC) The default on v8 is -xcode=abs32. The default on v9 is -xcode=abs44. For more information, see Section B.2.77, -xcode[=v].

(SPARC) The default for all v8 architectures is -xmemalign=8i. The default for all v9 architectures is -xmemalign=8s. For more information, see Section B.2.106, -xmemalign=ab

(SPARC) The default is now -xprefetch=auto,explicit. This change adversely affects applications that have essentially non-linear memory access patterns. To disable the change, specify -xprefetch=no%auto,no%explicit. For more information, see Section B.2.122, -xprefetch[=val[,val]].

The -fast option now expands to include the new option -xlibmopt. This option enables the compiler to use a library of optimized math routines. These routines can cause the value of errno to become unreliable. For more information, see Section 2.10, The Value of errno.

(SPARC) (Intel) The -O macro now expands to -xO3 instead of -xO2.

The change in default yields higher run-time performance. However, -x03 may be inappropriate for programs that rely on all variables being automatically considered volatile. Typical programs that might have this assumption are device drivers and older multi-threaded applications that implement their own synchronization primitives. The work around is to compile with -xO2 instead of -O. For more information, see Section B.2.16, -fast.

1.1.2 Improved Optimization

Improved optimization through the -xlibmopt, -xnolibmopt, -xipo_archive, and -xprefetch_auto_type options as well as automatically-generated precompiled-headers with -xpch.

The -xlibmopt option enables the compiler to use a library of optimized math routines. You must use default rounding mode by specifying -fround=nearest when you specify this option. The math routine library is optimized for performance and usually generates faster code. The results may be slightly different from those produced by the normal math library. If so, they usually differ in the last bit.

You can explicitly turn off this library by specifying the new -xnolibmopt option on the command line. For more information on -xlibmopt, see Section B.2.97, -xlibmopt, and for -xnolibmopt, see Section B.2.109, -xnolibmil.

The -xipo_archive option 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. Any object files contained in the library that were optimized during the compilation are replaced with their optimized version. For more information on -xipo_archive, see Section B.2.92, -xipo_archive=[a].

The -xprefetch_auto_type option enables the compiler to generate indirect prefetches for the loops indicated by the option -xprefetch_level=[1|2|3] in the same fashion that the prefetches for direct memory accesses are generated.

Options such as -xdepend, -xrestrict, and -xalias_level can improve the optimization benefits of -xprefetch_auto_type. They affect the aggressiveness of computing the indirect prefetch candidates and therefore the aggressiveness of the automatic indirect prefetch insertion because they help produce better memory alias disambiguation information. For more information on the -xprefetch_auto_type option, see Section B.2.123, -xprefetch_auto_type=a.

This release of the C compiler expands the precompiled header facility to include an automatic capability on the part of the compiler to generate the precompiled header file. You still have the option to manually generate the precompiled header file, but if you are interested in the new capability of the compiler, see Section B.2.118, -xpch=v.

1.1.3 Expanded C99 Compliance

This release provides expanded support for 1999 C ISO features.

1.1.4 Expanded Support for the Intel Architecture

The C compiler supports new flags for -xarch, -xtarget, and -xchip, flags for the Intel architecture. These new flags are designed to take advantage of Pentium 3 and Pentium 4 chips in combination with Solaris software support for SSE and SSE2 instructions on the Intel platform. Here are the new flags:



caution icon

Caution - Programs that are compiled with -xarch={sse|sse2} to run on Solaris x86 SSE/SSE2 Pentium 4-compatible platforms must be run only on platforms that are SSE/SSE2 enabled. Running such programs on platforms that are not SSE/SSE2-enabled could result in segmentation faults or incorrect results occurring without any explicit warning messages.



Patches to the OS and compilers to prevent execution of SSE/SSE2-compiled binaries on platforms not SSE/SSE2-enabled might be made available at a later date.

OS releases starting with Solaris 9 update 6 are SSE/SSE2-enabled on Pentium 4-compatible platforms. Earlier versions of Solaris OS are not SSE/SSE2-enabled. This warning extends also to programs that employ .il inline assembly language functions or __asm( ) assembler code that utilize SSE/SSE2 instructions.

If you compile and link in separate steps, always link using the compiler and with -xarch={sse|sse2} to ensure that the correct startup routine is linked

You can determine which combination of the new -xchip, -xtarget, and -xarch flags is appropriate for your needs by following these guidelines:

If so, the compiler makes the following expansions:



Note - You can specify -xarch=sse or -xarch=sse2 despite using these versions of Solaris software, but you must run the executable that results from your build on a machine that is running Solaris 9 update 6 or later or running Solaris 10 because these versions of Solaris software support sse and sse2 instructions.



If so, the compiler makes the following expansions:

For more information, see Section B.2.66, -xarch=isa, Section B.2.76, -xchip[=c], and Section B.2.138, -xtarget=t.

1.1.5 Support for New SPARC Chips

This release provides expanded SPARC support with new -xchip and -xtarget flags. The -xchip and -xtarget options now support ultra3i and ultra4 as values so you can build applications that are optimized for the UltraSPARC IIIi and UltraSPARC IV processors. For more information, see Section B.2.76, -xchip[=c], and Section B.2.138, -xtarget=t.

1.1.6 New Security Checks

This release of the lint utility features a new security-checking facility. You can use the new -errsecurity option before compilation to check your code for security liabilities. For more information on -errsecurity, see Section 5.3.13, -errsecurity=v.


1.2 Standards Conformance

The term C99 used in this book refers to the ISO/IEC 9899:1999 C programming language. There term C90 refers to the ISO/IEC 9899:1990 C programming language.

This compiler supports most of the language features specified in the ISO/IEC 9899:1999, Programming Language - C standard on operating systems earlier than Solaris 10. This compiler is in full compliance with the C99 standard on Solaris 10 when you specify -xc99=all,lib.

This compiler also conforms with the ISO/IEC 9899:1990, Programming Languages - C standard.

Because the compiler also supports traditional K&R C (Kernighan and Ritchie, or pre-ANSI C), it can ease your migration to ISO C.

For information on C90 implementation-specific behavior, see Appendix E.

For more information on supported C99 features, see Appendix D.


1.3 C Readme File

The C compiler's readme file highlights important information about the compiler, including:

To view the text version of the C readme file, type the following at a command prompt:

example% cc -xhelp=readme

To access the HTML version of the readme, in your Netscape Communicator 4.0 or compatible version browser, open the following file:

/opt/SUNWspro/docs/index.html

(If your C compiler-software is not installed in the /opt directory, ask your system administrator for the equivalent path on your system.) Your browser displays an index of HTML documents. To open the readme, find its entry in the index, then click the title.


1.4 Man Pages

Online manual (man) pages provide immediate documentation about a command, function, subroutine, or collection of such things.

You can display a man page by running the command:

example% man topic

Throughout the C documentation, man page references appear with the topic name and man section number: cc(1) is accessed with man cc. Other sections, denoted by ieee_flags(3M) for example, are accessed using the -s option on the man command:

example% man -s 3M ieee_flags


1.5 Organization of the Compiler

The C compilation system consists of a compiler, an assembler, and a link editor. The cc command invokes each of these components automatically unless you use command-line options to specify otherwise.

Appendix B discusses all the options available with cc.

The following figure shows the organization of the C compilation system.

  FIGURE 1-1 Organization of the C Compilation System

Diagram showing the components of the C compilation system.[ D ]

The following table summarizes the components of the compilation system.

TABLE 1-1 Components of the C Compilation System

Component

Description

Notes on Use

cpp

Preprocessor

-Xs only

acomp

Compiler (preprocessor built in for non-Xs modes)

 

ssbd

Static synchronization bug detection

(SPARC)

iropt

Code optimizer

(SPARC) -O, -xO2, -xO3, -xO4, -xO5, -fast

fbe

Assembler

 

cg

Code generator, inliner, assembler

(SPARC)

ipo

Interprocedural Optimizer

(SPARC)

postopt

Postoptimizer

(SPARC)

ir2hf

Intermediate code translator

(INTEL)

ube

Code generator

(INTEL)

ube_ipa

Interprocedure analyzer

(INTEL)

ld

Linker

 

ild

Incremental linker

(SPARC) -g, -xildon

mcs

Manipulate comment section

-mr



1.6 C-Related Programming Tools

There are a number of tools available to aid in developing, maintaining, and improving your C programs. The two most closely tied to C, cscope and lint, are described in this book. In addition, a man page exists for each of these tools.

Other tools for source browsing, debugging and performance analysis are available. See Section , Accessing Compilers and Tools Documentation for more information.