English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2000-12-26 (20:33)
From: Alain Frisch <frisch@c...>
Subject: Using primitives from dl libs

a few months ago, Nicolas George posted to this mailing list a patch
to allow using external (C) primitives without building a custom
runtime system (ocamlrun):

I am working on a similar solution. My approach is to add a new kind
of dynamically linked primitive declaration in the source code. For

external test : unit -> unit = "/home/frisch/caml/dl/test.so/ml_test"

ml_test is a C function defined in test.c (compiled to test.o then
converted to test.so with ld -shared).

Technically, I add a new section in the bytecode file listing the
primitives with a / in their name. The modified ocamlrun "dlopens"
the corresponding libraries at runtime. The patch (to the bytecode linker
and to ocamlrun) is really small.

Compared to Nicolas's solution, the advantage is to get rid of
the "primitive database" (a separate file indicating where to find
each primitive). Also, it is still possible to use statically linked

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.

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).

Any suggestion about this design ?

  Alain Frisch