The Parma Polyhedra Library (PPL) is a modern and complete C++ library providing numerical abstractions useful in program analysis including (but not limited to) convex polyhedra. The latest PPL version 0.9.1 includes bindings for several languages: C++, C, several Prolog systems, Java and O'Caml.
Axel Simon wrote PPL library bindings for the Glasgow Haskell Compiler (GHC) which he was kind enough to pass on to me. These are not yet part of the standard PPL distribution because of a conflict: both the PPL and the GHC runtime system use the GNU multiple precision library (GMP) for big-num arithmetic. Unfortunately, the GHC runtime modifies the GMP memory allocator to use its own custom one. When a foreign library (in this case the PPL) uses the shared GMP library we get segmentation faults sometime during execution. My guess was that GHCs garbage collector and the FFI finalizers were somehow interacting badly.
To prove this theory I tried a quick and dirty work-around: I modified the PPL to use its own private version of the GMP, so that the final GHC+PPL binary uses two copies of the GMP. This worked and proved my theory, thought it won't win prizes for elegance.
I realize it would be better to do the trick the other around, namely, make GHC use a private version of the GMP; after all, there is no point in using a shared library if other foreign code cannot use it! However, I had compiled the PPL from source already but had not done so with GHC, so I was lazy and chose the easiest path.By the way, I contacted Simon Marlow of the GHC development team who acknowledged the problem and said that the clean solution will come only when GMP in the Haskell compiler is replaced by a custom library, but this is not to be done in the near future. In the mean time, my hack allows circumventing the problem.
My work around solution was tested on a GNU/Linux system and uses
objcopy utility to rename symbols in PPL
and GMP libraries.
This tclsh script automates this
process. It produces new libraries
the original are not modified.
For some reason, this technique worked only for the static
Although nothing is modified or deleted (other than temporary files),
make sure you read the code before executing to check for paths, etc.
tclsh librename.tclfrom the
ppl-0.9directory; this should generate the following files:
make; this constructs a demo Haskell program that uses the PPL.