Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ada on Android and iOS?

843 views
Skip to first unread message

coding...@gmail.com

unread,
Jan 22, 2014, 6:39:51 AM1/22/14
to
Hi,

I am interested in developing commercial Ada software for Android and iOS (both of which I have never developed for, btw). I've spent several days trying to figure out how to create my own cross compiler for the ARM processor. Below are some of the links I've been using as reference.

http://gcc.gnu.org/install/
http://cross-lfs.org/view/CLFS-2.1.0/x86_64-64/index.html
https://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html
http://wiki.osdev.org/Building_GCC
http://wiki.osdev.org/GCC_Cross-Compiler
http://www.linux.com/community/blogs/127-personal/468920-cross-compiling-for-arm

Since both iOS and Android have a native interface API to allow people to develop software in languages other than Objective-C and Java, I am really hoping all I need to do is the following:

1) Compile my own native version of GCC 4.8.2 with Ada enabled. Let's call this My_Native_GCC (Note: I know I can just use 4.6, but I'd like to use the latest version of GCC)

2) Copy the header files of the target platform into my own target root directory

3) Compile and install a cross version of binutils 2.24 with My_Native_GCC.

4) Use My_Native_GCC to compile a minimal version of GCC that does not depend on GLIBC and outputs code for the target platform. Let's call this Min_Target_GCC. (NOTE: This is really for Android since they have the crappy Bionic libc)

5) Use Min_Target_GCC to compile and install a new version of GLIBC for the target platform.

6) Use Min_Target_GCC to compile and install a full version of GCC that generates code for the target platform and uses the new GLIBC.

So far, I've only attempted to do the above for the Android platform. I was successful in creating my own GCC 4.8.2 with Ada enabled. The only weird thing about my version is that I always need to use -I to include the paths of the C++ header files for my version of GCC. Otherwise, it can't find files like cstring.

For step 2, I downloaded the latest r9c of the Android NDK and copied over the contents of ~/android-ndk-r9c/platforms/android-17/arch-arm/usr/include into my own target root directory. Since GLIBC requires headers for Linux v2.6.19 or higher, and the NDK is bundled with Linux headers v2.6.18 (per the version.h file they include), I ended up grabbing the 3.0.31 Linux headers from Samsung's website http://opensource.samsung.com via their Jelly Bean update Zip file SGH-I747_JB_Opensource_Update1.zip. My phone is the ATT S3 model, btw.

Step 3 and 4 completed without problems. However, I am now stuck at Step 5. The building of the new GLIBC fails on ../sysdeps/unix/sysv/linux/gethostid.c with the following error:

### make[2]: Entering directory `/home/rascal/workspace/cross_build/glibc-2.18/src/misc'
### /opt/custom_tools/cross/android/api/17/arm-linux-androideabi/bin/arm-linux-androideabi-gcc-4.8.2 ../sysdeps/unix/sysv/linux/gethostid.c -c -std=gnu99 -fgnu89-inline -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes -fexceptions -I../include -I/home/rascal/workspace/cross_build/glibc-2.18/build/misc -I/home/rascal/workspace/cross_build/glibc-2.18/build -I../ports/sysdeps/unix/sysv/linux/arm/nptl -I../ports/sysdeps/unix/sysv/linux/arm -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../ports/sysdeps/unix/arm -I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -I../ports/sysdeps/arm/nptl -I../ports/sysdeps/arm/include -I../ports/sysdeps/arm -I../ports/sysdeps/arm/soft-fp -I../sysdeps/wordsize-32 -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../nptl -I../ports -I.. -I../libio -I. -nostdinc -isystem /opt/custom_tools/cross/android/api/17/arm-linux-androideabi/lib/gcc/arm-linux-androideabi/4.8.2/include -isystem /opt/custom_tools/cross/android/api/17/arm-linux-androideabi/lib/gcc/arm-linux-androideabi/4.8.2/include-fixed -isystem /opt/custom_tools/cross/android/api/17/arm-linux-androideabi/include -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DPIC -o /home/rascal/workspace/cross_build/glibc-2.18/build/misc/gethostid.o -MD -MP -MF /home/rascal/workspace/cross_build/glibc-2.18/build/misc/gethostid.o.dt -MT /home/rascal/workspace/cross_build/glibc-2.18/build/misc/gethostid.o
### ../sysdeps/unix/sysv/linux/gethostid.c: In function 'gethostid':
### ../sysdeps/unix/sysv/linux/gethostid.c:71:17: error: 'MAXHOSTNAMELEN' undeclared (first use in this function)
### char hostname[MAXHOSTNAMELEN + 1];
### ^
### ../sysdeps/unix/sysv/linux/gethostid.c:71:17: note: each undeclared identifier is reported only once for each function it appears in
### ../sysdeps/unix/sysv/linux/gethostid.c:71:8: warning: unused variable 'hostname' [-Wunused-variable]
### char hostname[MAXHOSTNAMELEN + 1];

