[an error occurred while processing this directive] [an error occurred while processing this directive]
Porting Intel Applications to 64 bit Linux PowerPCt
Introduction
About PowerPC Architecture
About SLES 8
Compiler Sets and Architecture Awareness
Porting with the GCC Compiler Set
Porting with the Visual Age Compiler Set
Java
Conclusion
Reference
About the author
Rate this article
Subscribe to the developerWorks newsletter
developerWorks Toolbox subscription

Level: Intermediate

Matt Davis (matdavis@us.ibm.com )
Technical Consultant, IBM
June 6, 2003

Linux PowerPC provides a platform for the development and deployment of 32 bit applications that would benefit from a 64 bit environment. This article addresses porting software from the Intel platform to Linux PowerPC with both of these compiler sets.

Introduction
Linux PowerPC provides a platform for the development and deployment of 32 bit applications that would benefit from a 64 bit environment. Equipped with a 64 bit kernel and application space, large commercial and computation intensive applications can utilize larger address spaces on the Linux PowerPC platform. Applications can be compiled with either the GNU Compiler Collection provided by the Free Software Foundation, or the VisualAge compiler set available from IBM. GCC’s strength rests in its standardization across several types of hardware, and therefore the robust portability of code written to be compiled with GCC compilers. However, the nature of the GNU license and the standardization of GCC prohibit the GCC compilers from taking full advantage of specialized architectures, e.g. IBM eServers that feature PowerPC architecture. Since the VisualAge compilers may offer a performance increase upwards of 30% compared to GCC on this high performance hardware, many vendors will want to compile binaries with the VA compilers. This document addresses porting software from the Intel platform to Linux PowerPC with both of these compiler sets.

About PowerPC Architecture
Performance Optimized with Enhanced RISC (POWER) architecture is the result of more than a decade of hardware engineering dating to the POWER1 chips released in 1990. The POWER1 was IBM’s first commercial RISC processor and debuted at 25 Mhz clock speed. POWER4, the current IBM RISC processor offering operates at speeds between 1.1 and 1.45 Ghz. With the extensive parallelism and optimization in the hardware of the current implementations, PowerPC can deliver more computation per cycle than other chip architectures. Announced in 2001, POWER4 chips feature two 64 bit microprocessors per CPU board and support SMP configurations up to 32 way. In addition to the POWER4 hardware, Linux PowerPC also runs on IBM eServer hardware featuring POWER3 and RS64IV hardware. These architectures both feature 64 bit SMP capability and copper fabrication technology, but whereas the RS64IV processors are still actively developed, POWER3 is considered the legacy predecessor to POWER4. Each of the PowerPC derived chips offers industry leading performance and provides a world class hardware platform for the deployment of Linux PowerPC.

About SLES 8
SuSE Linux, available for more than 10 years, offers two levels of Linux distribution. SuSE Linux 8.0 is intended for workstation environments, and SuSE Linux Enterprise Server version 8 (SLES 8) for enterprise systems. SLES 8 for PowerPC is the product of more than three years of collaboration between SuSE, IBM, and the open source community. In addition to providing a 64 bit kernel for the PowerPC architecture, SLES 8 now includes a 64 bit runtime environment and GCC toolchain for building 64 bit versions of popular open source software (e.g. the Apache web server and MYSQL). Combined with IBM’s VA Compilers for performance critical applications, the 64 bit Linux PowerPC environment offered by SLES 8 on IBM iSeries and pSeries hardware delivers an unparalleled platform for developing and deploying Linux solutions. For more information on SuSE Linux, see http://www.suse.com/us/company/index.html

Compiler Sets and Architecture Awareness
Unlike other Linux platforms, Linux PowerPC offers not only GCC, but also the IBM VA Compiler set. GCC offers robust portability of code intended for compilation in Linux, while the VA Compilers offer a substantial performance increase over GCC. Both compilers offer 32 and 64 bit compilation modes, and the Linux PowerPC environment allows both 32 and 64 bit code to be run simultaneously without a performance loss.

