diff options
author | Jim Grosbach <grosbach@apple.com> | 2011-04-04 23:04:39 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2011-04-04 23:04:39 +0000 |
commit | fcbe5b71936b820647dffff0e4f9c60ece3988a5 (patch) | |
tree | dd2bae41b7d089760ca4f8477d732a1d1ca22e13 /tools/llvm-rtdyld/llvm-rtdyld.cpp | |
parent | c15a91dfc84822037c40ae9d37f63ce1b1a763bb (diff) |
Layer the memory manager between the JIT and the runtime Dyld.
The JITMemory manager references LLVM IR constructs directly, while the
runtime Dyld works at a lower level and can handle objects which may not
originate from LLVM IR. Introduce a new layer for the memory manager to
handle the interface between them. For the MCJIT, this layer will be almost
entirely simply a call-through w/ translation between the IR objects and
symbol names.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-rtdyld/llvm-rtdyld.cpp')
-rw-r--r-- | tools/llvm-rtdyld/llvm-rtdyld.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index a670944235..e09f14ad78 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -13,7 +13,6 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/OwningPtr.h" -#include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/Object/MachOObject.h" #include "llvm/Support/CommandLine.h" @@ -41,6 +40,20 @@ Action(cl::desc("Action to perform:"), /* *** */ +// A trivial memory manager that doesn't do anything fancy, just uses the +// support library allocation routines directly. +class TrivialMemoryManager : public RTDyldMemoryManager { +public: + uint64_t startFunctionBody(const char *Name, uintptr_t &Size); + void endFunctionBody(const char *Name, uint64_t FunctionStart, + uint64_t FunctionEnd) {} +}; + +uint64_t TrivialMemoryManager::startFunctionBody(const char *Name, + uintptr_t &Size) { + return (uint64_t)sys::Memory::AllocateRWX(Size, 0, 0).base(); +} + static const char *ProgramName; static void Message(const char *Type, const Twine &Msg) { @@ -61,7 +74,7 @@ static int executeInput() { return Error("unable to read input: '" + ec.message() + "'"); // Instantiate a dynamic linker. - RuntimeDyld Dyld(JITMemoryManager::CreateDefaultMemManager()); + RuntimeDyld Dyld(new TrivialMemoryManager); // Load the object file into it. if (Dyld.loadObject(InputBuffer.take())) { @@ -69,7 +82,7 @@ static int executeInput() { } // Get the address of "_main". - void *MainAddress = Dyld.getSymbolAddress("_main"); + uint64_t MainAddress = Dyld.getSymbolAddress("_main"); if (MainAddress == 0) return Error("no definition for '_main'"); @@ -83,7 +96,7 @@ static int executeInput() { return Error("unable to mark function executable: '" + ErrorStr + "'"); // Dispatch to _main(). - errs() << "loaded '_main' at: " << MainAddress << "\n"; + errs() << "loaded '_main' at: " << (void*)MainAddress << "\n"; int (*Main)(int, const char**) = (int(*)(int,const char**)) uintptr_t(MainAddress); |