Dynamic loading problem

Simon Marlow simonmar at microsoft.com
Fri Apr 30 11:01:04 EDT 2004

On 29 April 2004 16:55, Hampus Ram wrote:

> by using the RTS I've made it possible to dynamically load modules for
> quite some time now. However, recently I've stumbled inte quite a
> problem.
> I've created a bunch of modules to handle all dynamic loading for me
> and things are good for simple programs. But now I want to load my
> dynamic loading modules dynamically (yes, it sounds weird) and that
> can't be done - not on linux anyways.
> The functions from the rts are ffi:ed into my program but when
> dynamically loading the module, these functions can't be found
> ("unknown symbol `lookupSymbol`") and neither can I load the
> HSrts.o package to make them visible due to duplicate functions
> ("I found a duplicate definition for symbol makeStableNamezh_fast").
> How can I proceed? Can I pass some flag to the linker or such to force
> them to behave as I want?

The linker (ghc/rts/Linker.c) has an explicit symbol table for symbols
in the RTS that need to be visible in dynamically loaded code.  Not
pretty, but it works and is cross-platform.

You need to add some more symbols to this table, and recompile the RTS.

Alternatively, you might be able to re-link HSrts.o with
--export-dynamic (something like 'ld -r --export-dynamic HSrts.o -o
my-HSrts.o') and then link this object into your program.  This works by
making all the symbols in HSrts.o visible to the system's dynamic
linker, which is used to resolve symbols that the RTS dynamic linker
can't find.

> I only have this problem with linux (tested on Debian and Redhat)
> using ghc 6.2.1. On Solaris everything works just great (one doesn't
> even have to load any extra packages there) with ghc 6.0.1.

Not sure why it works on Solaris.


More information about the Glasgow-haskell-users mailing list