Linux PowerPC varies from Linux Intel in that it is both Big Endian (left to right assignment of addresses to bytes in a data word) and 64 bit. Much has been written on byte-ordering and the PowerPC architecture. For an excellent review of addressing endian concerns, please see chapter 2 of the AIX 5L Porting Guide. Another practical and concise reference on this topic can be found at http://ibm.com/servers/esdd/articles/mig_tru64aix.html, Migrating Tru64 Applications to AIX. These references may prove particularly useful when migrating code with the VA Compilers.

Regarding 64 bit code, a long variable type is not the same as an int. On ppc64, an ints is 4 bytes and longs are 8 bytes. Addresses are also 8 bytes. Never cast a pointer to an int in 64 bit code; this would mismatch 32 and 64 bit data types.

Take time to ensure that bit-specific code is endian friendly and that libraries are the correct versions and the migration to 64 bit Linux PowerPC should be natural.

Porting with the GCC Compiler Set
In general, porting code with GCC compilers should be straightforward. Architecture may vary, and occasionally library version discrepancies may arise, but for the most part, GCC is GCC, no matter which architecture it runs on. Architecture specific flags are discouraged for compilation on Linux PPC (for example, –m486, -powerpc), as GCC does not have extensive processor maps for optimization routines on these architectures. Also, without architecture specific flags, binary compatibility will be greater across different models of PowerPC hardware.

64 bit GNU compilers for Linux PPC are provided at no cost from http://linuxpcc64.org. These compilers are included in SLES 8 as well. The compilers should be installed to a directory under /opt/ and Makefiles for source code should be altered to reflect the location of the 64 bit GNU compilers. By default, this location is /opt/cross. In some cases, environment variables will need to be set to reflect the location of the compilers as well.

The libraries for the 64 bit toolchain are located under the 64 bit toolchain directory tree, so it is important to properly modify the library and compiler path environment variables. Occasionally, the libraries called by code intended for 32 bit compilation will have slight name variations in the 64 bit toolchain. In these cases, a simple symbolic link to the correct library should resolve the issue. Individual examples of such inconsistencies vary by point release of the toolchain, and tend to be resolved at the next release. It is important to report these errors to the bug tracking system located at http://linuxppc64.org.

When linking, an undefined references error may be encountered. When followed by relocation truncated to fit: R_PPC_REL24, these may be ignored. However, when these errors are not paired in such a manner, they reflect a genuine code error. If a reference is undefined, then correct it. Likewise, if a greater-than 24 character relocation is generating an error, this should be corrected as well.

On all architectures, libraries must be compiled with –fPIC; IA32 has this flag applied by default with GCC. This flag creates position independent code, thereby dynamically linking to shared libraries.

Developers not familiar with the GPL should reference it carefully and make sure the terms and conditions of the license are understood.

Porting with the Visual Age Compiler Set
Compiling code with the VA compiler set has in many cases shown a significant performance increase on Linux for IBM eServers featuring PowerPC hardware. These compilers, migrated from the high performance compiler set used on AIX, have extensive optimization routines for PowerPC hardware, and therefore should be used for any application that wants to take full advantage of the PowerPC architecture’s potential. However, software originally intended to be compiled with GCC compilers may need more attention when recompiled with VA compilers. Makefiles need to be edited to reflect the correct path to the VA compilers, by default /opt/ibmcmp/. The correct optimization flags should also be set for the specific architecture (for example, -03 –qarch=pwr4 –qtune=pwr4 for IBM POWER4 hardware). In addition to optimization modes for various PowerPC architecture derivatives, the VisualAge compilers can be instructed to compile software in common mode. This guarantees compatibility across all types of PowerPC architecture at the expense of performance otherwise gained through architecture-specific optimization. When compiling 64 bit code, the compiler must be given the flag for a 64 bit build (-q64), as it defaults to 32 bit mode.

