2.1. 32- and 64-bit development environments

AIX, together with the C and C++ compilers, offer two different programming models:

  • ILP32

  • LP64

ILP32, which stands for integer/long/pointer 32, is the native 32-bit programming environment for AIX. It provides a 32-bit address space, with a theoretical memory limit of 4 GB.

LP64, or long/pointer 64, is the 64-bit programming environment for AIX. It can address memory beyond the 4 GB limit by providing a 64-bit address space. In general, except for the data type size and alignment difference, LP64 supports the same programming features as the ILP32 model, and backward compatibility with the most widely used int data type.

According to the C and C++ language standards, int and short should be at least 16 bits, and long should be at least as long as int, but not smaller than 32 bits. This relationship among the integral data types still holds true in the LP64 model:

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

The LP64 data model is the de facto standard on 64-bit UNIX-based systems provided by all major system vendors. Applications that transition to the LP64 data model are therefore highly portable to other LP64 vendor platforms.

Table 2-1 on page 39 lists the basic C and C++ data types on AIX and their corresponding sizes in bits for both the ILP32 and LP64 programming models.

Table 2-1. C and C++ data type sizes in bits
Data typeILP32LP64
char88
short1616
int3232
long3264
long long6464
pointer3264
float3232
double6464
long double[a]64 or 12864 or 128

[a] The size of long double is controlled by the -qlongdouble option, or when you invoke the compiler with the 128 suffix (see Table 1-4 on page 30).

2.1.1. The 64-bit advantage

The primary objective for developing in 64-bit is to take advantage of the newer, faster 64-bit hardware[1] and operating systems[2], and to make complex, memory demanding applications (for example, database and scientific computational applications) perform more efficiently. It offers the following benefits not found in 32-bit systems:

[1] Refer to 3.1.1, “How to determine hardware bit mode” on page 107.

[2] Refer to 3.1.2, “How to determine kernel bit mode” on page 107.

  • Full 64-bit addressing that expands the address space available to applications beyond the 4 GB limit

  • Large process data space mapped in a large virtual address space

  • Support for large data structures and executable files

  • Large file support using standard system library calls

  • Large file caches on systems with large physical memory

  • 64-bit data elements with instructions for performing efficient arithmetic and logical computations as operations, using full-register widths, the full-register set, and new instructions

  • Greater scalability of system derived data types, for example, time_t and dev_t

In addition, by keeping data in memory rather than writing out to disk, I/O bound applications can realize improved performance, since disk I/O is usually more time-consuming than memory access.

2.1.2. Compiler support

The compiler drivers (see 1.7.1, “Default compiler drivers” on page 30) by default invoke the compiler and linker in 32-bit mode. The following features are provided to enable 64-bit development:

  • Predefined __64BIT __ macro when invoked for 64-bit compilations

  • OBJECT_MODE environment variable

  • The -q64 option

  • -qarch support for 64-bit suboption

The compilers can be invoked for 64-bit or 32-bit mode by setting an environment variable, or by using a command line option to set the compilation mode of the compiler. Inconsistent options for compilation mode are resolved in the following order:

  1. OBJECT_MODE environment variable

  2. Configuration file

  3. Command line options

Please refer to the VisualAge C++ for AIX Compiler Reference, SC09-4959 for more details on the options supported.

__64BIT __ preprocessor macro

Like many of the features supported by the compilers, the preprocessor macro __64BIT__ is defined when compiling in 64-bit mode. The purpose of the macro is to allow the programmer to select different data structures or lines of code for 32-bit and 64-bit execution in the same source file.

The macro can be tested using conditional directives. For example:

#if defined(__64BIT__)
    /* 64-bit specific data structures or code */
#else
    /* 32-bit mode */
#endif

This ability to choose execution mode (of the final executable) at compile time using the __64BIT__ macro implies that there is no need to test execution mode at run time. It also eliminates the need of maintaining different variations of common header files. All the library header files are already coded in such a way that they can be compiled regardless of the mode.

Command line options

