merge-2.067: Cross compiling for AArch64

Kai Nacke via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Tue May 5 09:26:40 PDT 2015


Hi!

The merge-2.067 is already in a good shape. I though I could try 
to cross compile to AArch64.
Normally I use real hardware for porting but AArch64 metal is 
still rare. Here is what I did:

I am using Gentoo Linux. First I emerged qemu with 
QEMU_USER_TARGETS="aarch64". There is nothing special here - it 
compiles a qemu-aarch64 binary.

The next step was to create a cross compiler with crossdev:
USE="-fortran -sanitize" crossdev -t aarch64-pc-linux-gnu
This created  gcc 4.8.4, binutils 2.25 and glibc 2.20 for AArch64.
It is a bit tricky to find a working triple and the right 
versions to use.

In order to create the D libraries for AArch64, I needed to 
change the file runtime/CMakeLists.txt in the LDC source.
Before the main configuration I added

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER aarch64-pc-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-pc-linux-gnu-c++)

This tells CMake to use the cross compiler. I also added 
-mtriple=aarch64-pc-linux-gnu to the D_FLAGS variable.
Run cmake and compile with make -k. You might need to run make 
twice. There is still a problem with core.stdc.stdarg and phobos 
has still errors because of this.

The libraries in the lib folder are compiled for AArch64. Create 
a "Hello World" program and compile it with:
bin/ldc2 -mtriple=aarch64-pc-linux-gnu 
-gcc=aarch64-pc-linux-gnu-gcc 
-L-rpath=/usr/lib/gcc/aarch64-pc-linux-gnu/4.8.4

(I add the -rpath= option because I do not know how to tell qemu 
where to find libgcc_s.so.)

To execute the binary just type
qemu-aarch64 -L /usr/aarch64-pc-linux-gnu ./hello

Success!
I could also run a unittest - e.g. core.bitop.

I hope this post helps if someone wants to cross compile to a 
different architecture.

Regards,
Kai


More information about the digitalmars-d-ldc mailing list