User Tools

Site Tools


cross-compiler-gentoo

Cross-compilation toolchain on Gentoo

PowerPC toolchain

Build

Install the crossdev tool if not already done:

# emerge crossdev

Configure USE flags for GCC:

# echo "cross-powerpc-softfloat-linux-gnu/gcc cxx -nocxx -fortran" >> /etc/portage/package.use/crosscompilation

Setup the toolchain:

# crossdev -S --target powerpc-softfloat-linux-gnu

Here is a cross-compiler for PowerPC:

$ powerpc-softfloat-linux-gnu-gcc --version
powerpc-softfloat-linux-gnu-gcc (Gentoo 4.5.4 p1.0, pie-0.4.7) 4.5.4
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Basic test

Test the toolchain with the following program:

helloworld.c
#include <stdlib.h>
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	printf("hello, PowerPC world!\n");
	return 0;
}
$ powerpc-softfloat-linux-gnu-gcc -o helloworld -Wall -Werror helloworld.c
$ file helloworld
helloworld: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, with unknown capability 0x41000000 = 0x13676e75, with unknown capability 0x10000 = 0xb0402, not stripped

Advanced test

Install Qemu with PPC support:

# QEMU_SOFTMMU_TARGETS="ppc" QEMU_USER_TARGETS="ppc" emerge qemu

Run the helloworld program within qemu:

$ qemu-ppc ./helloworld
/lib/ld.so.1: No such file or directory

Qemu tried to use the dynamic loader of the build system :-(

Run the helloworld program within qemu, invoking the dynamic loader of the host system:

$ qemu-ppc /usr/powerpc-softfloat-linux-gnu/lib/ld-2.14.1.so ./helloworld
Invalid data memory access: 0x70a14008
NIP 1800a6fc   LR 1800a624 CTR 00000000 XER 00000000
MSR 00006040 HID0 00000000  HF 00006000 idx 0
TB 00000000 00000000
GPR00 00000000b03c0000 00000000188324e8 0000000000000000 00000000c8bf4010
GPR04 000000001801e5de 000000000000000b 0000000000000002 0000000000000003
GPR08 0000000000000000 0000000040500000 0000000080808080 000000000001b4ae
GPR12 0000000018010a5c 0000000000000000 0000000018832554 000000001883254c
GPR16 0000000000000000 0000000018032900 000000000000000a 0000000000000000
GPR20 0000000018032af0 0000000000000000 00000000c8bf4010 0000000070a13ff4
GPR24 000000001884f4ae 00000000180314c8 000000001000024c 000000006404ffff
GPR28 0000000032027fff 0000000000000000 0000000018031fe0 0000000018032878
CR 44042042  [ G  G  -  G  E  -  G  E  ]             RES ffffffff
FPR00 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR04 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR08 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR12 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR20 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR24 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPR28 0000000000000000 0000000000000000 0000000000000000 0000000000000000
FPSCR 00000000
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Erreur de segmentation

The dynamic loader tried to load some dynamic libraries from the build system :-(

Run the helloworld program within qemu, invoking the dynamic loader of the host system and loading the libraries from the host system too:

$ qemu-ppc /usr/powerpc-softfloat-linux-gnu/lib/ld-2.14.1.so --library-path /usr/powerpc-softfloat-linux-gnu/lib ./helloworld
hello, PowerPC world!

It works! :-)

ARM toolchain

Build

Install the crossdev tool if not already done:

# emerge crossdev

Configure USE flags for GCC:

# echo "arm-softfloat-linux-gnueabi/gcc cxx -nocxx -fortran" >> /etc/portage/package.use/crosscompilation

Setup the toolchain:

# crossdev -S --target arm-softfloat-linux-gnueabi

Here is a cross-compiler for ARM:

$ arm-softfloat-linux-gnueabi-gcc --version
arm-softfloat-linux-gnueabi-gcc (Gentoo 6.1.0) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Basic test

Test the toolchain with the following program:

helloworld.c
#include <stdlib.h>
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	printf("hello, ARM world!\n");
	return 0;
}
$ arm-softfloat-linux-gnueabi-gcc -o helloworld -Wall -Werror helloworld.c
$ file helloworld
helloworld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.32, not stripped

