caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rich@annexia.org>
To: Matthieu Dubuget <matthieu.dubuget@gmail.com>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Runtime variant _pic
Date: Fri, 11 Dec 2015 19:12:06 +0000	[thread overview]
Message-ID: <20151211191206.GB9373@annexia.org> (raw)
In-Reply-To: <565971BA.2090502@gmail.com>

On Sat, Nov 28, 2015 at 10:19:54AM +0100, Matthieu Dubuget wrote:
> Hello,
> 
> with version 4.02.3 of OCaml on a 64-bits linux box, I do have to add
> `-runtime-variant _pic` to `ocamlopt` arguments when generating a shared
> lib (.so).
> 
> I'd like to understand why and when this option is needed, in order to
> adapt my build script to use it only when needed.

We use it in nbdkit:

https://github.com/libguestfs/nbdkit/blob/master/plugins/ocaml/nbdkit-ocaml-plugin.pod

and the bug which triggered this request was:

http://caml.inria.fr/mantis/view.php?id=6693

which has some background information, especially Gerd's link here:

http://www.camlcity.org/knowledge/kb_002_shared_library.html

If you need to build a library that contains position independent code
(PIC), and the library is written in OCaml and compiled natively, then
you have to compile the OCaml code with -fPIC.  However that is not
sufficient, because the library will also be linked with the OCaml
runtime, and all that code needs to have been compiled with -fPIC too.

The '-runtime-variant _pic' parameter causes ocamlopt to link in the
variant of the runtime code that was compiled with -fPIC.

Prior to 4.02.2 there was no such variant, you had to compile the
whole of the OCaml runtime with -fPIC yourself - obviously not very
convenient :-)

On 32 bit Linux/x86 you could get away with it because the dynamic
loader is smart enough to be able to relocate even non PIC code
(although it's not very efficient to do so - you'll likely end up with
a complete private copy of the "shared" library in memory).  With
x86-64 you will need -fPIC everywhere.

Rich.

-- 
Richard Jones
Red Hat

      reply	other threads:[~2015-12-11 19:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-28  9:19 Matthieu Dubuget
2015-12-11 19:12 ` Richard W.M. Jones [this message]

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=20151211191206.GB9373@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=matthieu.dubuget@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).