[LLVMdev] LLVM ExecutionEngine/JIT trampoline question

Reid Kleckner reid.kleckner at gmail.com
Tue Feb 22 20:24:43 PST 2011


This is to support lazy compilation, so that when a new function is
invoked it is codegen'd and the trampoline is hotpatched to jump to
the new code.  This way all the callsites don't have to be updated.

Reid

On Tue, Feb 22, 2011 at 8:14 PM, Xin Tong Utoronto <x.tong at utoronto.ca> wrote:
> I understand that we need to push the address to a register then branch
> using the register. But i am asking why there is a trampoline there such
> that a call to foo is first branched to an snippet and the snippet branches
> to the X86CompilationCallback. is this snippet necessary ?
>
> Thanks
>
> Xin
>
>
> On Tue, Feb 22, 2011 at 12:39 PM, Reid Kleckner <reid.kleckner at gmail.com>
> wrote:
>>
>> The address of the callee may be more than 2 GB away in memory, which
>> cannot be encoded as an immediate offset in the call instruction.  So,
>> the value is first materialized with a mov instruction which can
>> encode the immediate and then jumped to through a register.
>>
>> Reid
>>
>> On Tue, Feb 22, 2011 at 12:03 PM, Xin Tong Utoronto <x.tong at utoronto.ca>
>> wrote:
>> > I have a question on the LLVM JIT
>> >
>> > I did some brief memory reading one day and I found that a call to a
>> > non-library function is resolved by the X86CompilationCallback, but the
>> > X86CompilationCallback is reached through a trampoline. why can not  the
>> > generated code jump to the X86CompilationCallback function directly ?
>> >
>> >           0x2b0a6a4d103b: mov    $0x2b0a6a561010,%rax
>> >           0x2b0a6a4d1045: callq  *%rax
>> > // call foo
>> >>
>> >>
>> >> ==>
>> >>
>> >> 0x2b0a6a561010: mov    $0xa743a0,%r10                   // some kind of
>> >> trampoline
>> >> 0x2b0a6a56101a: callq  *%r10
>> >>
>> >> ==>
>> >>
>> >> 0xa743a0 <X86CompilationCallback>:        push   %rbp
>> >> 0xa743a1 <X86CompilationCallback+1>:    mov    %rsp,%rbp
>> >> 0xa743a4 <X86CompilationCallback+4>:    push   %rdi
>> >> 0xa743a5 <X86CompilationCallback+5>:    push   %rsi
>> >
>> > --
>> > Kind Regards
>> >
>> > Xin Tong
>> >
>> > _______________________________________________
>> > LLVM Developers mailing list
>> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> >
>> >
>
>
>
> --
> Kind Regards
>
> Xin Tong
>




More information about the llvm-dev mailing list