On Fri, 2012-07-20 at 08:36 +0200, Duncan Sands wrote:> Hi Adhemerval Zanella, the old JIT infrastructure is going away, to be replaced > by "MC-JIT" (try passing -use-mcjit to lli). It sounds like you are working on > the old JIT, so I suggest you work instead on getting MC-JIT working on powerpc.Hi Duncan, Thanks for the pointers. We hadn't stumbled across the MC-JIT refs in our digging so far. (LLVM GettingStarted.html doesn't mention it, and (FIXME: T.B.D.) under llvm/lib/mc, so I suppose the MC jit is fairly recent?) Are we safe to assume the old JIT infrastructure will be completely replaced, or are there likely to be 'users' that may still need functionality? I imagine since the old jit is where Adhemerval was focused, the build/test steps must still be referencing it. Thanks, -Will> > Ciao, Duncan. > > I am currently working with PPC64 JIT support for LLVM. So far I could make function calls > > work by adding function descriptors in 'lib/Target/PowerPC/PPCJITInfo.h' and adding a > > virtual method at 'LLVM::TargetJITInfo' that is called within 'JITEmitter::finishFunction' > > just after 'sys::Memory::InvalidateInstructionCache' to update the Global Mapping with > > function descriptor instead of the function address. The JIT function descriptor is > > loaded correctly in 'JIT::runFunction', instead of assuming the JIT function code is > > an ODP. > > > > Now I'm trying to make the relocation work properly. Using the testcase '2003-01-04-ArgumentBug' > > the assembly generated for main functions is the following: > > > > .L.main: > > # BB#0: > > mflr 0 > > std 0, 16(1) > > stdu 1, -112(1) > > lis 3, .LCPI1_0 at ha > > li 4, 1 > > lfs 1, .LCPI1_0 at l(3) > > li 3, 0 > > bl foo > > nop > > addi 1, 1, 112 > > ld 0, 16(1) > > mtlr 0 > > blr > > > > Which is correct, however for the JIT one generated in memory the relocations generate some issues. > > > > First the 'lis 3, .LCPI1_0 at ha' can possible overflow which will generate an wrong relocation. > > Since the const data will be place just before the function code in JIT generation, my first > > approach was to point the functions descriptor TOC to the JIT function base, so the 'lis' relocation > > could be rewritten as 'addis 3,2,.LCPI1 at TOC@ha'. > > > > And there where I could use some help: is it the best approach? Where is the best place to make this > > kind of analysis? Is there another way to make code adjustments for JIT? > > > > At fist I though to put the logic at 'lib/Target/PowerPC/PPCJITInfo.cpp', but from what I could > > understand the 'relocate' function method is indeed just to operate on the relocation > > addresses, not to change the upcode. > > > > Any advices/tips/suggestion would be appreciated. > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On 07/20/2012 10:35 AM, Will Schmidt wrote:> On Fri, 2012-07-20 at 08:36 +0200, Duncan Sands wrote: >> Hi Adhemerval Zanella, the old JIT infrastructure is going away, to be replaced >> by "MC-JIT" (try passing -use-mcjit to lli). It sounds like you are working on >> the old JIT, so I suggest you work instead on getting MC-JIT working on powerpc. > Hi Duncan, > Thanks for the pointers. We hadn't stumbled across the MC-JIT refs > in our digging so far. (LLVM GettingStarted.html doesn't mention it, > and (FIXME: T.B.D.) under llvm/lib/mc, so I suppose the MC jit is fairly > recent?) > Are we safe to assume the old JIT infrastructure will be completely > replaced, or are there likely to be 'users' that may still need > functionality? > I imagine since the old jit is where Adhemerval was focused, the > build/test steps must still be referencing it. > > Thanks, > -WillThanks for the reply Duncan, I shifted my focus fo MCJIT. So far I could check there are basically two issues with MCJIT relating to PPC64 support: 1. Looks like LLVM does not generate PPC64 PIC code with TOC references. Using the testcase '2003-01-04-ArgumentBug.ll' I tried to invoke the llc with '-march=ppc64 -mcpu=ppc64 -mattr=64bit' and still uses the 32-bits relocations (@ha/@l(3)) where TOC would be expected (@toc). I did some adjustments to JIT code and function calling is correct (the function ODP is created and called), but BSS access is still not right since the 64-bits relocations are not done correctly. Could someone point where should I focus my efforts to add TOC support on PowerPC backend? 2. Relocations: I could add some support for PPC32 relocations by implementing some functions at 'RuntimeDyldELF.cpp', but then I fall back again in 1. (the PPC64 support is incomplete). Is my analysis correct or I am issuing llc/lli wrongly and not activating the PPC64 PIC support? Anyone to advice me on this one? Any help would be appreciated. -- Adhemerval Zanella Netto Software Engineer Linux Technology Center Brazil Toolchain / GLIBC on Power Architecture azanella at linux.vnet.ibm.com / azanella at br.ibm.com +55 61 8642-9890
On 07/31/2012 11:26 AM, Adhemerval Zanella wrote:> On 07/20/2012 10:35 AM, Will Schmidt wrote: >> On Fri, 2012-07-20 at 08:36 +0200, Duncan Sands wrote: >>> Hi Adhemerval Zanella, the old JIT infrastructure is going away, to be replaced >>> by "MC-JIT" (try passing -use-mcjit to lli). It sounds like you are working on >>> the old JIT, so I suggest you work instead on getting MC-JIT working on powerpc. >> Hi Duncan, >> Thanks for the pointers. We hadn't stumbled across the MC-JIT refs >> in our digging so far. (LLVM GettingStarted.html doesn't mention it, >> and (FIXME: T.B.D.) under llvm/lib/mc, so I suppose the MC jit is fairly >> recent?) >> Are we safe to assume the old JIT infrastructure will be completely >> replaced, or are there likely to be 'users' that may still need >> functionality? >> I imagine since the old jit is where Adhemerval was focused, the >> build/test steps must still be referencing it. >> >> Thanks, >> -Will > Thanks for the reply Duncan, I shifted my focus fo MCJIT. So far I could check there are basically > two issues with MCJIT relating to PPC64 support: > > 1. Looks like LLVM does not generate PPC64 PIC code with TOC references. Using the testcase > '2003-01-04-ArgumentBug.ll' I tried to invoke the llc with '-march=ppc64 -mcpu=ppc64 -mattr=64bit' > and still uses the 32-bits relocations (@ha/@l(3)) where TOC would be expected (@toc). I did some > adjustments to JIT code and function calling is correct (the function ODP is created and called), > but BSS access is still not right since the 64-bits relocations are not done correctly. > Could someone point where should I focus my efforts to add TOC support on PowerPC backend? > > 2. Relocations: I could add some support for PPC32 relocations by implementing some functions at > 'RuntimeDyldELF.cpp', but then I fall back again in 1. (the PPC64 support is incomplete). > > Is my analysis correct or I am issuing llc/lli wrongly and not activating the PPC64 PIC support? > Anyone to advice me on this one? Any help would be appreciated. >The modifications I have done so far are in attachments. Basically it adds the PPC64 machine name in Target, add some relocation support in Elf Runtime class. I'm still figuring out a lot of internal llvm and the patch is still WIP. -- Adhemerval Zanella Netto Software Engineer Linux Technology Center Brazil Toolchain / GLIBC on Power Architecture azanella at linux.vnet.ibm.com / azanella at br.ibm.com +55 61 8642-9890 -------------- next part -------------- A non-text attachment was scrubbed... Name: mcjit-ppc64.patch Type: text/x-patch Size: 6401 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120731/5f31545f/attachment.bin>
Hi Adhemerval, It looks like the default relocation model for PowerPC is "DynamicNoPIC" for the Darwin OS and "Static" elsewhere. There is a command line option ("relocation-model") to override this default in both lli and llc. However, I'm not sure using this will reduce your troubles. You may end up going down code paths that have not been sufficiently exercised in the past. I don't really know anything specifically about PowerPC, but I think that you may be able to glean some guidance from a patch which Petar Jovanovic recently submitted to add MCJIT support for MIPS. The patch (which hasn't yet been committed) is here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120723/146977.html The big difference I see between Petar's patch and yours is that Petar added explicit ELFWriterInfo support for his platform. This is outside the area of the code that I know well, but it looks like that might be the right direction for you to investigate to fix your relocation difficulties. -Andy -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Adhemerval Zanella Sent: Tuesday, July 31, 2012 7:26 AM To: will_schmidt at vnet.ibm.com Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Help with PPC64 JIT On 07/20/2012 10:35 AM, Will Schmidt wrote:> On Fri, 2012-07-20 at 08:36 +0200, Duncan Sands wrote: >> Hi Adhemerval Zanella, the old JIT infrastructure is going away, to >> be replaced by "MC-JIT" (try passing -use-mcjit to lli). It sounds >> like you are working on the old JIT, so I suggest you work instead on getting MC-JIT working on powerpc. > Hi Duncan, > Thanks for the pointers. We hadn't stumbled across the MC-JIT refs > in our digging so far. (LLVM GettingStarted.html doesn't mention it, > and (FIXME: T.B.D.) under llvm/lib/mc, so I suppose the MC jit is > fairly > recent?) > Are we safe to assume the old JIT infrastructure will be completely > replaced, or are there likely to be 'users' that may still need > functionality? > I imagine since the old jit is where Adhemerval was focused, the > build/test steps must still be referencing it. > > Thanks, > -WillThanks for the reply Duncan, I shifted my focus fo MCJIT. So far I could check there are basically two issues with MCJIT relating to PPC64 support: 1. Looks like LLVM does not generate PPC64 PIC code with TOC references. Using the testcase '2003-01-04-ArgumentBug.ll' I tried to invoke the llc with '-march=ppc64 -mcpu=ppc64 -mattr=64bit' and still uses the 32-bits relocations (@ha/@l(3)) where TOC would be expected (@toc). I did some adjustments to JIT code and function calling is correct (the function ODP is created and called), but BSS access is still not right since the 64-bits relocations are not done correctly. Could someone point where should I focus my efforts to add TOC support on PowerPC backend? 2. Relocations: I could add some support for PPC32 relocations by implementing some functions at 'RuntimeDyldELF.cpp', but then I fall back again in 1. (the PPC64 support is incomplete). Is my analysis correct or I am issuing llc/lli wrongly and not activating the PPC64 PIC support? Anyone to advice me on this one? Any help would be appreciated. -- Adhemerval Zanella Netto Software Engineer Linux Technology Center Brazil Toolchain / GLIBC on Power Architecture azanella at linux.vnet.ibm.com / azanella at br.ibm.com +55 61 8642-9890 _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev