Andreas Eriksson
2006-Sep-19 20:17 UTC
[LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
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
Ralph Corderoy
2006-Sep-20 10:33 UTC
[LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
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.
Andreas Eriksson
2006-Sep-20 11:30 UTC
[LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
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
Chris Lattner
2006-Sep-20 18:04 UTC
[LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
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/
Possibly Parallel Threads
- [LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
- [LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?