Version française
Home     About     Download     Resources     Contact us    
Browse thread
Using primitives from dl libs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Using primitives from dl libs
> [Dynamic loading of C libraries implementing OCaml external functions]

> Yet, I am not satisfied with my solution. Putting an explicit
> filename for the library in the source file is ugly for obvious reasons.
> Also, the decision to use dl for a specific library should be made during
> the linking phase, or best, at runtime: if the bytecode interpreter
> does not own a primitive, it searchs it in a shared lib.

Yes, I agree it should work this way.

> The problem is: in which library should it search ?  I try to avoid
> the primitive database. A solution is to provide this
> information to ocamlrun via the command line (ocamlrun will
> look up each primitive in every specified shared library).

The solution I considered (but never had the fortitude to implement)
is to have an extra section in the bytecode executable listing the
shared libraries needed by the executable, i.e. all shared libraries
given to the OCaml linker with -cclib.

This section would contain short file names (e.g. libunix.so, not
/usr/local/lib/ocaml/libunix.so), and the bytecode interpreter would
search the corresponding .so files in a number of standard directories
(the directory containing the executable + the OCaml standard library
directory + the directories searched by the system dynamic loader, for
instance).

Then, the bytecode interpreter would dlopen() these libraries, and
dlsym() them all for each primitive.

I'm still not sure how to handle dynamic libraries that do not reside
in a standard directory.  We could have ocamlrun options or
environment variables (similar to LD_LIBRARY_PATH) to specify other
directories to search, but this isn't very nice.  Perhaps there should
be a file (in the stdlib directory) listing the directories to search,
a la /etc/ld.so.conf.

- Xavier Leroy