porting gmp to pnacl

Kovács Zoltán zoltan at geogebra.org
Fri Dec 20 14:58:41 UTC 2013


Dear Developers,

I am trying to port gmp properly to the PNaCl platform. There is already
some work done in the web-shootout
<https://code.google.com/p/web-shootout>project, it seems gmp can be
ported without less pain, but I have three
problems. I uploaded my planned changes for the naclports project to
http://ggb1.idm.jku.at/~kovzol/data/naclports/src/ports/gmp/ so you can
check my steps if interested.

1. Both web-shootout's libgmp.a and my self-compiled one report this
strange error when using gmp as an included library:

  ...
  CC   pnacl/Release/isprime_pnacl.o
  LINK pnacl/Release/isprime_unstripped.bc
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
error:
/home/kovzol/tmp/nacl_sdk/pepper_31/lib/pnacl/Release/libgmp.a(lt36-out_str.o):
symbol '_impure_ptr' used as both __thread and non-__thread
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
./pnacl/Release/isprime_pnacl.o: previous definition here
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
error:
/home/kovzol/tmp/nacl_sdk/pepper_31/lib/pnacl/Release/libgmp.a(assert.o):
symbol '_impure_ptr' used as both __thread and non-__thread
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
./pnacl/Release/isprime_pnacl.o: previous definition here
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
error:
/home/kovzol/tmp/nacl_sdk/pepper_31/lib/pnacl/Release/libgmp.a(memory.o):
symbol '_impure_ptr' used as both __thread and non-__thread
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
./pnacl/Release/isprime_pnacl.o: previous definition here
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
error:
/home/kovzol/tmp/nacl_sdk/pepper_31/lib/pnacl/Release/libgmp.a(realloc.o):
symbol '_impure_ptr' used as both __thread and non-__thread
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/le32-nacl-ld.gold:
./pnacl/Release/isprime_pnacl.o: previous definition here
  FINALIZE pnacl/Release/isprime_unstripped.pexe
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_pnacl/host_x86_32/bin/opt:
pnacl/Release/isprime_unstripped.bc:1:1: error: expected top-level entity
ELF<some binary characters>

This error may be caused by using the wrong platform version of libgmp.a,
since I simply copied one version of it to the best fitting directory. But
for any help I could be grateful since the toolchain does not complain
about binary incompatibility.

2. When running the build.sh script, gmp seems to be compiled, and running
"make check" automatically passes many (validity) tests, but it stops
finally with

...
Valid.
PASS: t-urndmm.nexe
==================
All 7 tests passed
==================
make[4]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/rand'
make[3]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/rand'
Making check in misc
make[3]: Entering directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/misc'
make  t-printf.nexe t-scanf.nexe t-locale.nexe
make[4]: Entering directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/misc'
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99 -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../tests    -O2
-pedantic -c t-printf.c
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99 -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../tests    -O2
-pedantic -c t-scanf.c
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99 -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../tests    -O2
-pedantic -c t-locale.c
/bin/bash ../../libtool --tag=CC   --mode=link
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99  -O2 -pedantic   -o t-locale.nexe t-locale.o ../../tests/
libtests.la ../../libgmp.la
libtool: link:
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99 -O2 -pedantic -o t-locale.nexe t-locale.o
 ../../tests/.libs/libtests.a
/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/.libs/libgmp.a
../../.libs/libgmp.a
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-locale.o):
In function `localeconv':
locale.c:(.text+0xa0): multiple definition of `localeconv'
t-locale.o:t-locale.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make[4]: *** [t-locale.nexe] Error 1
make[4]: *** Waiting for unfinished jobs....
make[4]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/misc'
make[3]: *** [check-am] Error 2
make[3]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests/misc'
make[2]: *** [check-recursive] Error 1
make[2]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/tests'
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory
`/home/kovzol/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3'
make: *** [check] Error 2

On another platform (Linux, x86_64) everything is fine. I guess here "make
check" would not make really sense since I just use the validator for
executing the .nexe "executables".

3. When I try to compile a simple demo manually, this is what I get:

kovzol at kovzol:~/tmp/nacl_sdk/naclports/src/out/repository/gmp-5.1.3/demos$
make isprime
/home/kovzol/tmp/nacl_sdk/pepper_31/toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc
-std=gnu99 -O2 -pedantic    isprime.c   -o isprime
/tmp/ccBeMP1x.o: In function `main':
isprime.c:(.text+0x11c): undefined reference to `__gmpz_init'
isprime.c:(.text+0x17c): undefined reference to `__gmpz_probab_prime_p'
isprime.c:(.text+0x1bc): undefined reference to `__gmpz_out_str'
isprime.c:(.text+0x23c): undefined reference to `__gmpz_set_str'
isprime.c:(.text+0x37c): undefined reference to `__gmpz_set_str'
isprime.c:(.text+0x3bc): undefined reference to `__gmpz_probab_prime_p'
isprime.c:(.text+0x41c): undefined reference to `__gmpz_init'
collect2: ld returned 1 exit status
make: *** [isprime] Error 1

On another platform (Linux, x86_64) everything is fine:

kovzol at kovzol:~/tmp/gmp-5.1.3/demos$ make isprime
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I..    -O2 -pedantic
-fomit-frame-pointer -m64 -mtune=corei7 -march=corei7 -c isprime.c
/bin/bash ../libtool --tag=CC   --mode=link gcc -std=gnu99  -O2 -pedantic
-fomit-frame-pointer -m64 -mtune=corei7 -march=corei7   -o isprime
isprime.o ../libgmp.la
libtool: link: gcc -std=gnu99 -O2 -pedantic -fomit-frame-pointer -m64
-mtune=corei7 -march=corei7 -o .libs/isprime isprime.o  ../.libs/libgmp.so

Thank you very much for your hints in advance,
best regards and happy holidays,
Zoltan

-- 
Zoltán Kovács
GeoGebra | Software Developer
www.geogebra.org


More information about the gmp-devel mailing list