advtool-cross-compilers

Advance Toolchain for Linux on Power cross-compiler

The Advance Toolchain provides cross-compilers that run on Intel x86 and generate code for Power that helps teams to start developing for Power without having immediate access to a POWER server. The cross-compiler provides a way to compile programs for POWER by using a x86 (i386) or x86-64 (amd64) computer, helping teams to start developing for POWER without having access to a server in the early development phase.

IBM Advance Toolchain for Linux on Power 15.0-7 is now available! Learn more

Install the cross-compiler

Use these steps to download the public key, create a repository configuration file, and install the cross-compiler package.

  1. The gpg public key is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the gpg public key for your Linux distribution and import it by using the following commands, replacing RHELX with the Red Hat release that you are using and PUBKEY with its respective value.
    • For RHEL8, the gpg public key is: gpg-pubkey-6976a827-5164221b
    • For RHEL9, the gpg public key is: gpg-pubkey-615d762f-62f504a1
    wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/RHELX/PUBKEY
    sudo rpm --import PUBKEY
    
  2. Create a configuration file for the Advance Toolchain repository configuration file: /etc/yum.repos.d/advance-toolchain.repo. Add the following content:
    # Begin of configuration file
    [advance-toolchain]
    name=Advance Toolchain IBM FTP
    baseurl=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/RHELX
    enabled=1
    gpgcheck=1
    gpgkey=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/RHELX/PUBKEY
    # End of configuration file
    
  3. Install the cross-compiler by running yum install: yum install advance-toolchain-atX.X-cross-ppc64le

Use these steps to download the public key, create a repository configuration file, and install the Advance Toolchain packages.

  1. The gpg public key gpg-pubkey-6976a827-5164221b is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the gpg public key for your Linux distribution and import it by using the following commands:
    wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/RHEL8/gpg-pubkey-6976a827-5164221b
    rpm --import gpg-pubkey-6976a827-5164221b
    
  2. Create a configuration file for the Advance Toolchain repository configuration file: /etc/yum.repos.d/advance-toolchain.repo. Add the following content:
    # Begin of configuration file
    [advance-toolchain]
    name=Advance Toolchain IBM FTP
    baseurl=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15
    enabled=1
    gpgcheck=1
    gpgkey=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15/gpg-pubkey-6976a827-5164221b
    # End of configuration file
    
  3. To install the cross-compiler by using YAST, follow these steps:
    1. Run yast2 as root.
    2. Select Add-on Product.
    3. From Media Type, select the FTP Protocol: (x) FTP...
    4. Under Server name, enter public.dhe.ibm.com.
    5. Under Directory on Server, enter /software/server/POWER/Linux/toolchain/at/suse/SLES_15

      You get a warning about there being no product information available. The warning shows up because the repomd-based repository does not contain the YaST product information. It's not a bug. Select [Continue].

    6. Under the Software Management interface, search for "advance toolchain", and select advance-toolchain-atX.X-cross-ppc64le.
  4. To install the cross-compiler with Zypper:
    1. As root, add the IBM FTP to the repository list:
      zypper addrepo https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15 "Advance Toolchain"
      

      This command creates a new repository entry called "Advance Toolchain" pointing to the IBM FTP site

    2. To install the cross-compiler, run the following command: zypper install advance-toolchain-atX.X-cross-ppc64le

Use these steps to download the public key, create a repository configuration file, and install the cross-compiler package

  1. The gpg public key is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the gpg public key for your Linux distribution and import it by using the following commands:
    • For Ubuntu 20.04:
      wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu/dists/focal/6976a827.gpg.key
      sudo apt-key add 6976a827.gpg.key
      
    • For Debian 11, Debian 12 or Ubuntu 22.04:
      wget -qO- https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu/dists/jammy/615d762f.gpg.key | sudo tee -a /etc/apt/trusted.gpg.d/615d762f.asc
      
  2. Configure the Advance Toolchain repositories by adding the following line to /etc/apt/sources.list:

    On ppc64el or amd64:

    • When you install on Ubuntu 22.04 (jammy) or Ubuntu 20.04 (focal), point to its respective repository:
      deb [signed-by=/etc/apt/trusted.gpg.d/615d762f.asc] https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu jammy atX.X
      deb https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu focal atX.X
      
    • When you install on Debian 12 (bookworm) or Debian 11 (bullseye), point to its respective repository:
      deb [signed-by=/etc/apt/trusted.gpg.d/615d762f.asc] https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/debian bookworm atX.X
      deb [signed-by=/etc/apt/trusted.gpg.d/615d762f.asc] https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/debian bullseye atX.X
      
  3. Refresh the cache by running: sudo aptitude update or sudo apt update.
  4. Install the cross-compiler by running sudo aptitude install advance-toolchain-atX.X-cross-ppc64le or sudo apt install advance-toolchain-atX.X-cross-ppc64le.

