[LLVMdev] simple way to print disassembly of final code from jit?

Bill O'Hara billtohara at gmail.com
Wed Jul 7 20:45:00 PDT 2010

Thanks for all the hints everyone.

Based on your suggestion, O.J., I've added code to toy.cpp from the
tutorial to disassemble.

ready> 1+1;
ready> 	movabsq	$140737353367568, %rax
	movsd	(%rax), %xmm0
Evaluated to 2.000000

Which looks correct by inspection - printing the byte array to stdout
and feeding it to llvm-mc offline produces the same code as one would
also expect.

echo '0x48 0xb8 0x10 0x40 0xf4 0xf7 0xff 0x7f 0x0 0x0 0xf2 0xf 0x10
0x0 0xc3' |llvm-mc -disassemble -triple=x86_64-PC-Linux
	movabsq	$140737353367568, %rax
	movsd	(%rax), %xmm0


On Wed, Jul 7, 2010 at 3:07 AM,  <o.j.sivart at gmail.com> wrote:
> Hi Bill,
> I'm coincidently planning right now on doing exactly the same things as you. I haven't yet had a chance to implement the code, but I can point you to how I currently believe you can get access to what you need. If you take a look at the code for the implementation of lvm::JIT::runJITOnFunction(Function *, MachineCodeInfo *), you'll see that if a MachineCodeInfo parameter is supplied, it is populated via a call to setAddress and setSize via the registration of a JITEventListener on the Jitting of the given function. I'm almost certain this is the address and size that is needed by the disassembler. You then should be able to either use runJITOnFunction as part of your current JIT compilation process or do the same thing it does by way of registering your own JITEventListener to get access to the required values.
> O.J.
> p.s. let me know if you are successful in getting this working, I hope you have some success.
> On 07/07/2010, at 2:10 PM, Bill O'Hara wrote:
>> Thanks Reid - I'm on Windows. I guess I just assumed I was missing
>> something obvious in how to hook up the JIT and disassembler! Given
>> the nice looking disassembly code I found, I thought people would be
>> doing it all the time :-)
>> b.
>> On Tue, Jul 6, 2010 at 8:41 PM, Reid Kleckner <reid.kleckner at gmail.com> wrote:
>>> If you're on a recent flavor of Linux, you may be able to just go into
>>> gdb and type "disas <pointer-to-JITed-code>".  More detail here:
>>> http://llvm.org/docs/DebuggingJITedCode.html
>>> If you still want to do it programmatically, I think you might be
>>> stuck.  IIRC the length known by the JIT memory allocator is an
>>> overestimate (it's rounded up for alignment), so the disassembler will
>>> hit garbage at the end.
>>> Reid
>>> On Tue, Jul 6, 2010 at 3:07 PM, Bill O'Hara <billtohara at gmail.com> wrote:
>>>> Hi,
>>>> With the new llvm-mc code for disassembling, what is the recommended
>>>> way to disassemble the final code produced by a JIT compiler backend?
>>>> (Eg. in the toy.cpp example from the tutorial).
>>>> I can get the void* for the final code, but I don't know its length -
>>>> superficially at least it appears I need to know the length to
>>>> disassemble it as a buffer?
>>>> Thanks
>>>> b.
>>>> _______________________________________________
>>>> LLVM Developers mailing list
>>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list