Opened 5 years ago

Closed 5 years ago

#10003 closed bug (fixed)

integer-gmp2 tries to be GMP 4.x compatible but uses functions from GMP 5.x

Reported by: kgardas Owned by: hvr
Priority: high Milestone: 7.10.1
Component: libraries (other) Version: 7.10.1-rc1
Keywords: Cc:
Operating System: Solaris Architecture: sparc
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D675
Wiki Page:


Hello, recent HEAD is using integer-gmp2 wrapper around GMP library. This tries to be compatible with and use only functionality of GMP 4.x, but still it also uses some functions from GMP 5.x which makes this incompatible with GMP 4.x. The issue is for example shown on Solaris/SPARC platform where the OS provided library is GMP 4.3.2 and linking of stage2 binaries fails with:

Undefined                       first referenced
 symbol                             in file
__gmpn_andn_n /home/karel/src/ghc-sparc-reg_ncg-head-2015-01-17/libraries/integer-gmp2/dist-install/build/libHSinteg_21cuTlnn00eFNd4GMrxOMi.a(Type.o)
__gmpn_and_n /home/karel/src/ghc-sparc-reg_ncg-head-2015-01-17/libraries/integer-gmp2/dist-install/build/libHSinteg_21cuTlnn00eFNd4GMrxOMi.a(Type.o)
__gmpn_ior_n /home/karel/src/ghc-sparc-reg_ncg-head-2015-01-17/libraries/integer-gmp2/dist-install/build/libHSinteg_21cuTlnn00eFNd4GMrxOMi.a(Type.o)
__gmpn_xor_n /home/karel/src/ghc-sparc-reg_ncg-head-2015-01-17/libraries/integer-gmp2/dist-install/build/libHSinteg_21cuTlnn00eFNd4GMrxOMi.a(Type.o)
ld: fatal: symbol referencing errors. No output written to ghc/stage2/build/tmp/ghc-stage2

the unresolve symbols are from GMP 5.x. GMP 4.x does not provide them.

Change History (9)

comment:1 Changed 5 years ago by hvr

Milestone: 7.10.1
Owner: set to hvr

With GMP 5.0.0, the following new functions were added relative to GMP 4.x, so we need some compatibility layer to support GMP 4.x


  • New mpz function: mpz_powm_sec for side-channel quiet modexp computations.
  • New mpn functions: mpn_sqr, mpn_and_n, mpn_ior_n, mpn_xor_n, mpn_nand_n, mpn_nior_n, mpn_xnor_n, mpn_andn_n, mpn_iorn_n, mpn_com, mpn_neg, mpn_copyi, mpn_copyd, mpn_zero.
  • The function mpn_tdiv_qr now allows certain argument overlap.
  • Support for fat binaries for 64-bit x86 processors has been added.
  • A new type, mp_bitcnt_t for bignum bit counts, has been introduced.
  • Support for Windows64 through mingw64 has been added.
  • The cofactors of mpz_gcdext and mpn_gcdext are now more strictly normalised, returning to how GMP 4.2 worked. (Note that also release 4.3.2 has this change.)

comment:2 Changed 5 years ago by mietek

This also happens on 32-bit CentOS 6.5 and 32-bit Red Hat Enterprise Linux 6.5, when attempting to install the GHC 7.10.1-rc2 bindist, at configure phase:

checking for path to top of build tree... utils/ghc-pwd/dist-install/build/tmp/ghc-pwd: symbol lookup error: libraries/integer-gmp2/dist-install/build/ undefined symbol: __gmpn_andn_n

comment:3 Changed 5 years ago by hvr

Priority: normalhigh

comment:4 Changed 5 years ago by hvr

Differential Rev(s): Phab:675

comment:5 Changed 5 years ago by hvr

Differential Rev(s): Phab:675Phab:D675

comment:6 Changed 5 years ago by hvr

Status: newpatch

comment:7 Changed 5 years ago by Herbert Valerio Riedel <hvr@…>

In 5be8ed4da1963ed2d45a65fb61d761c977707cce/ghc:

Emulate GMP 5+ operations for GMP 4.x compat

The following operations are only (officially) available starting with
GMP 5.0:

- `mpn_and_n`
- `mpn_andn_n`
- `mpn_ior_n`
- `mpn_xor_n`

In order to properly support GMP 4.x, we simply emulate those operation
in terms of `mpz_*` operations available in GMP 4.x (unless GMP>=5.x
available, obviously) while incurring some overhead. Ideally, GMP 4.x
environments will reach their EOL in the foreseeable future...

This fixes #10003

Reviewed By: austin

Differential Revision:

comment:8 Changed 5 years ago by hvr

Status: patchmerge

comment:9 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Merged to ghc-7.10 (via 8827ade65eee66c42ff6aa11dff20f9b7bece3e2).

Note: See TracTickets for help on using tickets.