failed assertion in PPCJITInfo.cpp when calling native function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

failed assertion in PPCJITInfo.cpp when calling native function

Andreas Eriksson
Hi,

This is a follow up to my previous email since I have now found out a bit
more about what goes wrong.

I am generating JIT code that calls a native function, but I get the following
assertion telling me that the PC relative jump is too long:

/llvm/lib/Target/PowerPC/PPCJITInfo.cpp:206: failed assertion
`ResultPtr >= -(1 << 23) && ResultPtr < (1 << 23) && "Relocation out
of range!"'

I have looked into this a bit further, and everythings seems perfectly all
right except for the fact that the 16M block of memory for the JIT code that
is allocated in the JITMemoryManager constructor is simply to far from the
native function.

I can actually get my program to work if I run it in gdb which causes the 16M
block to be allocated at a different address, closer to the native function.
When I run the same program (the very same binary) outside of gdb, the memory
for the JIT code is too far off.

When I run my program outside of gdb, the native function is more than 2^23
words from the JIT code, which is too far for a PC relative jump:

        nativeFunction address 0x63b4d4c
        JIT memory base 0x9008000 (allocated in JITMemoryManager constructor)
        /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/Target/PowerPC/PPCJITInfo.cpp:206:
failed assertion `ResultPtr >= -(1 << 23) && ResultPtr < (1 << 23) &&
"Relocation out of range!"'

And when I run the same program from gdb, I get lucky and the native function
is less than 2^23 words from the JIT code:

        nativeFunction address 0x63b4d4c
        JIT memory base 0x8008000 (allocated in JITMemoryManager constructor)
        Hello from nativeFunction

So how is this supposed to work? Is it wrong that the memory block for the JIT
code is allocated too far off or should a non PC relative jump be generated
instead?

Regards,

Andreas
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: failed assertion in PPCJITInfo.cpp when calling native function

Ralph Corderoy

Hi Andreas,

> /llvm/lib/Target/PowerPC/PPCJITInfo.cpp:206: failed assertion
> `ResultPtr >= -(1 << 23) && ResultPtr < (1 << 23) && "Relocation out
> of range!"'
> ...
> So how is this supposed to work? Is it wrong that the memory block for
> the JIT code is allocated too far off or should a non PC relative jump
> be generated instead?

I'd guess that the author of the code generator simply coped with the
easier, more common, case and put the assert() in to catch the uncommon,
not implemented yet, case rather than stumbling blindly on making
debugging more difficult.

In other words, the code generator needs improving to cope with a jump
to an address that is too far away for a PC-relative jump.

Cheers,


Ralph.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: failed assertion in PPCJITInfo.cpp when calling native function

Andreas Eriksson
Ok, thanks for the reply.

> In other words, the code generator needs improving to cope with a jump
> to an address that is too far away for a PC-relative jump.

Should I file this as a bug?

If no one better suited is willing to look at this soon, I am willing
to give it a try.
Any suggestions? Look at the x86 llvm backend and how gcc does it?

Regards,

Andreas
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: failed assertion in PPCJITInfo.cpp when calling native function

Chris Lattner
On Wed, 20 Sep 2006, Andreas Eriksson wrote:
> Ok, thanks for the reply.
>> In other words, the code generator needs improving to cope with a jump
>> to an address that is too far away for a PC-relative jump.

Right.

> Should I file this as a bug? If no one better suited is willing to look
> at this soon, I am willing to give it a try. Any suggestions? Look at
> the x86 llvm backend and how gcc does it?

I'll take a look at it, sorry for the delay.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: failed assertion in PPCJITInfo.cpp when calling native function

Chris Lattner
In reply to this post by Andreas Eriksson
On Tue, 19 Sep 2006, Andreas Eriksson wrote:
> When I run my program outside of gdb, the native function is more than 2^23
> words from the JIT code, which is too far for a PC relative jump:

> So how is this supposed to work? Is it wrong that the memory block for the JIT
> code is allocated too far off or should a non PC relative jump be generated
> instead?

A simple solution/workaround:  instead of using GetAddressOfSymbol +
addGlobalMapping directly, just name the external LLVM Function
"nativeFunction" instead of "native".  The JIT will automatically find
'nativeFunction' in your app and DTRT.

I will try to fix addGlobalToMapping.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev