[llvm] r176057 - Provide workaround for PR 15130.

Andrew Kaylor andrew.kaylor at intel.com
Mon Feb 25 15:00:19 PST 2013


Author: akaylor
Date: Mon Feb 25 17:00:19 2013
New Revision: 176057

URL: http://llvm.org/viewvc/llvm-project?rev=176057&view=rev
Log:
Provide workaround for PR 15130.

This changes the RecordingMemoryManager in lli to use mapped memory rather than malloc to allocate memory for sections and uses a 'near' MemoryBlock to keep the allocations together.  This works around a problem in MCJIT where relocations are applied to a generated image immediately oupon generation, which isn't appropriate for the remote case.


Modified:
    llvm/trunk/tools/lli/RecordingMemoryManager.cpp
    llvm/trunk/tools/lli/RecordingMemoryManager.h

Modified: llvm/trunk/tools/lli/RecordingMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/RecordingMemoryManager.cpp?rev=176057&r1=176056&r2=176057&view=diff
==============================================================================
--- llvm/trunk/tools/lli/RecordingMemoryManager.cpp (original)
+++ llvm/trunk/tools/lli/RecordingMemoryManager.cpp Mon Feb 25 17:00:19 2013
@@ -19,23 +19,22 @@ RecordingMemoryManager::~RecordingMemory
   for (SmallVectorImpl<Allocation>::iterator
          I = AllocatedCodeMem.begin(), E = AllocatedCodeMem.end();
        I != E; ++I)
-    free(I->first.base());
+    sys::Memory::releaseMappedMemory(I->first);
   for (SmallVectorImpl<Allocation>::iterator
          I = AllocatedDataMem.begin(), E = AllocatedDataMem.end();
        I != E; ++I)
-    free(I->first.base());
+    sys::Memory::releaseMappedMemory(I->first);
 }
 
 uint8_t *RecordingMemoryManager::
 allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) {
   // The recording memory manager is just a local copy of the remote target.
   // The alignment requirement is just stored here for later use. Regular
-  // heap storage is sufficient here.
-  void *Addr = malloc(Size);
-  assert(Addr && "malloc() failure!");
-  sys::MemoryBlock Block(Addr, Size);
+  // heap storage is sufficient here, but we're using mapped memory to work
+  // around a bug in MCJIT.
+  sys::MemoryBlock Block = allocateSection(Size);
   AllocatedCodeMem.push_back(Allocation(Block, Alignment));
-  return (uint8_t*)Addr;
+  return (uint8_t*)Block.base();
 }
 
 uint8_t *RecordingMemoryManager::
@@ -43,13 +42,30 @@ allocateDataSection(uintptr_t Size, unsi
                     unsigned SectionID, bool IsReadOnly) {
   // The recording memory manager is just a local copy of the remote target.
   // The alignment requirement is just stored here for later use. Regular
-  // heap storage is sufficient here.
-  void *Addr = malloc(Size);
-  assert(Addr && "malloc() failure!");
-  sys::MemoryBlock Block(Addr, Size);
+  // heap storage is sufficient here, but we're using mapped memory to work
+  // around a bug in MCJIT.
+  sys::MemoryBlock Block = allocateSection(Size);
   AllocatedDataMem.push_back(Allocation(Block, Alignment));
-  return (uint8_t*)Addr;
+  return (uint8_t*)Block.base();
 }
+
+sys::MemoryBlock RecordingMemoryManager::allocateSection(uintptr_t Size) {
+  error_code ec;
+  sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size,
+                                                          &Near,
+                                                          sys::Memory::MF_READ |
+                                                          sys::Memory::MF_WRITE,
+                                                          ec);
+  assert(!ec && MB.base());
+
+  // FIXME: This is part of a work around to keep sections near one another
+  // when MCJIT performs relocations after code emission but before
+  // the generated code is moved to the remote target.
+  // Save this address as the basis for our next request
+  Near = MB;
+  return MB;
+}
+
 void RecordingMemoryManager::setMemoryWritable() { llvm_unreachable("Unexpected!"); }
 void RecordingMemoryManager::setMemoryExecutable() { llvm_unreachable("Unexpected!"); }
 void RecordingMemoryManager::setPoisonMemory(bool poison) { llvm_unreachable("Unexpected!"); }

Modified: llvm/trunk/tools/lli/RecordingMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/RecordingMemoryManager.h?rev=176057&r1=176056&r2=176057&view=diff
==============================================================================
--- llvm/trunk/tools/lli/RecordingMemoryManager.h (original)
+++ llvm/trunk/tools/lli/RecordingMemoryManager.h Mon Feb 25 17:00:19 2013
@@ -31,6 +31,12 @@ private:
   SmallVector<Allocation, 16> AllocatedDataMem;
   SmallVector<Allocation, 16> AllocatedCodeMem;
 
+  // FIXME: This is part of a work around to keep sections near one another
+  // when MCJIT performs relocations after code emission but before
+  // the generated code is moved to the remote target.
+  sys::MemoryBlock Near;
+  sys::MemoryBlock allocateSection(uintptr_t Size);
+
 public:
   RecordingMemoryManager() {}
   virtual ~RecordingMemoryManager();





More information about the llvm-commits mailing list