ocaml / Zarith

The Zarith library implements arithmetic and logical operations over arbitrary-precision integers and rational numbers. The implementation, based on GMP, is very efficient.
Other
231 stars 70 forks source link

ld: illegal text-relocation ... #70

Closed dbl001 closed 3 years ago

dbl001 commented 4 years ago

Trying to build zarith on OS X 10.11.6

$ clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ ./configure
binary ocaml: found in /Users/davidlaxer/.opam/default/bin
binary ocamlc: found in /opt/local/bin
binary ocamldep: found in /opt/local/bin
binary ocamlmklib: found in /opt/local/bin
binary ocamldoc: found in /opt/local/bin
binary ar: found in /usr/bin
binary perl: found in /usr/bin
binary gcc: found in /usr/bin
binary ocamlopt: found in /opt/local/bin
checking compilation with gcc -O3 -Wall -Wextra : working
include caml/mlvalues.h: found
library dynlink.cmxa: found
binary ocamlfind: found in /Users/davidlaxer/.opam/default/bin
OCaml's word size is 64
binary uname: found in /usr/bin
checking compilation with gcc -arch x86_64 -O3 -Wall -Wextra : working
include gmp.h: found
library gmp: found
OCaml extended comparison supported
OCaml new hash functions available
OCaml supports -bin-annot to produce documentation

detected configuration:

  native-code:          yes
  dynamic linking:      yes
  asm path:             x86_64
  defines:              -DZ_OCAML_HASH -DZ_OCAML_COMPARE_EXT -DHAS_GMP -DZ_UNDERSCORE_PREFIX -DZ_MACOS 
  libraries:             -lgmp
  C options:            -arch x86_64 -O3 -Wall -Wextra 
  asm options           -arch x86_64 
  installation path:    /Users/davidlaxer/.opam/default/lib
  installation method   findlib

configuration successful!
now type "make" to build
then type "make install" or "sudo make install" to install
(ai) MacBook-Pro:zarith davidlaxer$ make
project.mak:151: depend: No such file or directory
./z_pp.pl x86_64
Name "main::extra" used only once: possible typo at ./z_pp.pl line 29.
found assembly file caml_z_x86_64.S
  found abs
  found add
  found div
  found divexact
  found logand
  found lognot
  found logor
  found logxor
  found mul
  found neg
  found pred
  found rem
  found shift_left
  found shift_right
  found sub
  found succ
ocamldep -native  z.ml q.ml big_int_Z.ml z.mli q.mli big_int_Z.mli > depend
ocamlc -I +compiler-libs -bin-annot  -c z.mli
ocamlc -I +compiler-libs -bin-annot  -c z.ml
ocamlc -I +compiler-libs -bin-annot  -c q.mli
ocamlc -I +compiler-libs -bin-annot  -c q.ml
ocamlc -I +compiler-libs -bin-annot  -c big_int_Z.mli
ocamlc -I +compiler-libs -bin-annot  -c big_int_Z.ml
ocamlmklib -failsafe -o zarith z.cmo q.cmo big_int_Z.cmo -lgmp
gcc -DZ_OCAML_HASH -DZ_OCAML_COMPARE_EXT -DHAS_GMP -DZ_UNDERSCORE_PREFIX -DZ_MACOS  -arch x86_64    -c -o caml_z_x86_64.o caml_z_x86_64.S
ocamlc -ccopt "-I/opt/local/lib/ocaml  -DZ_OCAML_HASH -DZ_OCAML_COMPARE_EXT -DHAS_GMP -DZ_UNDERSCORE_PREFIX -DZ_MACOS  -arch x86_64 -O3 -Wall -Wextra " -c caml_z.c
caml_z.c:2987:3: warning: implicit declaration of function 'mpz_2fac_ui' is
      invalid in C99 [-Wimplicit-function-declaration]
  mpz_2fac_ui(mr, ma);
  ^
caml_z.c:3002:3: warning: implicit declaration of function 'mpz_mfac_uiui' is
      invalid in C99 [-Wimplicit-function-declaration]
  mpz_mfac_uiui(mr, ma, mb);
  ^
caml_z.c:3017:3: warning: implicit declaration of function 'mpz_primorial_ui' is
      invalid in C99 [-Wimplicit-function-declaration]
  mpz_primorial_ui(mr, ma);
  ^
3 warnings generated.
ocamlmklib -failsafe -o zarith caml_z_x86_64.o caml_z.o -lgmp
ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ocamlc -I +compiler-libs -bin-annot  -c zarith_top.ml
ocamlc -o zarith_top.cma -a zarith_top.cmo
ocamlopt -I +compiler-libs  -c z.ml
ocamlopt -I +compiler-libs  -c q.ml
ocamlopt -I +compiler-libs  -c big_int_Z.ml
ocamlmklib -failsafe -o zarith z.cmx q.cmx big_int_Z.cmx -lgmp
ocamlopt -shared -o zarith.cmxs -I . zarith.cmxa -linkall
ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking
make: *** [zarith.cmxs] Error 2
(ai) MacBook-Pro:zarith davidlaxer$ 
antoinemine commented 4 years ago

Could you check your GMP version and possibly upgrade it? mpz_2fac_ui is available since GMP 5.1.0 (2012 !). I'm not sure we want to support older versions.

dbl001 commented 4 years ago
$ sudo port list gmp
Password:
gmp                            @6.2.0          devel/gmp

I just downloaded the gmp 6.2.0 tar file from https://gmplib.org/#DOWNLOAD, and built 'gmp 6.2.0' from source. Now, zarith was able to build. Curious. Issue with Mac Port gmp 6.2.0?

antoinemine commented 4 years ago

Do you mean that you already had GMP 6.2.0 installed through MacPort, and reinstalling from source solved the issue ? This is strange indeed. One possible explanation is that you already had several versions of GMP installed, and ./configure picked the wrong one (an old one); then, installing from source installed 6.2.0 in a directory searched with higher priority by ./configure (such as /usr/local). I don't know Mac and MacPort enough to know the origin of the problem and find a workaround in the configure script. As it's fixed now anyway, I will close the issue.