caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <mail@philippewang.info>
To: "Ömer Sinan Ağacan" <omeragacan@gmail.com>
Cc: Dawid Toton <d0@wp.pl>, OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: OCaml binary formats -- how are they linked?
Date: Mon, 17 Jun 2013 01:18:32 +0100	[thread overview]
Message-ID: <CAAFfW_qkJKFec_VHHRuqmzeMt0TVVJ=rp78Lqwxy9jvXOf5Tsw@mail.gmail.com> (raw)
In-Reply-To: <CAMQQO3mEPo6mtt_d0HzM6Eps2mqM=4vSJdKwK=YoAx=8r_LAfw@mail.gmail.com>

On Fri, Jun 14, 2013 at 8:17 PM, Ömer Sinan Ağacan <omeragacan@gmail.com> 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

  reply	other threads:[~2013-06-17  0:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-14  9:30 [Caml-list] " Ömer Sinan Ağacan
2013-06-14 10:16 ` [Caml-list] " Dawid Toton
2013-06-14 12:02   ` Ömer Sinan Ağacan
2013-06-14 14:26     ` Dawid Toton
2013-06-14 19:17       ` Ömer Sinan Ağacan
2013-06-17  0:18         ` Philippe Wang [this message]
2013-06-17 12:12           ` Ömer Sinan Ağacan
2013-06-17 12:34             ` Philippe Wang

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='CAAFfW_qkJKFec_VHHRuqmzeMt0TVVJ=rp78Lqwxy9jvXOf5Tsw@mail.gmail.com' \
    --to=mail@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=d0@wp.pl \
    --cc=omeragacan@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).