Teach the RtDyld to tell the memory manager about how much space a function
authorJim Grosbach <grosbach@apple.com>
Fri, 13 May 2011 20:12:14 +0000 (20:12 +0000)
committerJim Grosbach <grosbach@apple.com>
Fri, 13 May 2011 20:12:14 +0000 (20:12 +0000)
actually takes rather than how much memory was allocated for it. This
is more accurate and should help the manager pack things more effectively.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131305 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

index 7548a87c9556c76eec115b7f1ca46ba4639254fe..2cfe87f37b0c24e2b369343d940261aa3f5d8d86 100644 (file)
@@ -129,18 +129,19 @@ void RuntimeDyldImpl::extractFunction(StringRef Name, uint8_t *StartAddress,
                                       uint8_t *EndAddress) {
   // Allocate memory for the function via the memory manager.
   uintptr_t Size = EndAddress - StartAddress + 1;
-  uint8_t *Mem = MemMgr->startFunctionBody(Name.data(), Size);
+  uintptr_t AllocSize = Size;
+  uint8_t *Mem = MemMgr->startFunctionBody(Name.data(), AllocSize);
   assert(Size >= (uint64_t)(EndAddress - StartAddress + 1) &&
          "Memory manager failed to allocate enough memory!");
   // Copy the function payload into the memory block.
-  memcpy(Mem, StartAddress, EndAddress - StartAddress + 1);
+  memcpy(Mem, StartAddress, Size);
   MemMgr->endFunctionBody(Name.data(), Mem, Mem + Size);
   // Remember where we put it.
   Functions[Name] = sys::MemoryBlock(Mem, Size);
   // Default the assigned address for this symbol to wherever this
   // allocated it.
   SymbolTable[Name] = Mem;
-  DEBUG(dbgs() << "    allocated to " << Mem << "\n");
+  DEBUG(dbgs() << "    allocated to [" << Mem << ", " << Mem + Size << "]\n");
 }
 
 bool RuntimeDyldImpl::