User Tools

Site Tools


cross-compiler-gentoo

====== Cross-compilation toolchain on Gentoo ====== ===== PowerPC toolchain ===== ==== Build ==== Install the crossdev tool if not already done:<code> # emerge crossdev</code> Configure USE flags for GCC:<code> # echo "cross-powerpc-softfloat-linux-gnu/gcc cxx -nocxx -fortran" >> /etc/portage/package.use/crosscompilation</code> Setup the toolchain:<code> # crossdev -S --target powerpc-softfloat-linux-gnu</code> Here is a cross-compiler for PowerPC:<code> $ 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. </code> ==== Basic test ==== Test the toolchain with the following program: <file c helloworld.c> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { printf("hello, PowerPC world!\n"); return 0; } </file> <code shell> $ 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 </code> ==== Advanced test ==== Install Qemu with PPC support:<code> # QEMU_SOFTMMU_TARGETS="ppc" QEMU_USER_TARGETS="ppc" emerge qemu </code> Run the helloworld program within qemu:<code> $ qemu-ppc ./helloworld /lib/ld.so.1: No such file or directory</code> 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:<code> $ 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 </code> 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:<code> $ 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! </code> It works! :-) ===== ARM toolchain ===== ==== Build ==== Install the crossdev tool if not already done:<code> # emerge crossdev</code> Configure USE flags for GCC:<code> # echo "arm-softfloat-linux-gnueabi/gcc cxx -nocxx -fortran" >> /etc/portage/package.use/crosscompilation</code> Setup the toolchain:<code> # crossdev -S --target arm-softfloat-linux-gnueabi</code> Here is a cross-compiler for ARM:<code> $ 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. </code> ==== Basic test ==== Test the toolchain with the following program: <file c helloworld.c> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { printf("hello, ARM world!\n"); return 0; } </file> <code shell> $ 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 </code> ==== Advanced test ==== Install Qemu with ARM support:<code> # QEMU_SOFTMMU_TARGETS="arm" QEMU_USER_TARGETS="arm" emerge qemu </code> Run the helloworld program within qemu:<code> $ qemu-arm ./helloworld /lib/ld-linux.so.3: No such file or directory</code> 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:<code> $ 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</code> 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:<code> $ qemu-arm /usr/arm-softfloat-linux-gnueabi/lib/ld-linux.so.3 --library-path /usr/arm-softfloat-linux-gnueabi/lib ./helloworld hello, ARM world! </code> It works! :-) ==== Prepare librohc dependencies ==== === For tests === In order to build and run librohc tests, install libpcap and cmocka for the ARM target:<code> # ARCH=arm arm-softfloat-linux-gnueabi-emerge -av libpcap cmocka </code> === 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):<code> # 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> </code> In order to build and run the Python module, install Python for the ARM target:<code> # # 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> </code> Then, install the Python's future extension:<code> # 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 </code> ===== MinGW toolchain for Windows ===== ==== Build ==== Install the crossdev tool if not already done:<code> # emerge crossdev</code> Setup the toolchain:<code> # crossdev -S --target i686-pc-mingw32</code> Here is a cross-compiler for Windows:<code> $ 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. </code> ==== Basic test ==== Test the toolchain with the following program: <file c helloworld.c> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { printf("hello, Windows world!\n"); return 0; } </file> <code shell> $ 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 </code> ==== Advanced test ==== Install Wine:<code> # emerge wine </code> Run the helloworld program within wine:<code> $ 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! </code> 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 17:58 by didier