caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joost Yervante Damad <joost@damad.be>
To: caml-list@inria.fr
Cc: toolslive@yahoo.com
Subject: Embedding the ocaml runtime in a shared library on amd64/x86_64
Date: Wed, 2 Dec 2009 13:33:11 +0100	[thread overview]
Message-ID: <200912021333.11599.joost@damad.be> (raw)

Hello,

while trying to get the ocaml runtime embedded in a shared library, I ran into issues similar to [1]. 
Basically there are quite some symbols that have a R_X86_64_32 relocation in libasmrun.a.
I worked around that by rebuilding libasmrun.a with -fPIC, however there still is the file amd64.S which gives errors like this:

usr/bin/ld: /usr/lib/ocaml/libasmrun.a(amd64.o): relocation R_X86_64_PC32 against symbol `caml_last_return_address' can not be used when making a shared 
object; recompile with -fPIC

For that I found the following workaround: add the -Bsymbolic linker option to the command that creates the shared library, something like this:

ocamlopt -ccopt -Wl,-Bsymbolic -verbose -o libmod.so -ccopt -shared mod.cmx modwrap.o

Then my C application links with libmod.so and runs.
It should be possible to adapt amd64.S to generate the correct relocation entries by adding @PLT to some of the symbols, something like this:

movq    %r15, G(caml_young_ptr)@PLT(%rip)

However while it removed the need to use -Bsymbolic when linking, the resulting library seems to be faulty because the application segfaults.

I think compiling with -fPIC by default on the amd64/x86_64 arch would be a good start to making it more usable for embedding.
Also it would be very interesting if someone with good knowledge of ocaml internals could fix amd64.S to be position independent.

Greetings, Joost Damad

[1] http://groups.google.com/group/fa.caml/browse_thread/thread/d734c80bc3fc5a1d/395cd691e481ceb7

-- 
Joost Yervante Damad - http://damad.be/joost/


             reply	other threads:[~2009-12-02 12:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-02 12:33 Joost Yervante Damad [this message]
2009-12-02 16:51 ` [Caml-list] " Richard Jones
2009-12-02 22:37   ` Stefano Zacchiroli
2009-12-03 10:56     ` Joost Yervante Damad
2009-12-03 11:53       ` Alain Frisch
2009-12-03 12:47       ` Stefano Zacchiroli
2010-01-05 12:52       ` [Caml-list] Embedding the ocaml runtime in a shared library on amd64/x86_64 [update] Joost Yervante Damad

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=200912021333.11599.joost@damad.be \
    --to=joost@damad.be \
    --cc=caml-list@inria.fr \
    --cc=toolslive@yahoo.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).