Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Dynamically loaded BSS not initialised to 0.
Date: Mon, 4 Jan 2010 14:10:28 +0000	[thread overview]
Message-ID: <20100104141028.GA3841@annexia.org> (raw)
In-Reply-To: <4B412680.7090405@citycable.ch>

On Mon, Jan 04, 2010 at 12:21:36AM +0100, Guillaume Yziquel wrote:
> Guillaume Yziquel a écrit :
> >Hello.
> >
> >I encountered a rather weird issue. A binding of mine works fine when 
> >bundled as a .cmxa, but fails when bundled as a .cma. I'm running a 
> >Linux Debian amd64.
> >
> >I've tracked down the issue to the following point: it seems that when 
> >the BSS (uninitialised data section) of libmonetdb5.so is dynamically 
> >loaded, it doesn't get initialised to 0. And the code in libmonetdb5.so 
> >relies on the fact that BSS gets initialised to 0 when dynamically loaded.
> >
> >So: is ocaml failing to initialise memory to 0 when limonetdb5.so is 
> >dynamically loaded?
> 
> Problem solved: This is in fact a symbol collision problem on the symbol 
> 'box'. There's one in libncurses, which is loaded by ocamlrun.

Good ol' ELF loading model ...  Uli wrote a really good introduction
to writing DSOs which everyone should read:

http://people.redhat.com/drepper/dsohowto.pdf

The issue of symbol scope is covered there too, although I don't think
it can help in this case.  One or other of the libraries is just going
to have to change the visibility of that symbol.  In ncurses it's a
public symbol, but if I understand the code correctly, in MonetDB it's
just an accidentally leaked global variable (not part of the API).  So
MonetDB could control the visibility of that symbol using a linker
script.  We use linker scripts extensively in libvirt to control which
clients can see which sets of symbols, eg:

http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/libvirt_public.syms;hb=HEAD
http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/libvirt_private.syms;hb=HEAD

In answer to your original question, initialization of the BSS is the
job of the loader (ld-linux.so(8)).  OCaml just calls dlopen(3), which
calls into some extremely well-tested code, so it was always going to
be unlikely that BSS initialization was the problem.

Rich.

-- 
Richard Jones
Red Hat


  reply	other threads:[~2010-01-04 14:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-03 11:37 Guillaume Yziquel
2010-01-03 23:21 ` [Caml-list] " Guillaume Yziquel
2010-01-04 14:10   ` Richard Jones [this message]
2010-01-08 20:12     ` Guillaume Yziquel

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=20100104141028.GA3841@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=guillaume.yziquel@citycable.ch \
    /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