Haskell PPL bug fix

Axel Simon A.Simon at kent.ac.uk
Fri Oct 15 05:25:14 EDT 2004


Roberto, Simon,

this is a message is about a Haskell binding to the Parma Polyhedra
Library. I had trouble with segfaults which were GC-related. Pedro
figured out what I had done wrong: the Haskell compiler GHC replaces the
memory allocator in GMP with one that allocates from the Haskell heap.
Pedro managed to link the PPL with a private version of GMP but that is
not a feasible solution in the long term. The purpose of the message:

for Simon M: conceptually it would be nicer if GHC uses it's private
version of GMP. Alternatively, GHC could just use malloc for allocating
memory and a finalizer each time an Integer goes out of scope. Would
that be too slow?

for Roberto: this is the reason why there is still no Haskell binding
for the PPL.

A big thanks to Pedro for figuring this out,
Axel.

P.S.: More comments below.

On Fri, 2004-10-15 at 10:39, Pedro Vasconcelos wrote:
> Hello again Axel,
> 
> I've done some more experiments using your PPL binding and I came across
> a bug which I think might be related to the situation you've described:
> the compiled program will crash misteriously (with a seg fault)  after
> executing fine for some time. It will happen with repeated solving of
> small problems, which led me to believe it is some form of memory
> corruption due to GC or deallocation.
> 
> I did a google search and found an related thread in the ghc users
> archive. Simon Marlow points out that the shared use of GMP by an
> externall library and GHC's runtime system is likely to run into
> trouble:
> 
> http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg06533.html

Wow, I don't remember reading that message. Good find. I am amazed why
GHC replaces the GMP allocation functions to allocate from the Haskell
heap, but since that is what happens, obviously it can only go wrong.
Thanks for tracking this down.

> None of the solutions suggested in the thread are particularly
> straightforward, but Kevin and I came up with an easier fix: what we
> require is to link PPL with it's own private GMP library and let the
> Haskell RTS use the standard shared GMP. It is sufficient to rename the
> symbols defined in GMP by adding a prefix (in linux this can be done
> using the "objcopy" util).
> 
> For each symbol XXX defined in libgmp.a, we rename it to myXXX; the
> result is libmygmp.a. Apply the same renaming to libppl.a, getting
> libmyppl.a using a private GMP library. I have only managed to do this
> for the static libraries, but that is good enough for my needs. 
> 
> After doing this I have not been able to reproduce the bug, so it looks
> like this does indeed solve the problem! 

That is quite a hack, indeed. I think the better solution is to rename
GHC's GMP library. Maybe we should suggest this to Simon.


> I'm attaching a small tcl script that builds the renaming table and
> creates new versions of the all the required libs. The original libs are
> left unchanged.

I'll try that when I'll use the PPL from Haskell again.

Thanks for tracking this down,
Axel.





More information about the FFI mailing list