Skip to main content

Painless powerpc cross-compiling

As an ex-IBMer, I'm still quite fond of POWER/ppc64 processors, and occasionally cross-compile kernels for 64-bit little-endian PowerPC (ppc64el/ppc64le) from my amd64 system.

It's not immediately obvious what the simplest way to do this is. On Ubuntu (and I'm told, Debian) it is really very simple.

Installation

sudo apt install gcc-powerpc64le-linux-gnu

Congrats, you now have a ppc64le cross-compiling toolchain installed!

If you need other languages, g++/gccgo/gfortran/gnat/gobjc-powerpc64le-linux-gnu are also available.

Kernel

cd your/linux/source
make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- <your usual kernel build commands here>

That's it.

Userspace

It depends a bit on the build system. Here's how to build, for example, sed, which uses autotools (./configure and friends).

./configure --host powerpc64le-linux-gnu
make

That's it. 

For a dynamically linked binary, you only need the headers for any library dependencies to be installed on the build system. (Static linking is more involved.)

You can verify that it has been cross-compiled with file:

file sed/sed
sed/sed: ELF 64-bit LSB shared object, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked, interpreter /lib64/ld64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8b50e3cdb6f3478263c603377e60006128614966, with debug_info, not stripped

And, if you copy this to a ppc64le system, everything will work. I tested the resulting binary on an Ubuntu install on an emulated ppc64le system and it worked fine!

Things might be a bit trickier with CMake and other build systems, but generally you should be able to override the compiler to run powerpc64le-linux-gnu-gcc and disable anything that assumes you can run the built binary on the host system.

Enjoy the world of POWER!

Comments