Building gmp library for the iPhone-Update

Pierre-Henri Jondot mpkju at
Thu Jul 16 07:10:11 CEST 2009

Le 16 juil. 09 à 00:38, Michał a écrit :

> Hi,
> Are you sure that apple allows native build for iphone?
> I am not very familiar with native development for iphone. I have  
> some experience with android and stand alone build of GMP for ARM. I  
> will try to give you some hints about what I have learned. Maybe  
> that will be useful.

Well, I couldn't make much use out of it, but thanks for trying !

Indeed, Apple allows native build for iphone (one could say only  
native, except for web apps that is), but the distribution of binaries  
must go through their own channel (appstore) and the binaries must be  
codesigned and built with iPhone's official SDK, which is available  
only for osx computers running intel cpu.

(Another toolchain exists, but only for jailbroken devices, and I am  
not going that route)

The results of my progress so far :

I've managed to build gmp for the iPhone simulator, which is not a big  
achievement, as the iPhone simulator uses intel binaries so there is  
no need for cross-compiling at this point (it is not an emulator). The  
only difficulty is that the simulator is 32 bits, and my system builds  
64 bits binaries by default... Adding --build=i386-apple-darwin did  
the trick and a first test case seems to prove it's working.

Building native arm library with some assembly still fails at the same  
spot (tmp-invert_limb.s) . It could be some incompatibility (or bug)  
with the apple's provided compiler for arm or more probably some  
misstake in my configuration.

I paste a little bit more information :
tmp-invert_limb.s is mostly empty, here are the first non empty lines :
	.align	3
	.globl	___gmpn_invert_limb
	stmfd	r13!, {r4, r14}
	mov	r3, r0, lsr #23
	sub	r3, r3, #256
	add	r2, r15, #invtab-.-8 <- error there
	mov	r3, r3, lsl #1
	ldrh	r1, [r2, r3]		
	mov	r2, r1, lsl #6		

and the error message is :
tmp-invert_limb.s:56:unsupported relocation on symbol invtab
tmp-invert_limb.s:56:FATAL:Internal error: incorrect fx_r_type (17)  
for fx_subsy != 0 in fix_to_relocation_info()

 From the gmp manual, the config.m4 might be useful, so I paste its  
content here :
nl config.m4.  Generated automatically by configure.
define(<TEXT>, <.text>)
define(<DATA>, <.data>)
define(<LABEL_SUFFIX>, <:>)
define(<GLOBL>, <.globl>)
define(<GLOBL_ATTR>, <>)
define(<GSYM_PREFIX>, <_>)
define(<RODATA>, <.text>)
define(<TYPE>, <>)
define(<SIZE>, <>)
define(<LSYM_PREFIX>, <L>)
define(<W32>, <.long>)
Not sure if I should write to gmp-bugs about it, as it seems premature  
to consider I've found a bug in gmp, but if you think it would be  
useful, let me know it and I'll do it.

Trying to build a gmp library for arm without asm, I replaced arm- 
apple-darwin host with none-apple-darwin (but keeping the arm cross- 
compiler with CC flag) I could  build an arm library.

That said, I have been unable to build a simple test case, the link  
stage failing with :
Undefined symbols:
   "___gmpn_invert_limb", referenced from:
       _mpn_mod_1_unnorm in libgmp.a(mod_1.o)
       _mpn_mod_1_norm in libgmp.a(mod_1.o)

I made sure to use : <<make distclean>>, or even in that last case  
redo the building starting from fresh sources, to no avail.


Pierre-Henri Jondot

More information about the gmp-discuss mailing list