Developing C/C++ cross-compiled applications for Linux on Power systems

A brief introduction to cross compiling, QEMU usermode, and IBM SDK for Linux on Power

The IBM® Software Development Kit (SDK) for Linux on Power is a free, Eclipse-based integrated development environment (IDE). The SDK integrates C/C++ source development with the Advance Toolchain, Post-Link Optimization, and classic Linux performance analysis tools, including Oprofile, Perf and Valgrind.

This article explains how to use the integrated environment provided by IBM SDK for developing cross-compiled applications for Linux on Power using IBM Advance Toolchain and QEMU usermode, which allows running and debugging applications compiled for one processor to run on a processor of a different architecture (that is, cross-compile/debug).

Requirements

For using the QEMU usermode within SDK, it is necessary to install IBM Advance Toolchain cross-compiler, QEMU usermode, and IBM SDK for Linux on Power.

For the purpose of this article, we used the following versions:

IBM Advance Toolchain cross compiler 8.0-1

IBM SDK for Linux on Power 1.6

QEMU usermode

Important: During the writing of this paper, when SDK 1.6 was launched, the packages that enabled the support for ppc64le (the little endian version of Linux on Power) were not available. In order to provide the latest improvements, the SDK team created an installable package for it.

The operational system used was Fedora 20.

Installing the IBM Advance Toolchain cross compiler

The IBM Advance Toolchain for PowerLinux™ is a set of open source development tools and runtime libraries which allows users to take leading edge advantage of the following latest IBM Power® hardware features (at the time of this publishing) on Linux,

IBM POWER8™ enablement

POWER8 optimized scheduler

POWER8 Transactional Memory enablement

OWER8 Crypto Operations enablement

POWER8 Fusion enablement

Perform the following steps to install IBM Advance Toolchain cross compiler.

Download the common package for AT 8.0-1 cross Download the ppc64le version of AT 8.0-1 cross Run the following commands to install both packages: $sudo yum install -y ./advance-toolchain-at8.0-cross-common-8.0-1.x86_64.rpm $sudo yum install -y ./advance-toolchain-at8.0-cross-ppc64le-8.0-1.x86_64.rpm

You can now notice that AT 8.0-1 cross is installed and available at /opt/at8.0.

Installing the x86_64 version of the SDK

The x86_64 version of IBM SDK supports the versions 7.0-1, 7.1-0, and 8.0-1. of IBM Advance Toolchain cross compiler. You can also use it for creating synchronized projects, which allows developing applications using a remote IBM Power server.

For more information about how to create synchronized projects, refer to SDK User Guide. If you want access a Power server, access the MiniCloud website and submit your request. It is free !

Back to SDK installation. Follow the steps below:

Download the x86_64 version of IBM SDK for Linux on Power Run the following command to install the package.

$sudo yum install -y ./ibm-sdk-lop-1.6.0-1.x86_64.rpm

Installing QEMU usermode

QEMU is a generic and open source machine emulator and virtualizer. The usermode allows launching processes compiled for one processor on another processor, which enables the running and debugging of cross-compiled applications.

When SDK 1.6 was launched, the version of the QEMU usermode available within the supported distros had not included the patches which provided support for ppc64le. To overcome this situation, the SDK team created an installable package for it.

To install QEMU usermode, perform the following steps.

Download the QEMU user-mode package. Run the following command to install the package.

$sudo yum install -y ./qemu-user-space-emulator-1-1.x86_64.rpm

Now, QEMU is ready to be used, but if you want to use the latest version of QEMU, you can build it locally. The process is very straightforward and the steps are described below:

Before you begin, ensure that you have Git installed.

Clone the QEMU source code using the following commands: git clone git://git.qemu.org/qemu.git cd ./qemu Create the build directory using the following commands: mkdir -p bin/debug/native cd bin/debug/native Install the dependencies using the command command:

$sudo yum install -y zlib.x86_64 glibc-devel.x86_64 zlib-devel.x86_64 pixman-devel.x86_64 libfdt-devel.x86_64 glib2-devel.x86_64 Configure the project using the following command:

