[LLVMdev] LLVM on 64-bit PowerPC Linux

Gary Benson gbenson at redhat.com
Fri Jul 3 07:29:37 PDT 2009


Hi all,

I'm trying to use LLVM on a 64-bit PowerPC Linux box.  This platform
has a weird way of dealing with function pointers which I don't think
LLVM has support for.  Can anyone point me in the right direction so
I can start implementing it?

The problem is this.  On most platforms, a function pointer in C is
the address of the entry point of the function.  This is the case for
32-bit Linux PowerPC, and, from looking at the code in LLVM it seems
to be the case for both 32- and 64-bit Darwin.  A call on these
platforms looks like this, assuming the function pointer is in rX,
and all arguments to the call have been put in the appropriate
places:

  mtctr rX
  bctrl

Simple.  On 64-bit Linux PowerPC, however, a function pointer in C
is the address of a function descriptor, a structure containing three
pointers:

 - The first pointer contains the address of the entry point of
   the function.
 - The second pointer contains the TOC base address for the function.
 - The third pointer contains the environment pointer (for languages
   that need one).

The TOC base address needs to be in r2, and the environment pointer
needs to be in r11.  Starting with the C function pointer in rX, a
call on 64-bit Linux PowerPC looks something like this:

  ld rY, 0(rX)          ; where rY is some free register
  mtctr rY
  std r2, 40(r1)        ; optional
  ld r2, 8(rX)
  ld r11, 16(rX)
  bctrl
  ld r2, 40(r1)         ; optional

The two lines marked "optional" could be omitted since LLVM doesn't
generate or use a TOC.

Any idea where I need to look to implement this?

Cheers,
Gary

-- 
http://gbenson.net/



More information about the llvm-dev mailing list