Making sure <gmp.h> and libgmp.* do match
I have been bitten by the following problem on a bi-arch system. By accident, I was compiling with the 32-bit version of <gmp.h> and linking with the 64-bit version of libgmp.*. The failure I got was not trivial at all (only one test out of thousands was failing), and debugging took a long time. Do you know a defense against this kind of errors? More specifically: - for version mismatches, the obvious thing to do is to compare the result of gmp_version() with the macros __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL; - I am wondering if something similar can be done for ABI mismatches: for example <gmp.h> defines __GMP_BITS_PER_MP_LIMB: does libgmp.* "leak" this information so that a comparison can be made? Thanks, Roberto -- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it
Roberto Bagnara <bagnara@cs.unipr.it> writes: I have been bitten by the following problem on a bi-arch system. By accident, I was compiling with the 32-bit version of <gmp.h> and linking with the 64-bit version of libgmp.*. The failure I got was not trivial at all (only one test out of thousands was failing), and debugging took a long time. Do you know a defense against this kind of errors? More specifically: - for version mismatches, the obvious thing to do is to compare the result of gmp_version() with the macros __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL; - I am wondering if something similar can be done for ABI mismatches: for example <gmp.h> defines __GMP_BITS_PER_MP_LIMB: does libgmp.* "leak" this information so that a comparison can be made? There is a documented variable mp_bits_per_limb. -- Torbjörn
FYI, I've done the follwing for years: assert(sizeof(mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS); assert(mp_bits_per_limb == GMP_LIMB_BITS); -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
Vincent Lefevre wrote:
FYI, I've done the follwing for years:
assert(sizeof(mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS); assert(mp_bits_per_limb == GMP_LIMB_BITS);
Torbjorn, Vincent, thank you very much indeed. This is precisely what I was looking for. Cheers, Roberto -- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it
participants (3)
-
Roberto Bagnara -
Torbjorn Granlund -
Vincent Lefevre