Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] Dynamic linking
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: RE: [Caml-list] Dynamic linking
On Tue, 2005-10-04 at 08:47 -0400, Alexander Bottema wrote:

> Now, as a developer it would be nice if it was possible to write certain
> parts in OCaml. The foreign language interface is good enough to be used
> in conjunction with C/C++, but the lack of support to use it in DLLs
> makes it impossible for us to have any OCaml code in our leaf product.
> 
> Nevertheless, I really tried to make it work (and I almost did). It's
> only Linux/AMD64 that I couldn't solve and I really tried to modify the
> AMD64 emitter.

I actually find this very strange. The x86 is incapable of
supporting position independent code without hackery or 
segmentation:

(a) there is no IP relative call instruction (only short branches)
(b) there is no IP relative data access (at all)

The amd64 (x86_64) on the other hand supports IP relative
calls and data access (with 32 bit offsets only, but
usually enough for all code and global data).


> > The only platform which I couldn't get to work was Linux AMD64. I
> tried
> > to modify the OCaml emitter for AMD64 to accommodate position
> > independent code using the offset tables, but it was too hard.

There is no need for offset tables. Just make sure all
'absolute' addresses accesses are changed to be RIP relative
and the assembler will do the rest automatically.

[There may be a problem on Windows, apparently the linker
can't add two offsets together due to a constraint in COFF
format, not sure about that though]

See section 2.2.5 of the AMD document 24592.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net