I tried compiling a native version of GLIBC to see if I get the same error, but it compiled just fine. So it appears to be an issue when I have the build process use my designated target root path that includes the header files from the Android NDK and the Galaxy S3 header files. But before I continue spending a great deal of time investigating this error, I'd like to know the following:

1) Will the 6 step process I laid out above only lead me to a dead end? I know about GNATdroid. The main reason why I am trying to avoid using GNATdroid is because I am hoping I can figure out a common process that allows me to create toolchains for both Android and iOS (hopefully, with the need to simply switch between the set of header files between the two platforms).

2) Does GNAT work with the Bionic library even though it doesn't implement the entire C runtime and is not POSIX compliant. I'd like to be able to use Ada tasks and protected types on Android.

3) Does GNAT work with EGLIBC and uCLIBC?

4) GNATdroid is built for Android 2.3. Does this mean an Ada Android app is limited to the capabilities of that old Android API? If yes, then is there any chance GNATdroid will be updated to a more recent version of Android (preferably Jelly bean)?

BTW, my development machine is Kubuntu 13.10 running on a Core-i7 based laptop.

Thanks.

Coding Rascal

Ludovic Brenta

unread,
Jan 22, 2014, 10:43:51 AM1/22/14
to
Coding Rascal wrote on comp.lang.ada:
> 3) Does GNAT work with EGLIBC and uCLIBC?

Debian uses eglibc instead of glibc[1] and gnat-4.6 and 4.8 both work on it.
I don't know about uCLIBC.

[1] http://blog.aurel32.net/47

I don't have answers for your other questions, sorry.

--
Ludovic Brenta.

jrmarino

unread,
Jan 22, 2014, 11:55:53 AM1/22/14
to
On Wednesday, January 22, 2014 12:39:51 PM UTC+1, coding...@gmail.com wrote:
> I am interested in developing commercial Ada software for Android and iOS (both of which I have never developed for, btw). I've spent several days trying to figure out how to create my own cross compiler for the ARM processor.
>
> Since both iOS and Android have a native interface API to allow people to develop software in languages other than Objective-C and Java, I am really hoping all I need to do is the following:
>
> 1) Compile my own native version of GCC 4.8.2 with Ada enabled. Let's call this My_Native_GCC (Note: I know I can just use 4.6, but I'd like to use the latest version of GCC)

I'm the creator of gnatdroid (Ada crosscompiler from FreeBSD/DragonFly to Android). At least with gcc 4.6 and 4.7, GNAT doesn't build "out of the box" for the android target. For 4.6 I had to implement the target and some functionality, and as I found out yesterday, I have to do more for gcc4.7.

