Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: oleg@okmij.org
Cc: alain@frisch.fr, Xavier.Leroy@inria.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Accelerating compilation
Date: Tue, 10 Sep 2013 12:21:42 +0200	[thread overview]
Message-ID: <1378808502.10274.136.camel@zotac> (raw)
In-Reply-To: <20130910020157.41613.qmail@www1.g3.pair.com>

[-- Attachment #1: Type: text/plain, Size: 4249 bytes --]

Good point. However, I think without RTLD_NOW there is not enough
protection against errors. The better solution would be if ocamlc.opt
spawned a child process that is a real byterun executable, and that does
the loading check for it. For simplicity, this executable should be the
just created executable, and an environment variable requests to do the
load check only (no real execution beyond that). NB. The "ldd" utility
on Linux uses exactly the same trick.

Gerd

Am Dienstag, den 10.09.2013, 02:01 +0000 schrieb oleg@okmij.org:
> > Or are there compelling arguments in favor of using the bytecode version 
> > of ocamlc/ocamlopt?
> 
> I have come across one case of the meaningful difference between
> ocamlc and ocamlc.opt: a particular project can only be linked on
> MacOS using ocamlc; ocamlc.opt fails to link. Admittedly, the real
> problem is in what I think a hard-to-justify design decision in
> OCaml linker.
> 
> The problem occurs when linking byte-compiled executables that use the
> delimcc library. I will only talk about byte-compiled version of
> delimcc in the message (there are no problems for the native version).
> 
> The following message
>         https://sympa.inria.fr/sympa/arc/caml-list/2013-04/msg00072.html
> gives more detail.
> 
> Similar to the nums library, delimcc includes some C code, which is
> arranged in a shared library libdelimcc.so. That shared library refers
> to a particular symbol caml_realloc_stack, which is provided by the
> byte-code run-time system (that is, ocamlrun). When we invoke the
> byte-code executable that uses delimcc, ocamlrun loads libdelimcc.so,
> the library looks for the symbol caml_realloc_stack. Since ocamlrun is
> the running executable and its provides the symbol, the resolution
> succeeds and everyone is happy.
> 
> The problem occurs when linking the executable that uses delimcc. When
> OCaml linker processes delimcc.cma, it notices that a shared library
> is required. The OCaml linker then loads the library *and forces the
> resolution of all undefined references there*. Therefore, the symbol
> caml_realloc_stack required by libdelimcc.so has to be found. When the
> linking is done by ocamlc, then the running executable is ocamlrun,
> which provides the symbol. However, if the linking is done by
> ocamlc.opt, it has a different run-time that does not provide the
> symbol. Linking fails. Therefore, although ocamlc.opt can be used to
> compile projects with delimcc, the final linking step must be done
> with ocamlc rather than ocamlc.opt
> 
> I managed to get around the problem using a weak reference. Alas, the
> subterfuge does not seem to work on Mac OS.
> 
> The real problem in my view is the strange decision to load shared
> libraries at link time and force the resolution of their undefined
> references. This decision certainly makes linking slower, without
> providing much benefit, it seems. After all, if the resolution
> succeeded at link time, it may still fail at run time since the
> linked executable can be run in a different location or even a
> different computer.
> 
> So, the real problem to me is ocamlc using RTLD_NOW flag when loading
> shared library. Removing the flag would make linking faster, and less
> painful.
> 
> A few technical details: dlopen with the problematic flag occurs in
> the function caml_dlopen in the file byterun/unix.c
> 
> void * caml_dlopen(char * libname, int for_execution, int global)
> {
>   return dlopen(libname, RTLD_NOW | (global ? RTLD_GLOBAL : RTLD_LOCAL) | RTLD_NODELETE);
>   /* Could use RTLD_LAZY if for_execution == 0, but needs testing */
> }
> 
> That function caml_dlopen is used within caml_dynlink_open_lib,
> which, under alias dll_open, is called in Dll.open_dll. The latter
> function is invoked in Bytelink.link_bytecode.
> 
> 
> 
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  reply	other threads:[~2013-09-10 10:21 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-06 13:56 Romain Bardou
2013-09-06 14:55 ` Markus Mottl
2013-09-06 15:19   ` Romain Bardou
2013-09-06 15:27     ` Gabriel Scherer
2013-09-06 15:33       ` Alain Frisch
2013-09-06 20:51     ` Fabrice Le Fessant
2013-09-09  7:44       ` Romain Bardou
2013-09-11 13:00       ` Francois Berenger
2013-09-11 13:46         ` Wojciech Meyer
2013-09-12  1:23           ` Francois Berenger
2013-09-12 15:15             ` Jacques Le Normand
2013-09-30  8:06       ` [Caml-list] from oasis to obuild (original subject was Re: Accelerating compilation) Francois Berenger
2013-09-30  8:18         ` Török Edwin
2013-09-30  9:00         ` Fabrice Le Fessant
2013-09-30  9:13           ` Anil Madhavapeddy
2013-09-30 11:13             ` Alain Frisch
2013-09-30 11:19               ` Anil Madhavapeddy
2013-09-30 11:27                 ` Alain Frisch
2013-09-30 11:36                   ` Anil Madhavapeddy
2013-09-30  9:18           ` Francois Berenger
2013-09-30 14:11         ` Sylvain Le Gall
2013-10-01  0:57           ` Francois Berenger
2013-10-01 12:25             ` Sylvain Le Gall
2013-09-07 11:37     ` [Caml-list] Accelerating compilation Matej Kosik
2013-09-08  6:37     ` Francois Berenger
2013-09-06 15:18 ` Gabriel Scherer
2013-09-06 15:28   ` Romain Bardou
2013-09-06 16:04   ` Markus Mottl
2013-09-06 16:30 ` Xavier Leroy
2013-09-07 19:13   ` Wojciech Meyer
2013-09-07 21:42     ` Jacques-Pascal Deplaix
2013-09-08  1:59       ` Markus Mottl
2013-09-09  7:59   ` Romain Bardou
2013-09-09  8:25   ` Alain Frisch
2013-09-09  8:35     ` Francois Berenger
2013-09-09 10:13     ` Anil Madhavapeddy
2013-09-09 17:08     ` Adrien Nader
2013-09-09 17:17       ` Gabriel Kerneis
2013-09-10  2:01     ` oleg
2013-09-10 10:21       ` Gerd Stolpmann [this message]
2013-09-10 16:15       ` Adrien Nader
2013-09-10 16:46       ` Xavier Leroy
2013-09-10 16:53         ` Adrien Nader
2013-09-10 17:43           ` ygrek
2013-09-06 18:45 ` Martin Jambon
2013-09-09  8:15   ` Romain Bardou
2013-09-09  8:36     ` Francois Berenger
2013-09-09  8:41       ` Thomas Refis
2013-09-09 17:32     ` Aleksey Nogin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378808502.10274.136.camel@zotac \
    --to=info@gerd-stolpmann.de \
    --cc=Xavier.Leroy@inria.fr \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=oleg@okmij.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox