[LLVMdev] Getting the start and end address of JITted code

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Dec 17 13:30:40 PST 2008


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.

Good luck!

Nicolas

> Thanks,
> Andrew.
>
> _______________________________________________
> 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