[LLVMdev] Getting the start and end address of JITted code
Andrew Haley
aph at redhat.com
Wed Dec 17 13:48:13 PST 2008
Nicolas Geoffray wrote:
> Hi Andrew,
>
> Andrew Haley wrote:
>> Here's my problem, which I raised on IRC:
>>
>> JIT::getPointerToFunction gets the address of the start of a function.
>> But how do I find out where the end of the function is? I need this
>> to register the function for profiling.
>>
>> varth said: aph, you need to intercept the "endFunctionBody" call on
>> the memory manager, it will tell you the start pointer and the end
>> pointer
>>
>
> Yep, that's what I said :)
>
>> But how can I do this? The obvious way would be for me to inherit
>> from DefaultMemoryManager and pass an instance of my class to
>> ExecutionEngine::createJIT.
>
> Correct.
>
>> But DefaultMemoryManager isn't public so
>> I can't inherit from it.
>
> You should inherit from JITMemoryManager.
>> It's not at all obvious to me how I'm
>> supposed to intercept endFunctionBody.
>
> Here's how vmkit does it:
>
> class MvmMemoryManager : public JITMemoryManager {
>
> /// realMemoryManager - The real allocator
> JITMemoryManager* realMemoryManager;
>
> public:
>
> MvmMemoryManager() : JITMemoryManager() {
> realMemoryManager = JITMemoryManager::CreateDefaultMemManager();
> }
>
>
> And MvmMemoryManager redefines all the virtual functions to call the
> real memory manager. For endFunctionBody, it inserts in a map the start
> and end pointers.
So I have to define *all* the virtual functions and wrap the memory manager
just in order to intercept endFunctionBody? !! Sheesh.
Thanks,
Andrew.
More information about the llvm-dev
mailing list