As opposed to GCC, the Visual Age Compilers do not create object code directly. First, an intermediate language called .w code is generated, which is fed back to the compiler’s backend optimizer. The optimizer explores variations on the code until the most efficient method is determined. Following this, the compiler generates .o files, and then the final binaries.

A few tips to compiling GCC oriented code with the VisualAge compiler set are:

  • C++ comments: GCC allows C++ style commenting to be used in C files by default, but this is not the case with XLC, the VisualAge C compiler. Since it is not economical to change all the comments in a group of source files to comply with C style commenting, XLC provides a –q argument to allow these comments, -q cpluscmt. When C code is compiled with this flag, both C and C++ style commenting is interpreted.
  • Environment variables are often the easiest way to configure build scripts. As opposed to hand editing Configure scripts and Makefiles, it is recommend that relevant environment variables such as $CC and $CFLAGS be set and the Configure script be allowed to generate the Makefile without the need for hand editing.
  • Configure scripts also need to be aware of the proper platform type. This will be either linux-powerpc-unknown-gnu or linux-powerpc64-unknown-gnu. This should be set for compilation with either GCC or VA by appending the –target=flag to the Configure script.

Although extensive documentation for the VisualAge compilers exists, an argument list is provided at the console by running the compiler with no arguments,for example, $COMPILER_PATH/bin/cc.

Java
In previous distributions of Linux PowerPC, the Blackdown JDK was the only available development kit. Blackdown, while renowned for offering a highly compatible JDK, has not boasted the performance the IBM JDK has delivered to Java applications on Linux Intel and AIX platforms. Yet, thanks to the joint effort of IBM, SuSE, and the open source community, Java migration to Linux PowerPC is now powered by the IBM JDK version 1.3.1. The IBM JDK offers the formal compliance to Java Standards and enterprise class performance expected from IBM development kits. Addition performance gains may be found by recompiling requisite C libraries with the VA Compilers. For more information on the IBM JDK, see IBM Developer Kits for Linux.

Developers not accustomed to developing with the IBM JDK should reference documentation available at Java technology. This may be helpful for understanding optimal levels of for example, garbage collection, and JNI usage.

Conclusion
Linux PowerPC offers an enterprise class Linux environment, complete with 64 bit kernel, application environment, and toolchains. Unlike other Linux environments, Linux PowerPC offers twin compiler sets representing the best of both worlds: ease of migration with open source code and high performance exploitation of the award winning high performance PowerPC architecture. As a result of more than three years of cooperation between IBM, SuSE, and the open source community, SLES 8 has emerged as a genuine enterprise class distribution and a leader in its field. Application performance available on the PowerPC architecture is now augmented by development tools never before offered on the Linux operating system. In summary, Linux PowerPC is the leading platform for the deployment of high performance Linux applications.

Reference
Where to find Compliers

The best source for GCC compilers for Linux PowerPC is from a certified IBM Linux vendor, such as SuSE Linux, as these vendors have taken efforts to build GCC and its libraries to minimize any version discrepancies.

VisualAge compilers can be found at http://ibm.com/software/awdtools/vacpp/. The beta program for the compilers is located at http://ibm.com/developerworks/offers/linux-speed-start/download-p.html. PartnerWorld members can find the VisualAge compilers in the DeveloperWorks Software Mall at http://developer.ibm.com/welcome/softmall.html.

Community Resources

  1. http://gcc.gnu.org
  2. http://linuxppc64.org
  3. http://ibm.com/developerworks/linux/

About the author
Matt Davis is a Linux technical consultant in the IBM eServer Solutions Enablement team. As a member of the pSeries Linux project since its inception, he explored and tested emerging technology for pSeries Linux and wrote several reports summarizing his findings. These include Journaling File Systems for Linux for POWER, Parallel Grid Computing with Linux for POWER, Open Source Alternatives to Commercial Software for Linux for POWER, and the Linux Solutions Catalog, to name a few. He came to IBM as an intern during his tenure as a student at the University of Texas at Austin, from which he earned two degrees with academic honors.


  About IBM   |   Privacy   |   Legal   |   Contact IBM