Building libgmp for Android

Gabriel Risterucci gabriel.risterucci at univmed.fr
Fri Dec 17 17:09:38 CET 2010


Hello,

I'm working on some cryptographic function that use GMP, and I'm in
the process of porting them to run on Android devices. To do so, I
needed to build libgmp using the Android NDK.
So far, I've got it to build with a little change in the sourcecode,
and it run fine.
However, there is two issues, and while I hesitated about which list
would be better (discuss, devel or bug), I think I'll start here:

 - I had to change some define in longlong.h, because it assume that
some assembler instruction are available, while they are not. I'm
compiling with the target "--host=arm-eabi".
The instructions are "adds", "subs", "umull" and "smull". Since the
NDK toolchain set the ANDROID define, it is possible to just ignore
them :

*** gmp-5.0.1/longlong.h        2010-02-06 13:43:13.000000000 +0100
--- gmp-5.0.1-diff/longlong.h   2010-12-15 16:35:56.000000000 +0100
***************
*** 424,428 ****
  #endif

! #if defined (__arm__) && W_TYPE_SIZE == 32
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
    __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3"                      \
--- 424,428 ----
  #endif

! #if defined (__arm__) && W_TYPE_SIZE == 32 && ! defined(ANDROID)
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
    __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3"                      \
***************
*** 469,473 ****
               : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
      } while (0)
! #if 1 || defined (__arm_m__)  /* `M' series has widening multiply support */
  #define umul_ppmm(xh, xl, a, b) \
    __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
--- 469,473 ----
               : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
      } while (0)
! #if ! defined(ANDROID) && (1 || defined (__arm_m__))  /* `M' series
has widening multiply support */
  #define umul_ppmm(xh, xl, a, b) \
    __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))

It's just a clunky change, but at least it build using the fallback C
code. Maybe configure should check wether the compiler actually accept
those instructions, or add a new android target (like
arm-androideabi). I'm not too familiar with autoconf, but that seem
feasible, seeing that GMP already support a lot of targets.
I also tried the "Generic" target, but I get a lot of undefined
symbols; this path was abandonned since we can actually use the
arm-eabi target.
Aside from that, the whole library build, and the resulting static
library can be used without issue, at least on a small sample code,
which bring the second issue:

 - I can't run "make check". This one will most likely be redirected
to an Android development list or something, because it's related to
running current arm binaries, however if someone here have a general
idea on how to do it, since the test blobs do get built, it might be
enough to run them through qemu, but I'm not sure about that part
though.

--
Gabriel Risterucci
http://cleyfaye.net


More information about the gmp-discuss mailing list