BGB wrote:> ok, here is another option then: > the stub is set up to manually modify the code near the return address (may > be arch specific and require spiffy use of assembler). > >That's not another option. That's what I want to do.> now, how you would go about implementing this is up to you. >And I need to know if I can currently do that with LLVM. Thus my initial question :)> > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
----- Original Message ----- From: "Nicolas Geoffray" <nicolas.geoffray at lip6.fr> To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> Sent: Wednesday, November 07, 2007 2:35 PM Subject: Re: [LLVMdev] Dynamic (JIT) type resolution> BGB wrote: >> ok, here is another option then: >> the stub is set up to manually modify the code near the return address >> (may >> be arch specific and require spiffy use of assembler). >> >> > > That's not another option. That's what I want to do. > >> now, how you would go about implementing this is up to you. >> > > And I need to know if I can currently do that with LLVM. Thus my initial > question :) >for x86: I presume LLVM supports inline assembler, and also uses the traditional frame pointer-based stack layout, but I don't know the details (people who know LLVM could probably be more helpful here). ok, maybe here is an option: after getting the value (in the created stub), execute a chunk of inline assembler to modify the caller (note: will probably need to modify inline asm syntax, as compilers tend to differ on this point...). something like this (figure out sort of how it works, and maybe mutate into something usable): int lookup_stub() { int i; i=getElementOffsetOf("One", "a"); asm { mov eax, i //return value mov edx, [ebp+4] //return addr mov byte [edx-5], 0xB8 //mov eax, imm32 mov [edx-4], eax //store return value in imm } return(i); }
BGB wrote:> > for x86: > I presume LLVM supports inline assembler, and also uses the traditional > frame pointer-based stack layout, but I don't know the details (people who > know LLVM could probably be more helpful here). > > ok, maybe here is an option: > after getting the value (in the created stub), execute a chunk of inline > assembler to modify the caller (note: will probably need to modify inline > asm syntax, as compilers tend to differ on this point...). > >Thanks BGB, but at this point I can handle it ;-). The problem is not how in theory (patch the caller), but how in the LLVM code generation process. There are three steps for that: 1) How to represent the stub in the IR? An intrinsic? An external field with a ghost linkage? 2) At which point in LLVM do we know we won't have any optimization, so that the field operation is next to the stub call? 3) Make LLVM think the stub call is not a real call, so that callee-saved registers do not get clobbered.> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >