Ehem, ARM
Joakim
joakim at airpost.net
Fri Nov 22 10:01:40 PST 2013
On Friday, 15 November 2013 at 10:31:40 UTC, Elvis Zhou wrote:
> On Friday, 15 November 2013 at 06:18:00 UTC, Joakim wrote:
>> Also, does dmd have any support for cross-compilation or is it
>> better to stick to ldc/gdc when cross compiling to Android?
>
> A month ago I tried to cross compile a Hello World for Android
> with ldc on Debian7 x64 with android_ndk_r9 but failed with
> lots of link errors. One of those issues reveal that qsort is
> absent from Android stdlib, I get over it by grabbing a qsort.c
> and it works. Other issues are beyond my knowledge and I'm too
> busy to continue, hope I can take some time to hack on this
> late this month.
What did you modify in ldc to try and get it to work with the NDK
and compile an Android-compatible binary?
I spent some time setting up the appropriate VMs and looking at
the relevant Android dev tools myself. It appears that the
Android NDK uses a lightly patched version of stock llvm/clang
3.3, along with the gold linker. Their patches are available
online:
https://android.googlesource.com/toolchain/llvm/+log/release_33
https://android.googlesource.com/toolchain/clang/+log/release_33
Their llvm is the same as llvm 3.3 until commit ce33750 and clang
is the same until commit 20c7d45. The stock llvm/clang 3.3 have
some limited support for Android, not much. I'm going to start
going through those patches next.
Since there are only about 50-100 llvm/clang patches, many of
them architecture-specific and so not necessary, this suggests
that the Android ABI is not that different from linux. Although,
when I ran ldd from Arch linux on an x86 sample app compiled by
the NDK, it said "error while loading shared libraries:
/usr/lib/libc.so: invalid ELF header," suggesting there is some
difference. They wrote their own ldd for the NDK, which works
fine with their generated code:
https://android.googlesource.com/platform/ndk/+/master/sources/host-tools/ndk-depends/ndk-depends.cc
Turns out I was wrong earlier when I said I'd compile D to pure
native, as opposed to a shared library pulled in through JNI, as
the former is not possible on Android. I saw some docs earlier
where they said you can write pure native apps now and you can,
but I now see that you still have to compile it to a shared
library, because they want everything sandboxed within Dalvik.
You provide an android_main function as the entry point from
Dalvik into the native app/library, so shared library support and
some JNI compatibility are necessary for D to work on Android.
It appears the next steps to get D working on Android/x86 are:
1) Get a basic D "hello world" shared library to compile and run
on Android, by modifying dmd to generate an Android-compatible
shared library.
2) Get druntime and phobos working as much as possible.
3) Translate the remaining native Android API headers so they can
be called from D.
I was hoping to mostly work on 2), but it appears there's some
work for 1) that has to be done first. If anybody else wants to
help with 1), you too can take a look at the above llvm/clang
commits and let us know what you find.
More information about the Digitalmars-d
mailing list