Hi Marc,
I ran 'make check' on gmp-6.2.1 and it reported problems (see the attached file). I can't remember if I ran it before my original email but 'make install' seemed to have worked so if I did I think I must have ignored it. As you suggested I downloaded gmp-6.2.99-20221117121717 ran './configure', 'make', 'make check' (see attached file) and 'make install' and now pt3 runs to completion printing 'hmmm, it hasn't failed' After I sent the first email I did a bit of digging around the source code and isolated the error to a call of mpz_powm() in millerrabin() Prior to calling mpz_powm() I printed the parameters to millerrabin() which are passed to mpz_powm(). With these values millerrabin( n=20000000000000000011, x=7804482689133377995, y=1, q=10000000000000000005, k=1) mpz_powm() crashed. This seems to have been resolved in 6.2.99 Thank you very much for your help sorting this out. TTFN Philip Riebold On Fri, Jun 9, 2023 at 5:18 AM Marc Glisse <marc.gli...@inria.fr> wrote: > Hello, > > could you try with a recent snapshot from > https://gmplib.org/download/snapshot/ ? > > If you built GMP yourself, did you run `make check` afterwards? > > > On Thu, 8 Jun 2023, Philip Riebold wrote: > > > Hi, > > > > > > I think I may have come across an error in mpz_probab_prime_p() It seems > to > > > > occasionally cause a segmentation fault either when repeatedly run with > the > > > > same arguments or with increasing values of the first argument. > > > > > > I initially came across the bug when I was trying to find the closest > primes > > > >> 10^n, 2*10^n or 5*10^n when the program would crash after listing the > > first > > > > few dozen/hundred results. > > > > > > The platform is a 16GB M2 Mac Air. > > > > > > The test program below, pt3.c is the simplest I could produce to > demonstrate > > > > the problem. > > > > > > The first argument 20000000000000000011 is the smallest value I found > which > > > > caused the error. > > > > > > When I ran pt3 100 times the for() loop executed between 4 and 4684 times > > > > before crashing. > > > > > > GMP version 6.2.1 > > > > ===================== > > > > Philip:gmp_error philip$ cat pt3.c > > > > #include <stdio.h> > > > > #include <string.h> > > > > #include <gmp.h> > > > > > > int main(void) > > > > { > > > > setbuf(stdout,NULL); > > > > mpz_t test; > > > > > > for(int n = 1; n <= 1000; n++) { > > > > printf("%4d\n", n); > > > > mpz_init(test); > > > > mpz_set_str(test, "20000000000000000011", 10); > > > > int res = mpz_probab_prime_p(test, 100); > > > > mpz_clear(test); > > > > if(res != 1) > > > > printf("res = %d\n", res); > > > > } > > > > printf("hmmm, it hasn't failed\n"); > > > > } > > > > Philip:gmp_error philip$ > > > > ===================== > > > > Philip:gmp_error philip$ cc -v > > > > Apple clang version 14.0.3 (clang-1403.0.22.14.1) > > > > Target: arm64-apple-darwin22.5.0 > > > > Thread model: posix > > > > InstalledDir: > > > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin > > > > Philip:gmp_error philip$ > > > > ===================== > > > > Philip:gmp_error philip$ uname -a > > > > Darwin Philip 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:43 > PDT > > 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8112 arm64 > > > > Philip:gmp_error philip$ > > > > ===================== > > > > Philip:gmp-6.2.1 philip$ ./config.guess > > > > aarch64-apple-darwin22.5.0 > > > > Philip:gmp-6.2.1 philip$ > > > > ===================== > > > > Philip:gmp-6.2.1 philip$ ./configfsf.guess > > > > aarch64-apple-darwin22.5.0 > > > > Philip:gmp-6.2.1 philip$ > > > > ===================== > > > > Philip:gmp_error philip$ cc -o pt3 pt3.c -lgmp > > > > Philip:gmp_error philip$ ./pt3 > > > > 1 > > > > 2 > > > > 3 > > > > 4 > > > > ⋮ > > > > 143 > > > > 144 > > > > 145 > > > > 146 > > > > Segmentation fault: 11 > > > > Philip:gmp_error philip$ > > > > ===================== > > > > > > If there's anything I can do to help please ask. > > > > > > TTFN > > > > Philip Riebold > > > > -- > Marc Glisse >
Philip:gmp-6.2.1 philip$ make check /Applications/Xcode.app/Contents/Developer/usr/bin/make check-recursive Making check in tests Making check in . /Applications/Xcode.app/Contents/Developer/usr/bin/make libtests.la t-bswap t-constants t-count_zeros t-hightomask t-modlinv t-popc t-parity t-sub make[4]: `libtests.la' is up to date. /bin/sh ../libtool --tag=CC --mode=link gcc -O2 -pedantic -march=armv8-a -no-install -o t-bswap t-bswap.o libtests.la ../libgmp.la libtool: warning: '-no-install' is ignored for aarch64-apple-darwin22.5.0 libtool: warning: assuming '-no-fast-install' instead rm: .libs/t-bswap: Permission denied libtool: link: gcc -O2 -pedantic -march=armv8-a -o .libs/t-bswap t-bswap.o ./.libs/libtests.a /Users/philip/euler/gmp/gmp-6.2.1/.libs/libgmp.dylib ../.libs/libgmp.dylib ld: can't write output file: .libs/t-bswap for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [t-bswap] Error 1 make[3]: *** [check-am] Error 2 make[2]: *** [check-recursive] Error 1 make[1]: *** [check-recursive] Error 1 make: *** [check] Error 2 Philip:gmp-6.2.1 philip$
Philip:gmp-6.2.99-20221117121717 philip$ make check /Applications/Xcode.app/Contents/Developer/usr/bin/make check-recursive Making check in tests Making check in . /Applications/Xcode.app/Contents/Developer/usr/bin/make libtests.la t-bswap t-constants t-count_zeros t-hightomask t-modlinv t-popc t-parity t-sub make[4]: `libtests.la' is up to date. make[4]: `t-bswap' is up to date. make[4]: `t-constants' is up to date. make[4]: `t-count_zeros' is up to date. make[4]: `t-hightomask' is up to date. make[4]: `t-modlinv' is up to date. make[4]: `t-popc' is up to date. make[4]: `t-parity' is up to date. make[4]: `t-sub' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-bswap PASS: t-constants PASS: t-count_zeros PASS: t-hightomask PASS: t-modlinv PASS: t-popc PASS: t-parity PASS: t-sub ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 8 # PASS: 8 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in devel make[3]: Nothing to be done for `check'. Making check in mpn /Applications/Xcode.app/Contents/Developer/usr/bin/make t-asmtype t-aors_1 t-divrem_1 t-mod_1 t-fat t-get_d t-instrument t-iord_u t-mp_bases t-perfsqr t-scan logic t-toom22 t-toom32 t-toom33 t-toom42 t-toom43 t-toom44 t-toom52 t-toom53 t-toom54 t-toom62 t-toom63 t-toom6h t-toom8h t-toom2-sqr t-toom3-sqr t-toom4-sqr t-toom6-sqr t-toom8-sqr t-div t-mul t-mullo t-sqrlo t-mulmod_bnm1 t-sqrmod_bnm1 t-mulmid t-mulmod_bknp1 t-sqrmod_bknp1 t-addaddmul t-hgcd t-hgcd_appr t-matrix22 t-invert t-bdiv t-fib2m t-broot t-brootinv t-minvert t-sizeinbase t-gcd_11 t-gcd_22 t-gcdext_1 make[4]: `t-asmtype' is up to date. make[4]: `t-aors_1' is up to date. make[4]: `t-divrem_1' is up to date. make[4]: `t-mod_1' is up to date. make[4]: `t-fat' is up to date. make[4]: `t-get_d' is up to date. make[4]: `t-instrument' is up to date. make[4]: `t-iord_u' is up to date. make[4]: `t-mp_bases' is up to date. make[4]: `t-perfsqr' is up to date. make[4]: `t-scan' is up to date. make[4]: `logic' is up to date. make[4]: `t-toom22' is up to date. make[4]: `t-toom32' is up to date. make[4]: `t-toom33' is up to date. make[4]: `t-toom42' is up to date. make[4]: `t-toom43' is up to date. make[4]: `t-toom44' is up to date. make[4]: `t-toom52' is up to date. make[4]: `t-toom53' is up to date. make[4]: `t-toom54' is up to date. make[4]: `t-toom62' is up to date. make[4]: `t-toom63' is up to date. make[4]: `t-toom6h' is up to date. make[4]: `t-toom8h' is up to date. make[4]: `t-toom2-sqr' is up to date. make[4]: `t-toom3-sqr' is up to date. make[4]: `t-toom4-sqr' is up to date. make[4]: `t-toom6-sqr' is up to date. make[4]: `t-toom8-sqr' is up to date. make[4]: `t-div' is up to date. make[4]: `t-mul' is up to date. make[4]: `t-mullo' is up to date. make[4]: `t-sqrlo' is up to date. make[4]: `t-mulmod_bnm1' is up to date. make[4]: `t-sqrmod_bnm1' is up to date. make[4]: `t-mulmid' is up to date. make[4]: `t-mulmod_bknp1' is up to date. make[4]: `t-sqrmod_bknp1' is up to date. make[4]: `t-addaddmul' is up to date. make[4]: `t-hgcd' is up to date. make[4]: `t-hgcd_appr' is up to date. make[4]: `t-matrix22' is up to date. make[4]: `t-invert' is up to date. make[4]: `t-bdiv' is up to date. make[4]: `t-fib2m' is up to date. make[4]: `t-broot' is up to date. make[4]: `t-brootinv' is up to date. make[4]: `t-minvert' is up to date. make[4]: `t-sizeinbase' is up to date. make[4]: `t-gcd_11' is up to date. make[4]: `t-gcd_22' is up to date. make[4]: `t-gcdext_1' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-asmtype PASS: t-aors_1 PASS: t-divrem_1 PASS: t-mod_1 PASS: t-fat PASS: t-get_d PASS: t-instrument PASS: t-iord_u PASS: t-mp_bases PASS: t-perfsqr PASS: t-scan PASS: logic PASS: t-toom22 PASS: t-toom32 PASS: t-toom33 PASS: t-toom42 PASS: t-toom43 PASS: t-toom44 PASS: t-toom52 PASS: t-toom53 PASS: t-toom54 PASS: t-toom62 PASS: t-toom63 PASS: t-toom6h PASS: t-toom8h PASS: t-toom2-sqr PASS: t-toom3-sqr PASS: t-toom4-sqr PASS: t-toom6-sqr PASS: t-toom8-sqr PASS: t-div PASS: t-mul PASS: t-mullo PASS: t-sqrlo PASS: t-mulmod_bnm1 PASS: t-sqrmod_bnm1 PASS: t-mulmid PASS: t-mulmod_bknp1 PASS: t-sqrmod_bknp1 PASS: t-addaddmul PASS: t-hgcd PASS: t-hgcd_appr PASS: t-matrix22 PASS: t-invert PASS: t-bdiv PASS: t-fib2m PASS: t-broot PASS: t-brootinv PASS: t-minvert PASS: t-sizeinbase PASS: t-gcd_11 PASS: t-gcd_22 PASS: t-gcdext_1 ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 53 # PASS: 53 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in mpz /Applications/Xcode.app/Contents/Developer/usr/bin/make reuse t-addsub t-cmp t-mul t-mul_i t-tdiv t-tdiv_ui t-fdiv t-fdiv_ui t-cdiv_ui t-gcd t-gcd_ui t-lcm t-invert dive dive_ui t-sqrtrem convert io t-inp_str logic t-bit t-powm t-powm_ui t-pow t-div_2exp t-root t-perfsqr t-perfpow t-jac t-bin t-get_d t-get_d_2exp t-get_si t-set_d t-set_si t-lucm t-fac_ui t-mfac_uiui t-primorial_ui t-fib_ui t-lucnum_ui t-scan t-fits t-divis t-divis_2exp t-cong t-cong_2exp t-sizeinbase t-set_str t-aorsmul t-cmp_d t-cmp_si t-hamdist t-oddeven t-popcount t-set_f t-io_raw t-import t-export t-pprime_p t-nextprime t-remove t-limbs make[4]: `reuse' is up to date. make[4]: `t-addsub' is up to date. make[4]: `t-cmp' is up to date. make[4]: `t-mul' is up to date. make[4]: `t-mul_i' is up to date. make[4]: `t-tdiv' is up to date. make[4]: `t-tdiv_ui' is up to date. make[4]: `t-fdiv' is up to date. make[4]: `t-fdiv_ui' is up to date. make[4]: `t-cdiv_ui' is up to date. make[4]: `t-gcd' is up to date. make[4]: `t-gcd_ui' is up to date. make[4]: `t-lcm' is up to date. make[4]: `t-invert' is up to date. make[4]: `dive' is up to date. make[4]: `dive_ui' is up to date. make[4]: `t-sqrtrem' is up to date. make[4]: `convert' is up to date. make[4]: `io' is up to date. make[4]: `t-inp_str' is up to date. make[4]: `logic' is up to date. make[4]: `t-bit' is up to date. make[4]: `t-powm' is up to date. make[4]: `t-powm_ui' is up to date. make[4]: `t-pow' is up to date. make[4]: `t-div_2exp' is up to date. make[4]: `t-root' is up to date. make[4]: `t-perfsqr' is up to date. make[4]: `t-perfpow' is up to date. make[4]: `t-jac' is up to date. make[4]: `t-bin' is up to date. make[4]: `t-get_d' is up to date. make[4]: `t-get_d_2exp' is up to date. make[4]: `t-get_si' is up to date. make[4]: `t-set_d' is up to date. make[4]: `t-set_si' is up to date. make[4]: `t-lucm' is up to date. make[4]: `t-fac_ui' is up to date. make[4]: `t-mfac_uiui' is up to date. make[4]: `t-primorial_ui' is up to date. make[4]: `t-fib_ui' is up to date. make[4]: `t-lucnum_ui' is up to date. make[4]: `t-scan' is up to date. make[4]: `t-fits' is up to date. make[4]: `t-divis' is up to date. make[4]: `t-divis_2exp' is up to date. make[4]: `t-cong' is up to date. make[4]: `t-cong_2exp' is up to date. make[4]: `t-sizeinbase' is up to date. make[4]: `t-set_str' is up to date. make[4]: `t-aorsmul' is up to date. make[4]: `t-cmp_d' is up to date. make[4]: `t-cmp_si' is up to date. make[4]: `t-hamdist' is up to date. make[4]: `t-oddeven' is up to date. make[4]: `t-popcount' is up to date. make[4]: `t-set_f' is up to date. make[4]: `t-io_raw' is up to date. make[4]: `t-import' is up to date. make[4]: `t-export' is up to date. make[4]: `t-pprime_p' is up to date. make[4]: `t-nextprime' is up to date. make[4]: `t-remove' is up to date. make[4]: `t-limbs' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: reuse PASS: t-addsub PASS: t-cmp PASS: t-mul PASS: t-mul_i PASS: t-tdiv PASS: t-tdiv_ui PASS: t-fdiv PASS: t-fdiv_ui PASS: t-cdiv_ui PASS: t-gcd PASS: t-gcd_ui PASS: t-lcm PASS: t-invert PASS: dive PASS: dive_ui PASS: t-sqrtrem PASS: convert PASS: io PASS: t-inp_str PASS: logic PASS: t-bit PASS: t-powm PASS: t-powm_ui PASS: t-pow PASS: t-div_2exp PASS: t-root PASS: t-perfsqr PASS: t-perfpow PASS: t-jac PASS: t-bin PASS: t-get_d PASS: t-get_d_2exp PASS: t-get_si PASS: t-set_d PASS: t-set_si PASS: t-lucm PASS: t-fac_ui PASS: t-mfac_uiui PASS: t-primorial_ui PASS: t-fib_ui PASS: t-lucnum_ui PASS: t-scan PASS: t-fits PASS: t-divis PASS: t-divis_2exp PASS: t-cong PASS: t-cong_2exp PASS: t-sizeinbase PASS: t-set_str PASS: t-aorsmul PASS: t-cmp_d PASS: t-cmp_si PASS: t-hamdist PASS: t-oddeven PASS: t-popcount PASS: t-set_f PASS: t-io_raw PASS: t-import PASS: t-export PASS: t-pprime_p PASS: t-nextprime PASS: t-remove PASS: t-limbs ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 64 # PASS: 64 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in mpq /Applications/Xcode.app/Contents/Developer/usr/bin/make t-aors t-cmp t-cmp_ui t-cmp_si t-equal t-get_d t-get_str t-inp_str t-inv t-md_2exp t-set_f t-set_str io reuse t-cmp_z make[4]: `t-aors' is up to date. make[4]: `t-cmp' is up to date. make[4]: `t-cmp_ui' is up to date. make[4]: `t-cmp_si' is up to date. make[4]: `t-equal' is up to date. make[4]: `t-get_d' is up to date. make[4]: `t-get_str' is up to date. make[4]: `t-inp_str' is up to date. make[4]: `t-inv' is up to date. make[4]: `t-md_2exp' is up to date. make[4]: `t-set_f' is up to date. make[4]: `t-set_str' is up to date. make[4]: `io' is up to date. make[4]: `reuse' is up to date. make[4]: `t-cmp_z' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-aors PASS: t-cmp PASS: t-cmp_ui PASS: t-cmp_si PASS: t-equal PASS: t-get_d PASS: t-get_str PASS: t-inp_str PASS: t-inv PASS: t-md_2exp PASS: t-set_f PASS: t-set_str PASS: io PASS: reuse PASS: t-cmp_z ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 15 # PASS: 15 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in mpf /Applications/Xcode.app/Contents/Developer/usr/bin/make t-dm2exp t-conv t-add t-sub t-sqrt t-sqrt_ui t-muldiv reuse t-cmp_d t-cmp_si t-div t-fits t-get_d t-get_d_2exp t-get_si t-get_ui t-gsprec t-inp_str t-int_p t-mul_ui t-set t-set_q t-set_si t-set_ui t-trunc t-ui_div t-eq t-pow_ui make[4]: `t-dm2exp' is up to date. make[4]: `t-conv' is up to date. make[4]: `t-add' is up to date. make[4]: `t-sub' is up to date. make[4]: `t-sqrt' is up to date. make[4]: `t-sqrt_ui' is up to date. make[4]: `t-muldiv' is up to date. make[4]: `reuse' is up to date. make[4]: `t-cmp_d' is up to date. make[4]: `t-cmp_si' is up to date. make[4]: `t-div' is up to date. make[4]: `t-fits' is up to date. make[4]: `t-get_d' is up to date. make[4]: `t-get_d_2exp' is up to date. make[4]: `t-get_si' is up to date. make[4]: `t-get_ui' is up to date. make[4]: `t-gsprec' is up to date. make[4]: `t-inp_str' is up to date. make[4]: `t-int_p' is up to date. make[4]: `t-mul_ui' is up to date. make[4]: `t-set' is up to date. make[4]: `t-set_q' is up to date. make[4]: `t-set_si' is up to date. make[4]: `t-set_ui' is up to date. make[4]: `t-trunc' is up to date. make[4]: `t-ui_div' is up to date. make[4]: `t-eq' is up to date. make[4]: `t-pow_ui' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-dm2exp PASS: t-conv PASS: t-add PASS: t-sub PASS: t-sqrt PASS: t-sqrt_ui PASS: t-muldiv PASS: reuse PASS: t-cmp_d PASS: t-cmp_si PASS: t-div PASS: t-fits PASS: t-get_d PASS: t-get_d_2exp PASS: t-get_si PASS: t-get_ui PASS: t-gsprec PASS: t-inp_str PASS: t-int_p PASS: t-mul_ui PASS: t-set PASS: t-set_q PASS: t-set_si PASS: t-set_ui PASS: t-trunc PASS: t-ui_div PASS: t-eq PASS: t-pow_ui ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 28 # PASS: 28 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in rand /Applications/Xcode.app/Contents/Developer/usr/bin/make t-iset t-lc2exp t-mt t-rand t-urbui t-urmui t-urndmm make[4]: `t-iset' is up to date. make[4]: `t-lc2exp' is up to date. make[4]: `t-mt' is up to date. make[4]: `t-rand' is up to date. make[4]: `t-urbui' is up to date. make[4]: `t-urmui' is up to date. make[4]: `t-urndmm' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-iset PASS: t-lc2exp PASS: t-mt PASS: t-rand PASS: t-urbui PASS: t-urmui PASS: t-urndmm ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 7 # PASS: 7 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in misc /Applications/Xcode.app/Contents/Developer/usr/bin/make t-printf t-scanf t-locale make[4]: `t-printf' is up to date. make[4]: `t-scanf' is up to date. make[4]: `t-locale' is up to date. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS PASS: t-printf PASS: t-scanf PASS: t-locale ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 3 # PASS: 3 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in cxx /Applications/Xcode.app/Contents/Developer/usr/bin/make make[4]: Nothing to be done for `all'. /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS ============================================================================ Testsuite summary for GNU MP 6.2.99 ============================================================================ # TOTAL: 0 # PASS: 0 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ Making check in mpn make[2]: Nothing to be done for `check'. Making check in mpz make[2]: Nothing to be done for `check'. Making check in mpq make[2]: Nothing to be done for `check'. Making check in mpf make[2]: Nothing to be done for `check'. Making check in printf make[2]: Nothing to be done for `check'. Making check in scanf make[2]: Nothing to be done for `check'. Making check in rand make[2]: Nothing to be done for `check'. Making check in cxx make[2]: Nothing to be done for `check'. Making check in demos Making check in calc /Applications/Xcode.app/Contents/Developer/usr/bin/make check-am make[4]: Nothing to be done for `check-am'. Making check in expr make[3]: Nothing to be done for `check'. make[3]: Nothing to be done for `check-am'. Making check in tune make[2]: Nothing to be done for `check'. Making check in doc make[2]: Nothing to be done for `check'. make[2]: Nothing to be done for `check-am'. Philip:gmp-6.2.99-20221117121717 philip$
_______________________________________________ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs