Re: nhc98-1.16: Segmentation fault and wrong Integer computation

Malcolm Wallace <[email protected]> Mon, 8 Dec 2003 12:00:10 +0000
Newsgroups gmane.comp.lang.haskell.nhc.bugs
Organization Dept of Computer Science, University of York
Message-ID <[email protected]>
Thorkil Naur <[email protected]> writes:

> 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