The compilers can be invoked for 64-bit or 32-bit mode by setting an 64-bit mode support in the C and C++ compilers is mainly provided by the two compiler options, -q64 and -q32, respectively.

Note

Unlike the -X option for the utility commands, the -q32 or -q64 compiler options do not allow a white space after -q; -q64 is valid whereas -q 64 is invalid.


When used in conjunction with the -qarch option, they determine the mode and instruction set for the target architecture. The -q32 and -q64 options take precedence over the setting of the -qarch option. Conflicts between the -q32 and -q64 options are resolved by the last option wins rule. Setting -qarch=com will ensure future compatibility for applications, whereas specific settings will be more hardware architecture dependent.

Please refer to the “Acceptable Compiler Mode and Processor Architecture Combinations” section of the VisualAge C++ for AIX Compiler Reference, SC09-4959 for valid combinations of the -q32, -q64, -qarch, and -qtune compiler options.

Note

In 64-bit mode, -qarch=com is treated the same as -qarch=ppc.


OBJECT_MODE environment variable

Having to specify an option every time you compile can become cumbersome and prone to mistakes (for example, inadvertently mixing 32-bit and 64-bit objects in the link edit step, which is not supported). If you are always compiling in one mode during a development session, you can set the OBJECT_MODE environment variable to change the default compilation mode. Permissible values for the OBJECT_MODE environment variable are:

(unset)Generate and/or use 32-bit objects.
32Generate and/or use 32-bit objects.
64Generate and/or use 64-bit objects.
32_64Accept both 32- and 64-bit objects.

Note

The compiler and linker do not support OBJECT_MODE=32_64, and using this choice will generate the error message:

1501-254 OBJECT_MODE=32_64 is not a valid setting for the compiler.


The benefit of using OBJECT_MODE to control the development environment is that other utilities that are often used during development are also sensitive to this environment variable.

Note

The use of OBJECT_MODE to determine the default mode can cause serious problems if a user is unaware of the current setting. For example, the user may not be aware that OBJECT_MODE has been set to 64 and may unexpectedly obtain 64-bit object files from a compiling source file that is not designed for 64-bit. We strongly urge users to be aware of the setting of OBJECT_MODE at the time and to set OBJECT_MODE to ensure that the compiler is invoked for the correct mode.


Linker command line options

The linker, ld, also supports 64-bit link editing with the -b64 option as well as the default 32-bit link editing with -b32. Since the compiler drivers automatically sets the linker option properly based on the -q64 and -q32 options, it is not necessary to specify these linker specific options.

2.1.3. Utility commands support

The following utility commands that deal with object files by default, assumes the object file is in 32-bit XCOFF[3] format:

[3] The eXtended Common Object File Format, XCOFF, is the object format for AIX. For a detailed description of the XCOFF format, see the AIX 5L Version 5.2 Files Reference.

arMaintains the indexed libraries used by the linkage editor.
dumpDumps selected parts of an object file.
lorderFinds the best order for member files in an object library.
nmDisplays information about symbols in object files, executable files, and object-file libraries.
ranlibConverts archive libraries to random libraries.
sizeDisplays the section sizes of the XCOFF object files.
stripReduces the size of an XCOFF object file by removing information used by the binder and symbolic debug program.

To support the 64-bit XCOFF object format, these utility commands have been enhanced with the -X option. The -X option specifies the type of object file the utility should examine, and accepts one of the following values:

32Processes only 32-bit object files
64Processes only 64-bit object files
32_64Processes both 32-bit and 64-bit object files

Note

These utility commands also refer to the OBJECT_MODE environment value; however, the -X option overrides the environment value setting.


Before developing your 64-bit application, you must confirm whether the libraries that your application depends on are provided in 64-bit. Most C and C++ libraries provided by AIX are hybrid mode archives (both 32- and 64-bit objects are included). However, this may not be the case with third party vendor libraries. See “32- and 64-bit objects” on page 48 and “Hybrid mode library archives” on page 48 for further information about this topic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset