From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA32274 for caml-red; Tue, 26 Dec 2000 21:33:24 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA20089 for ; Tue, 26 Dec 2000 18:11:00 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eBQHAxT13893 for ; Tue, 26 Dec 2000 18:10:59 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id eBQHAxM19069 for ; Tue, 26 Dec 2000 18:10:59 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id SAA25144 for ; Tue, 26 Dec 2000 18:10:59 +0100 (MET) Date: Tue, 26 Dec 2000 18:10:59 +0100 (MET) From: Alain Frisch To: caml-list@inria.fr Subject: Using primitives from dl libs Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr Hello, 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): http://caml.inria.fr/archives/200004/msg00104.html 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 instance: 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 libraries. 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