z3bra, the stripes apart

cross-compiling with PCC and musl

16 August, 2015

TL;DR: See the full script here: It will create your toolchain in $HOME/cross/pcc-x86_64 and name the tools x86_64-linux-musl-*.

I've recently been playing around with PCC and musl, and to make the process of compiling softwares with them easier, I decided to setup a cross-compiler relying on both.

The process is (in theory) pretty simple:

  1. download and extract sources
  2. patch everything
  3. install linux headers
  4. build binutils
  5. build musl
  6. build pcc/pcc-libs
  7. (optionnal) add a pkg-config wrapper

1. grabbing sources

This part is pretty simple. You just need to choose which version of the software you want to use. Here is my list at the time of writing:

You can get the sources by following these links:

ftp://pcc.ludd.ltu.se https://www.kernel.org

Once you have all your tarballs, extract them somewhere.

2. patch everything

Everything doesn't need patching, but when you're playing with musl, you'll quickly realise how heavily softwares rely on the GNU libc.

GregorR did all the dirty job here, and provide patches for use with cross-compilers to work with musl. Check what's in, and grab those you might need.

The 1.1.0 version of pcc require some patching too, in order to work flawlessly with an alternative libc. It seems to be fixed in 1.2.0 (DEVEL version), if you're interrested. They fix the configure script to accept musl based targets, and fix the default library pass of the compiler.

3,4,5,6. build everything

For this part, just check the appropriate sections in the original script. You might want to enable shared libraries, or avoid compiling everything statically, so tweak it however you want.

For PCC, the PCCINCDIR and PCCLIBDIR are important, as they will tell the compiler where are the PCC libraries. The --with-incdir and --with-libdir parameters are used to tell the compiler where to search for default libraries, so make sure you set them properly.


You compiler should be ready to go! You can test it by running the following snippet:

    $ echo 'main(){}' > dummy.c
    $ PATH="$HOME/cross/pcc-x86_64/bin:$PATH"; export PATH
    $ x86_64-linux-musl-pcc dummy.c

For the sake of the experience, I also built a gcc cross-compiler using the same method, and tested both compilers on the libressl code base. The packages are simply tar.bz2 archives of libressl installed on a chroot (so there are only the libressl files):

    $ du -h libressl-*.pkg
    8.1M    libressl-gcc-2.1.6.pkg
    8.9M    libressl-glibc-2.1.6.pkg
    4.4M    libressl-pcc-2.1.6.pkg

Looks like we have a winner!