Advanced test

Install Qemu with ARM support:

# QEMU_SOFTMMU_TARGETS="arm" QEMU_USER_TARGETS="arm" emerge qemu

Run the helloworld program within qemu:

$ qemu-arm ./helloworld
/lib/ld-linux.so.3: No such file or directory

Qemu tried to use the dynamic loader of the build system :-(

Run the helloworld program within qemu, invoking the dynamic loader of the host system:

$ qemu-arm /usr/arm-softfloat-linux-gnueabi/lib/ld-linux.so.3 ./helloworld
./helloworld: error while loading shared libraries: libc.so.6: wrong ELF class: ELFCLASS64

The dynamic loader tried to load some dynamic libraries from the build system :-(

Run the helloworld program within qemu, invoking the dynamic loader of the host system and loading the libraries from the host system too:

$ qemu-arm /usr/arm-softfloat-linux-gnueabi/lib/ld-linux.so.3 --library-path /usr/arm-softfloat-linux-gnueabi/lib ./helloworld
hello, ARM world!

It works! :-)

Prepare librohc dependencies

For tests

In order to build and run librohc tests, install libpcap and cmocka for the ARM target:

# ARCH=arm arm-softfloat-linux-gnueabi-emerge -av libpcap cmocka

For Python binding

In order to build and run the Python module, install Python 3.5 for the host target (Python 3.3 and 3.4 seem not to cross-compile fine at the moment on Gentoo Linux):

# USE=-ncurses ACCEPT_KEYWORDS=~amd64 emerge -av dev-lang/python:3.5
# eselect python list --python3
# eselect python set --python3 <id of python 3.5>

In order to build and run the Python module, install Python for the ARM target:

# # eselect requires ncurses that fails to cross-compile, and it is not very useful,
# # so let's emerge think it is installed
# echo 'app-admin/eselect-1.4.6' >> /usr/arm-softfloat-linux-gnueabi/etc/portage/profile/package.provided
# # disable ncurses and readline support for python since ncurses fails to cross-compile
# USE="-ncurses -readline" \
  ARCH=arm arm-softfloat-linux-gnueabi-emerge -av dev-lang/python:3.5
# eselect python list --python3
# eselect python set --python3 <id of previous python version>

Then, install the Python's future extension:

# echo '=dev-python/future-0.15.2 **' >> /usr/arm-softfloat-linux-gnueabi/etc/portage/package.accept_keywords
# ARCH=arm PYTHON_TARGETS="python3_5" arm-softfloat-linux-gnueabi-emerge -av1 dev-python/future

MinGW toolchain for Windows

Build

Install the crossdev tool if not already done:

# emerge crossdev

Setup the toolchain:

# crossdev -S --target i686-pc-mingw32

Here is a cross-compiler for Windows:

$ i686-pc-mingw32-gcc --version
i686-pc-mingw32-gcc (Gentoo 4.5.3-r2 p1.1, pie-0.4.7) 4.5.3
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Basic test

Test the toolchain with the following program:

helloworld.c
#include <stdlib.h>
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	printf("hello, Windows world!\n");
	return 0;
}
$ i686-pc-mingw32-gcc -o helloworld -Wall -Werror helloworld.c
$ file helloworld
helloworld: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

Advanced test

Install Wine:

# emerge wine

Run the helloworld program within wine:

$ wine ./helloworld
err:xrandr:xrandr12_init_modes Failed to get output info.
err:xrandr:xrandr12_init_modes Failed to get output info.
err:xrandr:xrandr12_init_modes Failed to get output info.
hello, Windows world!

Except for some problems related to display/graphic (that we don't care for the ROHC library), it works! :-)

cross-compiler-gentoo.txt · Last modified: 2016/07/03 19:58 by didier