caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] [patch] PIC on amd64
@ 2006-01-25 13:26 Alexander Bottema
  2006-01-25 19:53 ` Erik Bourget
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Bottema @ 2006-01-25 13:26 UTC (permalink / raw)
  To: caml-list

Hasn't support for PIC/AMD64 been fixed in the latest release of OCaml
(3.09.1)? Or have you found a bug in 3.09.1? I've tried to (native)
compile a simple program on AMD64 as a shared library and it worked
fine.

Alexander Bottema
(Software Developer @ The Mathworks)

-----Original Message-----
From: caml-list-bounces@yquem.inria.fr
[mailto:caml-list-bounces@yquem.inria.fr] On Behalf Of Erik Bourget
Sent: Wednesday, January 25, 2006 7:52 AM
To: caml-list@yquem.inria.fr
Subject: [Caml-list] [patch] PIC on amd64


Attached is a patch that makes ocaml able to compile proper PIC code on
amd64.
This allows shared libraries to be created from ocaml code.

This patch needs work - in addition to being rough around the edges,
there is
a fairly major issue where it will generate patters as such:

some_label:
     movq camlPcre@GOTPCREL(%rip), %r13
     movq 248(%r13), %r10
     call caml_apply8@PLT
...
caml_apply8:
    call (%r10) # should call camlPcre+248

This would be cool but %r10 is clobbered by the call in some
circumstances as
it's defined as a scratch register.  Ocaml's compiler seems to have
logic to
'spill' registers onto the stack but I haven't studied it hard enough to
put
it to use; maybe someone else is more familiar and will be able to mark
registers as live when they are used in this way?  :)

- Erik


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

* Re: [Caml-list] [patch] PIC on amd64
  2006-01-25 13:26 [Caml-list] [patch] PIC on amd64 Alexander Bottema
@ 2006-01-25 19:53 ` Erik Bourget
  0 siblings, 0 replies; 2+ messages in thread
From: Erik Bourget @ 2006-01-25 19:53 UTC (permalink / raw)
  To: Alexander Bottema; +Cc: caml-list

"Alexander Bottema" <Alexander.Bottema@mathworks.com> writes:

> Hasn't support for PIC/AMD64 been fixed in the latest release of OCaml
> (3.09.1)? Or have you found a bug in 3.09.1? I've tried to (native)
> compile a simple program on AMD64 as a shared library and it worked
> fine.

The problem is when you try to go beyond simple :)

ocamlopt -fPIC -output-obj -o hello.o pcre.cmxa hello.cmx
ld -shared --whole-archive -o hello.so hello.o -lpcre

You could make a shared library from ocaml if you assembled everything into
one object file as the assembler would be able to see all the functions.
amd64 linkers require you to look up functions in the GOT (which ld.so keeps
up to date when it loads new stuff) if they're not local.

ocaml 3.09.1:
  movq symbol(%rip), %r11  # add symbol to %rip and we know in memory where 
                           # it is.

With shared library patch:
  movq symbol@GOTPCREL(%rip), %r11  # get the address of the symbol in 
                                    # the table the linker has made for us,
  movq (%r11), %r11                 # and load it.  We have to do this because
                                    # we don't know the address of
                                    # symbol until runtime!

So, specifically, the aim of this patch is to allow the creation of shared
libraries that in turn pull in other libraries.  The amd64 ABI doc
(x86-64.org) goes into great detail about the different kinds of relocations
that are available - some are valid for shared objects and some are not.

- Erik


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

end of thread, other threads:[~2006-01-25 19:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-25 13:26 [Caml-list] [patch] PIC on amd64 Alexander Bottema
2006-01-25 19:53 ` Erik Bourget

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