../../../configure --disable-debug-tcg --enable-tcg-interpreter --target-list="ppc64abi32-linux-user ppc64le-linux-user ppc64-linux-user" --disable-vnc --extra-cflags="-O3" Run the following make command.

make -j5 Install the QEMU binaries using the following command.

$sudo make install

Important: after the installation, QEMU binaries are located at /usr/local/bin, but SDK expects them at /opt/ibm/qemu-user-space-emulator. The following steps provide a fix for this situation:

Create the directory using the following command:

$sudo mkdir -p /opt/ibm/qemu-user-space-emulator Copy the binaries from /usr/local/bin to /opt/ibm/qemu-user-space-emulator using the following command:

$sudo cp /usr/local/bin/qemu-ppc64 /usr/local/bin/qemu-ppc64abi32 /usr/local/bin/qemu-ppc64le /opt/ibm/qemu-user-space-emulator

Creating a cross-compiled project

Creating a cross compiled project using IBM SDK for Linux on Power is very simple. After completing the installation of Advance Toolchain, QEMU, and SDK installation, you can start developing your C/C++ cross-compiled application.

The first step is to start SDK. You can do it by selecting it either through the user interface or command line.

Using user interface:

Search for IBM SDK for Linux on Power 1.6.

Search for IBM SDK for Linux on Power 1.6. Using command line:

Run the following command: /opt/ibm/ibm-sdk-lop/ibm-sdk-lop When SDK is starting, you will be prompted to select a workspace. Figure 1. Define a workspace Then, after the workspace definition SDK will be read for using. Figure 2. SDK perspective Now, you can create your cross-compiled project. On the Getting Started tab, select either New IBM Advance Toochain C Project or IBM Advance Toolchain C++ Project. Figure 3. Selecting a project type After selecting the required project type, you need to set the configuration for your new project which includes name, location, type, and toolchain. Figure 4. Project configuration You can also tune your application by selecting the processor type. Figure 5. Tuning the application Click Finish to set up your project at the workspace previously created. It will be located on the Project Explorer tab. Figure 6. Project structure

Building a cross-compiled project

As your project is now created, you can build it. Select the project, right-click and then click Build Project.

Figure 7. Building the project

After the build process is completed, the cross-compiled binary are available under the Binaries node on the Project Explorer tab.

Figure 8. Build result

Running a cross-compiled project using QEMU usermode

To run your cross-compiled project using QEMU usermode, you need to perform the following steps.

Select your project, right-click and then click Run As → Qemu. Figure 9. Running a cross-compiled application with QEMU As this is the first time you are attempting to run your application with QEMU, it is necessary to configure a new launcher for the application. Figure 10. QEMU launcher configuration Now, you need to select the application. Click Browse. The Program Selection dialog box is displayed. Figure 11. Binary selection Click OK. Automatically, all the required fields will be filled in. The required fields are the QEMU location and the paths where the necessary libraries to run your application are located. Important: If your application depends on specific libraries, you need to handle the dependencies before trying to run it. Figure 12. Required fields To set the location for new libraries, click Browse in the Libraries Paths section. Figure 13. Libraries paths manager In the Libraries Paths dialog box, you can use the options New Path and Remove to add and remove a path location respectively. An optional step is to set the QEMU options. When selecting an option, its output will be included in a file called qemu.log, which is shown on the Project Explorer tab. The available options are shown in the following figure. Figure 14. QEMU options If you move the mouse pointer over any option, you can seea brief explanation (or tool tip) about it. For instance if you move the mouse pointer over the option int, you can see the description shown in the following figure. Figure 15. Quick tip Once you have configured all the options to run your application, click Run. You can see the output on the Console tab. Figure 16. Running an application Important: If you have selected any of the QEMU options, you need to update your application after running the application in order to be able to see the qemu.log.

Support

The tools shown in this article are free of charge. User support for the tools is through the community support in developerWorks. Questions, comments, and requests for help can be submitted through the forums located there and will be reviewed by experts.

Resources

Refer to the following resources for more information regarding IBM SDK, IBM Advance Toolchain, cross compilation and QEMU.

Downloadable resources