From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 303037EE42 for ; Mon, 17 Jun 2013 02:18:54 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 74.125.82.43 as permitted sender) identity=mailfrom; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f43.google.com) identity=helo; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-wg0-f43.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkBAJ9VvlFKfVIrjWdsb2JhbABagzpJgn+7S3oIFg4BAQEBBwsLCRIGJIIjAQEEASMdATgBAwwBBQULDQICJgICIQESAQUBHAYTh3wDCQaaYYt8g06DfScNiEwBBQyBGos+gTF/gwaBFAOOQ4UsgWuBZ4wfgz8WKYFdglk7gTU X-IPAS-Result: AjkBAJ9VvlFKfVIrjWdsb2JhbABagzpJgn+7S3oIFg4BAQEBBwsLCRIGJIIjAQEEASMdATgBAwwBBQULDQICJgICIQESAQUBHAYTh3wDCQaaYYt8g06DfScNiEwBBQyBGos+gTF/gwaBFAOOQ4UsgWuBZ4wfgz8WKYFdglk7gTU X-IronPort-AV: E=Sophos;i="4.87,876,1363129200"; d="scan'208";a="22054386" Received: from mail-wg0-f43.google.com ([74.125.82.43]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Jun 2013 02:18:32 +0200 Received: by mail-wg0-f43.google.com with SMTP id z11so1852856wgg.34 for ; Sun, 16 Jun 2013 17:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=oGzEsyQMH7PlXOGdL/8A8eRb7sZK/rv7+PSwVeAQzjs=; b=JvX52zBHLWVhJ1kQKt0T0BWZLVI4TxQh+Vh/owcotF8uXnw0IAP6pfvDhNusRuuo1n 0nAdqO6j6cDib2HwRT7/MsYuG7upaCfn6wDgyeb8SB8usDWaRigCa5V/+PYPcfC5SXWn vnCQUJNSxhxUhEog/03DC4A717sLnI9a/wvGfOomcmRpGWjiC3KIMK3q6sN7CJdgvt09 Fhs2vgF0JiQ0ghx4F0YduzolFUfU3H83sLiFjkSVuFwUBa1jLkC4x8jfPNiAd+Vq6jTb oYRhTuA0b5WHE2xkMWrWYrBBowj0j2/Zu/gXefvyCZ7q0rnmun9LpzmxBnBPtpKqXNdl 34pA== MIME-Version: 1.0 X-Received: by 10.180.187.209 with SMTP id fu17mr3551820wic.52.1371428312100; Sun, 16 Jun 2013 17:18:32 -0700 (PDT) Sender: philippe.wang.lists@gmail.com Received: by 10.216.13.74 with HTTP; Sun, 16 Jun 2013 17:18:32 -0700 (PDT) In-Reply-To: References: Date: Mon, 17 Jun 2013 01:18:32 +0100 X-Google-Sender-Auth: cdGb55lkaPQyy4lxblKfIhlM4q8 Message-ID: From: Philippe Wang To: =?ISO-8859-9?Q?=D6mer_Sinan_A=F0acan?= Cc: Dawid Toton , OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Re: OCaml binary formats -- how are they linked? On Fri, Jun 14, 2013 at 8:17 PM, =C3=96mer Sinan A=C4=9Facan wrote: > Dawid, thanks for your answer. It really helped. > >> Bytecode is compiled to a files with #! prefix. > > Interesting, I just tried reading an OCaml executable created with > ocamlc, and it had a ELF header. Am I compiling to my program to > native by mistake? I'm not calling ocamlopt, only ocamlc. > If you're using ocamlc and have ELF header, it probably means that you used the option -custom. In that case, instead of a #!/path/to/ocamlrun, you get ocamlrun (the binary) as the first part of the binary. Actually, when the OCaml VM runs a bytecode executable, it reads from the end of file (where there are information on, e.g., where the bytecode is), hence the fact that virtually anything can be put before the actual bytecode. $ echo 'print_endline "hello";;' > p.ml $ ocamlc p.ml -o p $ ( head -n 1 p ; cat p.ml p ) > q $ chmod a+x q $ ./q hello Oh, a binary that contains its source code! :-) (It's not that easy if it's compiled using -custom, because then you have to find out when the ELF binary ends in order to insert whatever you might want to insert). -- Philippe Wang mail@philippewang.info