caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Runtime variant _pic
@ 2015-11-28  9:19 Matthieu Dubuget
  2015-12-11 19:12 ` Richard W.M. Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Matthieu Dubuget @ 2015-11-28  9:19 UTC (permalink / raw)
  To: Caml-list

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.

Salutations


-- 
Matthieu Dubuget
Guide d’autodéfense numérique : http://guide.boum.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Runtime variant _pic
  2015-11-28  9:19 [Caml-list] Runtime variant _pic Matthieu Dubuget
@ 2015-12-11 19:12 ` Richard W.M. Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Richard W.M. Jones @ 2015-12-11 19:12 UTC (permalink / raw)
  To: Matthieu Dubuget; +Cc: Caml-list

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-11 19:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-28  9:19 [Caml-list] Runtime variant _pic Matthieu Dubuget
2015-12-11 19:12 ` Richard W.M. Jones

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).