FPC AIX Port

From Free Pascal wiki
Jump to navigationJump to search

Overview

As of revision 20851, FPC svn trunk supports targeting the AIX operating system.

AIX is a UNIX platform and hence treated like one by FPC. As of revision 21053, FPC can create both AIX/PowerPC 32 bit and AIX/PowerPC64 applications and libraries. Note that gcc and xlc on AIX by default generate 32 bit code. The reason is that on PowerPC, 32 bit programs are usually faster and use less memory than 64 bit ones.

Snapshots

An initial snapshot is available in two flavours: a native AIX compiler, and a cross-compiler from Windows. Note that these are not compiled from the version that was committed to svn, but from a slightly older version. It is unlikely that future binary snapshots will be created (unless someone volunteers), but as of the next major release, (native) AIX compilers will be included;

Port information

Required helper tools

To compile the compiler on AIX, you must have the AIX assembler and linker installed, as well as GNU diffutils and GNU make.

To cross-compile from other platforms, you need the GNU BinUtils configured as follows:

 ./configure --target=powerpc-ibm-aix5.3 --with-sysroot

Note that the extra "5.3" at the end is required. Afterwards, rename the generated binaries from powerpc-ibm-aix5.3-as etc to powerpc-aix-as, as those are the names that the compiler expects (-XPpowerpc-ibm-aix5.3- won't work, as the compiler currently does not support dots in prefixes).

Debugger

AIX uses its own debugging format, Stabx. As the name implies, this is a variant of the regular Stabs format, but it has some differences. GDB on AIX does not fully support the Stabx format, but instead supports a hybrid format between regular Stabs and Stabx, which is also generated by GCC. FPC generates this same hybrid information. The result is that FPC-generated binaries compiled with debug information can be debugged by GDB on AIX, but not (fully) by DBX, the native AIX debugger.

The default GDB compiles without any problems on AIX. A compiled version of GDB 7.3.1 for AIX can also be downloaded from our ftp site.

Line info unit for symbolicating backtraces

No support has been added (yet) for the AIX debugging format (Stabx) to the lineinfo unit. Instead, when compiling with -gl, the resulting binary will launch gdb to symbolicate backtraces. This can cause trouble if you are debugging a program compiled with -gl, since this newly launched will not be able to attach to the process in that case. The reason is that a process can only be debugged by one debugger at a time.

Assembler/linker

When compiling/linking an AIX program/library on a platform other than AIX, FPC assumes that the used assembler and linker are from the GNU BinUtils. When compiling/linking an AIX program/library on AIX itself, only the native AIX assembler and linker are supported. The reason is that the native and GNU BinUtils linker require the object files to be specified in a different way, and we differentiate between the two based on the target OS on which the program has to be linked.

Cross-compiling

When cross-compiling, you not only need cross-BinUtils as explained above, but also a copy of the AIX libraries from the target system. These libraries are located in /usr/lib on the AIX system. On your build system, create a directory hierarchy like this:

 aixroot/
 aixroot/usr/
 aixroot/usr/lib/

After copying the contents of /usr/lib on the AIX system to aixroot/usr/lib to your build system, create a symbolic link called lib in the aixroot directory that points to usr/lib. If you are on a system that does not support symbolic links, you can simply create a directory called lib in aixroot and copy usr/lib/*.o into this lib directory.

Finally, when compiling for AIX always specify the full path to this aixroot directory via -XR/full/path/to/aixroot to the compiler.

Supported OS versions

IBM supports backward compatibility as long as you only use the system libraries for OS interfacing, which is what FPC does. The compiler and test suite have been verified as working on AIX 5.3, and hence should work on AIX 5.3 and later.

AIX quirks

Reading from NULL pointers

AIX does not raise an exception when reading from NULL pointers and other low addresses (up to 16KB on a test system, but there is no documentation about the upper limit). The reason is that this allows compilers to speculatively dereference pointers while scheduling code before NULL pointer checks. Writing to NULL pointers or other low addresses will still result in segmentation faults like on other supported platforms.

There is no system option to disable this behaviour. Since IBM's compiler makes extensive use of this property, doing so would result in many application crashes anyway since the system libraries have been compiled with this assumption.

FPC has added an extra code generation option titled -CN that instructs the compiler to add additional code to check that memory reads do not load data from such low addresses. If such an access is detected, a run time error 216 will be raised.

Unicode/code page support

Like on other UNIX and UNIX-like platforms, for unicodestring support FPC requires that libiconv functionality is available. On AIX, this library is not always installed by default. If it is not available, you can install it using the bos.rte.iconv package. Also install the bos.iconv.ucs.pc package if you want to support common Windows code pages.

AIX' libiconv is somewhat more limited than libiconv on most other platforms. In particular, its libiconv supports code page 866 only when converting from or to ISO-8859-5. These code pages both support the same Cyrillic characters, but are different in terms of special characters. This means that converting from UTF-8/16/32 to code page 866 will be lossy as far as those special characters are concerned.

Maximum number of processes/threads

By default, the maximum number of processes per user may be fairly limited (128 on a test system). Individual threads count as a process in this context. You can increase this limit by executing smit chgsys as superuser and then changing the Maximum number of PROCESSES allowed per user setting.

Maximum amount of memory per process

By default, the maximum amount of memory that a single process can allocate may be fairly limited (128MB on a test system). You can increase this amount by setting the LDR_CNTRL environment variable. E.g., export LDR_CNTRL=MAXDATA=0x20000000 in a Bourne sh-compatible shell will increase this amount to 256MB. See IBM's site for more information.

Shared library initialisation order

AIX does not guarantee the order in which dynamic libraries are loaded and initialised. In particular, its dynamic linker/loader does not follow library dependency chains and will not automatically initialise dependent libraries before others. AIX does however allow you to manually define priorities for each library to influence this initialization order. Getting this to work properly is however not easy.

Getting access to an AIX system

Via the GCC compile farm

The GCC compile farm offers free accounts to all developers of free and open source software packages for testing. Recently they added an AIX server to the pool of available machines. Note that many of the GNU utilities required to build and test FPC are not installed on that machine. You can work around that by adding /home/muller/bin to your path :)

Via IBM

Companies can register (for free) to become a member of the IBM PartnerWorld program. The only downside is that you cannot disable getting their (regular) commercial emails on your primary contact address.

Once you are a PartnerWorld member, you can (for free) make use of their Power Development Program. This program provides you with remote access via VPN to virtual machines running various versions of or Linux and AIX on various kinds of POWER processors (POWER 5, 6, 7 and 8). You have full root access to these VMs, and they can run continuously for up to 14 days at a time. You can however (automatically) save the contents of your virtual disk image on IBM's servers for use during subsequent reservations.