nhc98-1.16: Segmentation fault and wrong Integer computation

Hello nhc-bugs, Using nhc98-1.16 to experiment with some number-theoretic computations (c.f. H. W. Lenstra: "Factoring integers with elliptic curves", Annals of Math., 126 (1987), 649-673), I ran into a "Segmentation fault" and also examples of inconsistent Integer computations. The result of executing the same program varies with the size of the heap (the +RTS -H<size> option). I have reduced the size of the original program and attached the resulting t5.hs. Using the also attached t5.sh, the program is compiled and executed three times with varying heap size and with three different outcomes: Segmentation fault, wrong result, OK result. The OK result is verified by also running t5.hs with hugs. The output t5.out of sh t5.sh >t5.out 2>&1 is also attached. To attempt to re-create this behaviour, place t5.hs and t5.sh in a fresh directory, adjust NHC98 and HUGS in t5.sh to point to the installed nhc98 compiler and hugs interpreter, and run sh t5.sh The t5.hs program attempts to factor the square of the Mersenne prime 2^127-1, that happens in the line putStr ( "t5: " ++ show ( ec 2 ((2^127-1)^2) 50 1 ) ++ "\n" ) of t5.hs. Not a particular useful endeavor, but it suffices to illustrate the problem. The "50" in this line limits the list of primes that are used in the elliptic curve method. It may be possible to reduce this number and get a shorter computation that illustrates similar problems. I have attempted to use (2^127-1) instead of ((2^127-1)^2), but failed to illustrate the problem. The behaviour is apparently consistent, but erratic, depending on the specified heap size. In the present case, for example, a heap size of 10000 bytes gets the segmentation fault. The ghc98 that I use is compiled (currently "make basic" only) from nhc98src-1.16.tar.gz on a Redhat 8.0 Linux. I would be most grateful to receive some advice on how to proceed in this matter. Thanks a lot. Regards Thorkil

Thorkil Naur
Using nhc98-1.16 to experiment with some number-theoretic computations (c.f. H. W. Lenstra: "Factoring integers with elliptic curves", Annals of Math., 126 (1987), 649-673), I ran into a "Segmentation fault" and also examples of inconsistent Integer computations. The result of executing the same program varies with the size of the heap (the +RTS -H<size> option).
I suspect that the fault here is in nhc98's runtime system. Your program deals with some very large integers, which are represented internally as variable-length arrays of machine words. The RTS checks whether sufficient continuous memory is available to represent the result of a calculation before doing it. I think probably the check is estimating the result size wrongly. As a consequence, when the heap is small, it will be more likely that the actual result overwrites the end of the heap, causing memory corruption that could lead to either a seg fault or incorrect computation.
I would be most grateful to receive some advice on how to proceed in this matter.
Until I get the opportunity to find and fix this bug properly, the simple workaround is to ensure that your programs always use a sufficiently large heap. You can set the default heapsize at compile-time if you wish, e.g. nhc98 -o prog prog.hs -H16M or hmake -nhc98 prog +CTS -H16M -CTS Regards, Malcolm
participants (2)
-
Malcolm Wallace
-
Thorkil Naur