GHC Dynamic Loading

Simon Marlow simonmar@microsoft.com
Thu, 4 Apr 2002 10:48:02 +0100


> I am trying to dynamically load a shared haskell module - and=20
> it almost
> works... however as
> soon as the grabage collector thread runs it frees/moves=20
> something and the
> program falls over.
> Presumably this means I need to use a StablePtr - however I=20
> have as yet been
> unable to work out
> what exactly is the cause. I was hoping somebody with some=20
> knowledge of th
> einternals of GHC could
> help me out...

What you're doing really isn't supported, I'm afraid.  The particular
problem I believe you're running into is that the garbage collector
doesn't know about the module you loaded so it can't distinguish
pointers to static data in that module from heap pointers.

You *can* achieve something like this using GHCi's dynamic linker (which
is available in the RTS from any program).  The interface is quite
straightforward, see ghc/rts/Linker.h.  You can load .o files of Haskell
code, or shared libraries of C code (*not* Haskell code) using this
mechanism.

Cheers,
	Simon