APT supports package upgrades for new revision releases (that is 7.1-0 to 7.1-1). For new major releases (that is 7.1-1 to 8.0-0), proceed as in a normal installation.

Build a sample program

GNU wget is a small program that highlights the important problems when cross compiling a certain software: it depends on libraries provided by the Advance Toolchain cross-compiler and external libraries.

In this example, we build GNU wget for POWER little endian by using a x86 computer with the Advance Toolchain cross-compiler.

Copy headers and libraries

First, copy all necessary libraries and headers to a certain directory. This example uses the following libraries and headers:

  • Headers: ${HOME}/wget/include
  • Libraries: ${HOME}/wget/lib

In this case, ${HOME} is a shell variable holding the path of my home directory.

For GNU wget, we need to provide some OpenSSL libraries and Zlib. Both of them are available in the Advance Toolchain native compiler. However, the list of necessary libraries might vary according to the project. If you don't know well the project, you can use the following tools in order to identify the list of libraries they use:

ldd <executable>
rpm -q --requires -p <package.rpm>
dpkg-deb -f <package.deb> | grep "Depends:"

Usually the list of libraries necessary to build a project is the same across all processor architectures. So, you might use the previous commands against an executable or package compiled for another processor.

Here is the list of files required in order to build wget:

$ ls -1 ${HOME}/wget/include/
openssl/
zconf.h
zlib.h
$ ls -1 ${HOME}/wget/lib/
libcrypto.so
libcrypto.so.1.0.0
libssl.so
libssl.so.1.0.0
libz.so
libz.so.1
libz.so.1.2.6

Make sure the libraries are compiled for the target processor. If they don't match, you don't be able to use them. You might use readelf -h to verify this information:

$ /opt/at7.1/bin/powerpc64le-linux-gnu-readelf -h ${HOME}/wget/lib/libz.so.1.2.6
...
 Data:                              2's complement, little endian
...
 Machine:                           PowerPC64
...

Build

With the header files and libraries in place, the system is ready to start the build. So, create a separate build directory:

mkdir ${HOME}/wget/build && cd ${HOME}/wget/build

After you enter the separate build directory, it's possible to configure the build by running:

CC=/opt/at7.1/bin/powerpc64le-linux-gnu-gcc \
CFLAGS="-I${HOME}/wget/include" \
LDFLAGS="-L${HOME}/wget/lib" \
       ../wget-1.15/configure \
               --host=powerpc64le-linux \
               --with-ssl=openssl

Where:

  • The variable CC specifies which compiler to use. In this case, Advance Toolchain 7.1 cross-compiler for POWER little endian. Cross-compilers usually have a prefix in their program name to clearly indicate they don't generate executable code for the current processor. In this case, the prefix is "powerpc64le-linux-gnu-". This rule applies to all programs, for example: g++, gdb, ld, as, etc
  • The variable CFLAGS="-I" indicates where the compiler finds the header files.
  • The variable LDFLAGS="-L" indicates where the linker finds the libraries.
  • This ../wget-1.15 is the directory where wget source code is available. In this case, it is the same of ${HOME}/wget/wget-1.15.
  • The option --host=powerpc64le-linux indicates this code runs on POWER little endian.
  • The option --with-ssl=openssl forces wget to use OpenSSL.

Finally, build wget by using the make command:

make

After you run this command, you'll find the program available at ${HOME}/wget/build/src/wget.

You can now copy it to a POWER little endian system with the Advance Toolchain runtime package installed and run it.

Frequently asked questions (FAQ)

Get answers to some of the most frequently asked questions about working with the cross-compiler.

Are cross-compiler builds slower?

Not necessarily. It depends on the code being built and the level of optimization in use.

If I build a program by using a cross-compiler, will it be slower than by using a native toolchain?

No. There are some differences in the metadata of the binaries, but it runs at the same speed.

My project doesn’t allow passing flags to the linker or to the compiler. How can I use extra libraries?

In this case, it isn’t possible to pass -I to the compiler or -L to linker and the only possible solution is to save the headers and libraries in one of the Advance Toolchain directories:

For POWER little endian (ppc64le):

/opt/atX.X/ppc64le/usr/include
/opt/atX.X/ppc64le/usr/lib64

Be careful to not override any Advance Toolchain files while you are copying the files.