> For step 2, I downloaded the latest r9c of the Android NDK and copied over the contents of ~/android-ndk-r9c/platforms/android-17/arch-arm/usr/include into my own target root directory. Since GLIBC requires headers for Linux v2.6.19 or higher, and the NDK is bundled with Linux headers v2.6.18 (per the version.h file they include), I ended up grabbing the 3.0.31 Linux headers from Samsung's website http://opensource.samsung.com via their Jelly Bean update Zip file SGH-I747_JB_Opensource_Update1.zip. My phone is the ATT S3 model, btw.

If you want to verify the general process on how to create an ada cross compiler, just example the makefile of lang/gnatdroid-armv5 (or lang/gnatdroid/armv7) along with the helper ports lang/gnatdroid-sysutils and lang/gnatdroid-binutils on FreeBSD or DragonFly. The makefile represents a step by step process. Your outline is general correct.


> 1) Will the 6 step process I laid out above only lead me to a dead end? I know about GNATdroid. The main reason why I am trying to avoid using GNATdroid is because I am hoping I can figure out a common process that allows me to create toolchains for both Android and iOS (hopefully, with the need to simply switch between the set of header files between the two platforms).

You're at a dead-end because you think a stock gcc can build an ada compiler without patches. You have some good news though:
1) A couple of days ago I made GNATDroid use binutils 2.24 (nonfactor as 2.21 is just fine too)
2) As we speak, and totally by coincidence, I'm running a testsuite on GNATDroid based on gcc 4.7. The port will be updated today most likely. It's on C9 right now, passed every test so far, but that was after I implemented additional functionality to the gcc 4.7 base on top of my previous patchset.


> 2) Does GNAT work with the Bionic library even though it doesn't implement the entire C runtime and is not POSIX compliant. I'd like to be able to use Ada tasks and protected types on Android.

yes.


> 4) GNATdroid is built for Android 2.3. Does this mean an Ada Android app is limited to the capabilities of that old Android API? If yes, then is there any chance GNATdroid will be updated to a more recent version of Android (preferably Jelly bean)?

I guess so. It's not like anybody ever requested something newer. I don't even know how many people use it. I haven't even looked at GNATDroid in over a year, except for yesterday when I started to base it on gcc 4.7

I am skipping gcc 4.8 completely.
The next set of FreeBSD ports will be based on GCC 4.9. From what I can tell, gcc 4.8 can't build any of the 2012 or 2012 Adacore packages like polyorb or GPRBuild but GCC 4.9 should be able to. So in my opinion GCC 4.8 didn't present enough of an improvement to take on the task of patching and test it.

Saying that, if you can use FreeBSD or DragonFly, GNATDroid based on gcc 4.7 should be sufficient for you as long as the Android 2.3 API is acceptable. I don't know of any other officially packaged cross-compilers. This was the first and only that I'm aware of.

John

coding...@gmail.com

unread,
Jan 22, 2014, 4:35:00 PM1/22/14
to
Hi John,

Thanks for all the great info, and a BIG thanks for coming out with GNATDroid. =)

Yeah, I figured I was being a bit too naive on this whole cross compiling effort, especially to get Ada going.

1) How were you able to figure out that you needed to patch GCC? Was it like the build would fail and you had to dig into the GCC code and figure out what the offending code was trying to do? Or was it more like the cross compiler built successfully but the ACATS failed and you dug into the assembler to figure out why it failed? I've never patched a compiler before, nor have I ever taken a compiler course in college.

2) What did you mean when you said "I had to implement the target and some functionality"? Did you have to implement something in the GNAT run time to use an Android sub-system?

3) For the target header files, did you use the NDK header files and combined them with newer Linux headers from somewhere else like I did?

I'll take a look at the GNATDroid make files as you suggested. BTW, is there a mailing list or something that you and anyone else involved with GNATDroid
collaborate on? I think it would be interesting to find out what goes behind the scene of maintaining GNATDroid.

- Coding Rascal

On Wednesday, January 22, 2014 8:55:53 AM UTC-8, jrmarino wrote:

