Thread overview
merge-2.067: Cross compiling for AArch64
May 05, 2015
Kai Nacke
May 07, 2015
Dan Olson
May 08, 2015
Kai Nacke
May 09, 2015
Dan Olson
May 18, 2015
Dan Olson
May 07, 2015
Temtaime
May 08, 2015
Kai Nacke
May 08, 2015
Temtaime
May 07, 2015
Johan Engelen
May 08, 2015
Kai Nacke
May 05, 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
May 07, 2015
"Kai Nacke" <kai@redstar.de> writes:

> The merge-2.067 is already in a good shape. I though I could try to cross compile to AArch64.

Nice.  I plan to follow in a month with hardware.
May 07, 2015
It's good to hear about aa64. But what about win32?
May 07, 2015
Great stuff. I think you should add this to the wiki somewhere!

-Johan
May 08, 2015
On Thursday, 7 May 2015 at 03:44:38 UTC, Dan Olson wrote:
> "Kai Nacke" <kai@redstar.de> writes:
>
>> The merge-2.067 is already in a good shape. I though I could try to
>> cross compile to AArch64.
>
> Nice.  I plan to follow in a month with hardware.

Note that the vararg code is currently horrible broken (ICE). Which hardware do you want to use? iPhone?

Regards,
Kai
May 08, 2015
On Thursday, 7 May 2015 at 19:08:13 UTC, Johan Engelen wrote:
> Great stuff. I think you should add this to the wiki somewhere!
>
> -Johan

I added the status to the wiki. Thanks for the hint.

Regards,
Kai
May 08, 2015
On Thursday, 7 May 2015 at 15:15:01 UTC, Temtaime wrote:
> It's good to hear about aa64. But what about win32?

Win32 exception handling is currently added to LLVM. If this is done I will create a native Win32 client.

(Yes, I consider the Windows platform important. But the exception handling stuff is very complicated and easily broken...)

Regards,
Kai
May 08, 2015
I'm glad to hear that :)
I'll try to build ldc with llvm trunk today i think as win64 target.
May 09, 2015
"Kai Nacke" <kai@redstar.de> writes:

> On Thursday, 7 May 2015 at 03:44:38 UTC, Dan Olson wrote:
>> "Kai Nacke" <kai@redstar.de> writes:
>>
>>> The merge-2.067 is already in a good shape. I though I could try to cross compile to AArch64.
>>
>> Nice.  I plan to follow in a month with hardware.
>
> Note that the vararg code is currently horrible broken (ICE). Which hardware do you want to use? iPhone?

Yeah - iPhone
May 18, 2015
Dan Olson <zans.is.for.cans@yahoo.com> writes:

> "Kai Nacke" <kai@redstar.de> writes:
>
>> On Thursday, 7 May 2015 at 03:44:38 UTC, Dan Olson wrote:
>>> "Kai Nacke" <kai@redstar.de> writes:
>>>
>>>> The merge-2.067 is already in a good shape. I though I could try to cross compile to AArch64.
>>>
>>> Nice.  I plan to follow in a month with hardware.
>>
>> Note that the vararg code is currently horrible broken (ICE). Which hardware do you want to use? iPhone?
>
> Yeah - iPhone

Oh, and an Android arm64 tablet too.  I have to wait until mid-summer though because I am in a busy spell right now.