Dynamic loading problem

Gregory Wright gwright at comcast.net
Thu Apr 29 17:04:22 EDT 2004


Hi,

I was playing with dynamically loaded modules and had the same problem.
It has nothing to do with shared objects. What you have to do is to 
force
the main program (the one that loads the loadable modules) to explicitly
link all of the object files that the set {<main program>, <loadable 
modules>}
depends on.

For example, if a module depends on symbols in 
<ghc_lib_path>/HShaskell98.o,
(but the main program doesn't), you should explicit link 
<ghc_lib_path>/HShaskell98.o
into the main program.

This happens because when you build your loadable modules the linker
assumes that they will later be linked into a main program, at which 
time
all of the undefined references will be resolved. Since you never link 
the modules
and main together, some references remain unresolved.

It shouldn't be hard to automate this; a script could run nm on the 
module
and main program, make a list of unresolved references, search the files
in <ghc_lib_path> to know which object to include, and then relink the 
main
program.

If you look at the makefiles in

http://www.algorithm.com.au/wiki/hacking/haskell.ghc_runtime_loading

you'll see some examples of how the main program has to be linked.

Best Wishes,
Greg



On Apr 29, 2004, at 3:24 PM, Hampus Ram wrote:

> On Thu, Apr 29 2004, Alastair Reid wrote:
>> Does passing the flag RTLD_GLOBAL to dlopen help?  (man dlopen for 
>> info about
>> this flag)
>
> No, since none of the objects involved are shared objects (I use 
> neither
> dlopen or addDLL but the loadObj function). They are just compiled 
> Haskell
> modules and the problem lies in the RTS symbols which for some reason 
> can't
> be loaded dynamically (why it doesn't work when the base package etc. 
> can
> be loaded is beyond me).
>
> However when loading shared objects your flag is the one to use. That
> works without flaw and is really a nicer way to load shared objects 
> than
> the RTS function addDLL.
>
> /Hampus
>
> -- 
> Homepage: http://www.dtek.chalmers.se/~d00ram
> E-mail: d00ram at dtek.chalmers.se
>
> "Det är aldrig försent att ge upp"
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>



More information about the Glasgow-haskell-users mailing list