<snip>
>
> I'm the creator of gnatdroid (Ada crosscompiler from FreeBSD/DragonFly to Android). At least with gcc 4.6 and 4.7, GNAT doesn't build "out of the box" for the android target. For 4.6 I had to implement the target and some functionality, and as I found out yesterday, I have to do more for gcc4.7.
>
>
<snip>

jrmarino

unread,
Jan 22, 2014, 6:07:00 PM1/22/14
to
On Wednesday, January 22, 2014 10:35:00 PM UTC+1, coding...@gmail.com wrote:
> 1) How were you able to figure out that you needed to patch GCC? Was it like the build would fail and you had to dig into the GCC code and figure out what the offending code was trying to do? Or was it more like the cross compiler built successfully but the ACATS failed and you dug into the assembler to figure out why it failed? I've never patched a compiler before, nor have I ever taken a compiler course in college.

I decided to try to build an Android cross-compiler after I already had experience "porting" GNAT to FreeBSD, DragonFly, OpenBSD, and NetBSD. In theory, GNAT was already ported to FreeBSD, but it didn't work (didn't pass a big chunk of ACATS) and certainty x86-64 was a non-starter. There was no unwind implemented, so zero cost exceptions didn't work. I had to update targets and change GNAT codes on a per target basis. It took several iterations and yes, ACATS failures gives a hint what is broken. By the time I had GNAT working on *BSD, creating an Android target was a logical progression.


> 2) What did you mean when you said "I had to implement the target and some functionality"? Did you have to implement something in the GNAT run time to use an Android sub-system?

With 4.6, there was no android target at all. With 4.7, it seems like linux-eabi and some flavor of android-eabi was supported, but I don't think that extended to GNAT. So at the very minimum the android target had to be defined. But that's not all. Temp files are handled differently, threading has to be tweaked now, signals needed dedicated code, etc.



> 3) For the target header files, did you use the NDK header files and combined them with newer Linux headers from somewhere else like I did?

see lang/gnatdroid-sysroot
Should be whatever the latest android kit was at the time (2.3, API v9)
http://www.freshports.org/lang/gnatdroid-sysroot/


> I'll take a look at the GNATDroid make files as you suggested. BTW, is there a mailing list or something that you and anyone else involved with GNATDroid
> collaborate on? I think it would be interesting to find out what goes behind the scene of maintaining GNATDroid.

Not anymore. www.dragonlace.net is occasionally updated.
GNATDroid has been static. I was hoping somebody would recreate a java interface to all the standard android tools.

You'd probably be interested in Rob Veenker's work:
http://rveenker.home.xs4all.nl/Ada%20on%20Android.html


John

Dan'l Miller

unread,
Jan 23, 2014, 2:20:27 PM1/23/14
to
http://www.engadget.com/2010/04/08/apples-iphone-lockdown-apps-must-be-written-in-one-of-three-la

Presumably to thwart app development in Adobe Flash (and to thwart Android & .NET apps on iOS), the article linked above says that nonHTML/nonJavaScript app development is legally restricted by Apple to be in only the programming languages {C, Objective C, C++, Objective C++}. Does anyone know whether the iOS app developer agreement has been changed since 2010 to remove this restriction?

Micronian Coder

unread,
Jan 23, 2014, 3:19:23 PM1/23/14
to
Apple already relaxed the restrictions a few months later that same year:
http://arstechnica.com/apple/2010/09/apple-relaxes-restrictions-on-ios-app-code-iad-analytics/

Lucretia

unread,
Jan 23, 2014, 6:48:07 PM1/23/14
to
I built arm and mipsel Android GNAT using the svn/git 4.9.0 branch of GCC.I had to add in mips, but it built. Not done anything with it yet.

Luke.

Guillermo Hazebrouck

