From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 731B37FD8B for ; Fri, 11 Dec 2015 20:12:08 +0100 (CET) IronPort-PHdr: 9a23:HxUgtRaio3kIYyipALk7dpr/LSx+4OfEezUN459isYplN5qZpcS+bnLW6fgltlLVR4KTs6sC0LqI9fi4EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35rxj7j60qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45jOvAXfTQqC+zMwT28LnRdUS1zA5Q3mXpb8r232q+Bg1ySGFcLzRLEwHz+l6vE4ZgXvjXJNDT8y8GjNhoRPyocd6DCmoRFkicaAeoCeNNJ3eKXQbdITA21bUZACBGR6HoqgYt5XXKI6NuFCoty4/gNWoA== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BZBgBeH2tW/7BbRFBEGoM6U26CYoo3nGkBAQEBAQEGlREjhWwCgTA8EAEBAQEBAQEBgQmCLYIIAQEEOj8QCxgJExIPBSghHIgqCTu+GQEBAQEGAQEBAQEBHYYOPoUHiCaBGgWTAoNwAYU0gnGFFYItjRWNVzgrhAQ+NAGFZAEBAQ X-IPAS-Result: A0BZBgBeH2tW/7BbRFBEGoM6U26CYoo3nGkBAQEBAQEGlREjhWwCgTA8EAEBAQEBAQEBgQmCLYIIAQEEOj8QCxgJExIPBSghHIgqCTu+GQEBAQEGAQEBAQEBHYYOPoUHiCaBGgWTAoNwAYU0gnGFFYItjRWNVzgrhAQ+NAGFZAEBAQ X-IronPort-AV: E=Sophos;i="5.20,414,1444687200"; d="scan'208";a="156910751" Received: from annexia.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 11 Dec 2015 20:12:07 +0100 Received: from rich by annexia.org with local (Exim 4.84) (envelope-from ) id 1a7T6s-0004Fh-J3; Fri, 11 Dec 2015 19:12:06 +0000 Date: Fri, 11 Dec 2015 19:12:06 +0000 From: "Richard W.M. Jones" To: Matthieu Dubuget Cc: Caml-list Message-ID: <20151211191206.GB9373@annexia.org> References: <565971BA.2090502@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <565971BA.2090502@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [Caml-list] Runtime variant _pic 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