This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
[BUG] Linux/PPC64 closures
- From: Marcus Comstedt <marcus at mc dot pp dot se>
- To: libffi-discuss at sourceware dot org
- Date: Mon, 14 Jul 2008 16:09:49 +0200
- Subject: [BUG] Linux/PPC64 closures
Hi.
I'm trying to use libffi to create closures for native Java methods
for IBM JDK 1.6.0.1 on Gentoo/PPC64. The problem is that they don't
work, since .ffi_closure_LINUX64 assumes that r11 holds a pointer to
the closure structure. While the IBM runtime does indeed put this
pointer into r11 during the extraction of the function address and
TOC value, it restores the register to a previous value before
actually jumping to the function:
0x0000040003196a28: std r11,-8(r1) <-- r11 is saved
0x0000040003196a2c: ori r11,r19,0
0x0000040003196a30: std r2,40(r1)
0x0000040003196a34: ld r2,0(r11)
0x0000040003196a38: mtctr r2
0x0000040003196a3c: ld r2,8(r11)
0x0000040003196a40: ld r11,-8(r1) <-- r11 is restored
0x0000040003196a44: bctrl <-- call
As far as I can see, the 64-bit PowerPC ELF ABI Supplement does not
require that r11 holds the function pointer, it only reserves it as a
volatile register for this purpose. It also explicitly says that the
callee can't depend on r11 keeping the value put there by the caller
anyway. So I think libffi is abusing the ABI. It should be rather
simple to rewrite the code to use r2 as the context register instead,
and let .ffi_closure_LINUX64 load the correct TOC value itself after
it has saved the context pointer to r11 or whatever.
// Marcus