unread,
Jun 20, 2023, 9:31:47 AM6/20/23
to
El viernes, 24 de enero de 2014 a la(s) 00:48:07 UTC+1, Lucretia escribió:
> I built arm and mipsel Android GNAT using the svn/git 4.9.0 branch of GCC.I had to add in mips, but it built. Not done anything with it yet.
>
> Luke.
Do you still have this? Or could you explain how you created the toolchain?
Guillermo

Luke A. Guest

unread,
Jun 20, 2023, 1:43:59 PM6/20/23
to
Not exactly and you'd really need one of the older gcc android ndk's to
get the exact options they were using then and anything else extra they
added. Also they were 32-bit, it's all aarch now.

for android, --target=android-aarch64? or similar. You'd need to specify
the libc as bionic too and I cannot remember how to do it.

As for ios, maybe Simon can help here, I never really got around to
building it for ios, only android.

Would be worth posting it here so it's documented.

Luke A. Guest

unread,
Jun 20, 2023, 2:08:38 PM6/20/23
to

Luke A. Guest

unread,
Jun 20, 2023, 2:45:19 PM6/20/23
to
Ok, just found a cross compiler on my machine, based on GCC 11.

$ ~/opt/android-gnat/bin/x86_64-linux-android-gcc -v
Using built-in specs.
COLLECT_GCC=/home/laguest/opt/android-gnat/bin/x86_64-linux-android-gcc
COLLECT_LTO_WRAPPER=/home/laguest/opt/android-gnat/libexec/gcc/x86_64-linux-android/11.0.0/lto-wrapper
Target: x86_64-linux-android
Configured with:
/home/laguest/src/mine/free-ada/tmp/android/../gcc/configure
--target=x86_64-linux-android --prefix=/home/laguest/opt/android-gnat
--enable-languages=c,c++,ada --enable-multilib --enable-threads=posix
--disable-nls --enable-libgomp --disable-shared --disable-tls
--disable-tls --disable-libitm --disable-libstdc__-v3
--disable-sjlj-exceptions
--with-sysroot=/home/laguest/src/mine/free-ada/tmp/android/sysroot/android-x86_64
--disable-libssp --with-arch=x86-64 --with-tune=intel --with-fpmath=sse
--with-multilib-list=m32,m64 --enable-bionic-libs --disable-bootstrap
--enable-plugins --disable-libcilkrts --disable-libsanitizer
--enable-gold --enable-threads --enable-eh-frame-hdr-for-static
--enable-libatomic-ifuncs=no --enable-initfini-array
--enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc
-Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.0.0 20200816 (experimental) (GCC)

Simon Wright

unread,
Jun 20, 2023, 3:17:27 PM6/20/23
to
"Luke A. Guest" <lag...@archeia.com> writes:

> As for ios, maybe Simon can help here, I never really got around to
> building it for ios, only android.

No, sorry

Luke A. Guest

unread,
Jun 20, 2023, 3:29:24 PM6/20/23
to
:/

Luke A. Guest

unread,
Jun 20, 2023, 3:35:11 PM6/20/23
to
On 20/06/2023 20:17, Simon Wright wrote:
Might be better to use gnat-llvm for ios, maybe even android.

Luke A. Guest

unread,
Jun 20, 2023, 5:27:20 PM6/20/23
to
On 20/06/2023 14:31, Guillermo Hazebrouck wrote:
As a test, I updated my ndk and tried to compile both gcc 13 and 12,
both failed. 13 with Ghost aspects and 12 with missing headers.

They've changed the structure of the sysroot and I don't know enough
about the android ndk anymore.

Guillermo Hazebrouck

unread,
Jun 21, 2023, 3:01:13 AM6/21/23
to
Ok, thanks for that. I guess It will be more productive and future-proof to explore the LLVM option... Any clue about that? I understand a bit the logic of LLVM, but putting it into practice probably won't be ease.

Luke A. Guest

unread,
Jun 21, 2023, 5:06:09 AM6/21/23
to
AFAIK, just build the front end and then port the runtime.
0 new messages