Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Unused .cma and .so
[ 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: [Caml-list] Unused .cma and .so
>  I used to think that linking a .cma when no module inside it is required
>  is completely hurtless. I was wrong: it seems that .so added during linking
>  of those .cma are loaded. To me, this seems a feature with a
>  counter-intuitive semantics.
>  Is there any way to disable this behaviour?

No, because it is actually necessary.

External functions declared in .mli files are expanded inline into
client code.  For instance, if we have a module A with signature

        external f : ... = "my_f"
        val g : ...

references to A.f in client code are expanded inline into C calls to "my_f",
while references to A.g leave an explicit reference to A in client code.

Now, assume that we have a.cma composed of the module A above and of
a C library dlla.so defining my_f.  If the client code never references A.g,
the linker will correctly discard the Caml code for A.  However, it
must link dlla.so so that inlined references to "my_f" are satisfied.  

If you're linking with ocamlopt or ocamlc -custom, the C linker will
be passed liba.a and will actually discard it if there are no
references to my_f.  But doing the same thing with the pure bytecode
compiler ocamlc is very hard: there is no standard API to examine
the dependencies of DLLs, and the C part of a library can reference
directly functions form the C part of another library.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners