Solaris 64-bit Developer's Guide

Build Environment

The build environment includes the system headers, compilation system, and libraries. These are explained in the sections that follow.

Headers

A single set of system headers supports both 32-bit and 64-bit compilation environments. You do not need to specify a different include path for the 64-bit compilation environment.

To better understand the changes made to the headers for support of the 64-bit environment, you should understand the various definitions in the header <sys/isa_defs.h>. This header contains a group of well known #defines and sets these for each instruction set architecture. Inclusion of <sys/types.h> automatically includes <sys/isa_defs.h>.

The symbols in the following table are defined by the compilation environment:

__sparcIndicates any of the SPARC family of processor architectures. This includes SPARC V7, SPARC V8, and SPARC V9 architectures. The symbol sparc is a deprecated historical synonym for __sparc.
__sparcv8Indicates the 32-bit SPARC V8 architecture as defined by Version 8 of the SPARC Architecture Manual.
__sparcv9Indicates the 64-bit SPARC V9 architecture as defined by Version 9 of the SPARC Architecture Manual.
__i386 This symbol is generic for all processors implementing the Intel 386 instruction set or a superset of it. This includes all members of the 386, 486, and Pentium family of processors.

The symbols __sparcv8 and __sparcv9 are mutually exclusive and are only relevant when the symbol __sparc is defined.

The following symbols are derived from some combination of the symbols above being defined:

_ILP32The data model where sizes of int, long, and pointer are all 32 bits.
_LP64The data model where sizes of long and pointer are all 64 bits.

The symbols _ILP32 and _LP64 are also mutually exclusive.

If writing completely portable code is not possible, and specific 32-bit versus 64-bit code is required, make the code conditional using _ILP32 or _LP64. This makes the compilation environment machine independent and maximizes the portability of the application to all 64-bit platforms.

Compilers

The Sun WorkShop C, C++, and Fortran compilation environments have been enhanced to support the creation of both 32-bit and 64-bit applications. The 5.0 release of the C compiler from Sun WorkShop provides 64–bit compilation support.

Native and cross-compilation modes are supported. The default compilation environment continues to produce 32-bit applications. While both modes are supported, they are still architecture-specific. It is not possible to create SPARC objects on Intel machines, nor Intel objects on SPARC machines with the Sun compilers. In the absence of a specification of the architecture or mode of compilation, the appropriate __sparc or __i386 symbol is defined by default, and as part of this, _ILP32 is also defined. This maximizes interoperability with the existing applications and hardware base.

Using the C compiler from Sun WorkShop as an example, to enable the 64-bit compilation environment on a SPARC machine, the -xarch=v9 flag needs to be given as an argument to cc(1).

This generates LP64 code in ELF64 objects. ELF64 is a 64-bit object file format supporting 64-bit processors and architectures. This is in contrast to the ELF32 object files generated when compiling in the default 32-bit mode.

The -xarch=v9 flag is used to generate code on either 32–bit or 64–bit systems. Using the 32–bit compiler you can build 64–bit objects on a 32–bit system (using -xarch=v9) though you cannot run them on a 32–bit system. You need not specify the library path for the 64-bit libraries. If the -l or -L option is used to specify an additional library or library path and that path points only to 32-bit libraries, the linker detects this and fails with an error.

Libraries

The Solaris operating environment provides shared libraries for both 32-bit and 64-bit compilation environments. While no 32–bit static libraries have been removed, no 64–bit static libraries are provided.

32-bit applications must link with 32-bit libraries, and 64-bit applications must link with 64-bit libraries. It is not possible to create or execute a 32-bit application using 64-bit libraries. The 32-bit libraries continue to be located in /usr/lib and /usr/ccs/lib. On SPARC platforms, the 64-bit libraries are located in a sparcv9 subdirectory of the appropriate lib directory. Because the placement of the 32-bit libraries has not changed, 32-bit applications built on prior releases are binary compatible.

In order to build 64-bit applications, you need 64-bit libraries. It is possible to do either native or cross-compilation, because the 64-bit libraries are available for both 32-bit and 64-bit environments. The compiler and other miscellaneous tools (for example; ld, ar, and as) are 32–bit programs capable of building 64-bit programs on 32-bit or 64-bit systems. Of course, a 64-bit program built on a system running the 32-bit operating system cannot execute in that 32-bit environment.