caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Embedding the ocaml runtime in a shared library on amd64/x86_64
@ 2009-12-02 12:33 Joost Yervante Damad
  2009-12-02 16:51 ` [Caml-list] " Richard Jones
  0 siblings, 1 reply; 7+ messages in thread
From: Joost Yervante Damad @ 2009-12-02 12:33 UTC (permalink / raw)
  To: caml-list; +Cc: toolslive

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/


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

end of thread, other threads:[~2010-01-05 12:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-02 12:33 Embedding the ocaml runtime in a shared library on amd64/x86_64 Joost Yervante Damad
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

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