[PATCH] D13627: [JIT] TrivialMemoryManager: Fail if we can't allocate memory

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 21:29:52 PDT 2015


davide created this revision.
davide added a reviewer: lhames.
davide added a subscriber: llvm-commits.

TrivialMemoryManager currently doesn't check the return type of AllocateRWX -- and returns a 'null' MemoryBlock to its caller.
I would like to change the behavior, and check for errors inside the memory manager, so that If AllocateRWX fails, we can get an human readable error message that explains why the allocation failed, rather than printing a generic failure message. Also, if we check for memory allocation failures in the MemoryManager, we can guarantee the following invariant: if the memory manager returns, the buffer returned is valid. Therefore the clients can convert error handling into asserts.
Please let me know what you think.

http://reviews.llvm.org/D13627

Files:
  tools/llvm-rtdyld/llvm-rtdyld.cpp

Index: tools/llvm-rtdyld/llvm-rtdyld.cpp
===================================================================
--- tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -181,7 +181,10 @@
                                                    unsigned Alignment,
                                                    unsigned SectionID,
                                                    StringRef SectionName) {
-  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, nullptr);
+  std::string Err;
+  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
+  if (!MB.base())
+    report_fatal_error("MemoryManager allocation failed: " + Err);
   FunctionMemory.push_back(MB);
   return (uint8_t*)MB.base();
 }
@@ -191,7 +194,10 @@
                                                    unsigned SectionID,
                                                    StringRef SectionName,
                                                    bool IsReadOnly) {
-  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, nullptr);
+  std::string Err;
+  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
+  if (!MB.base())
+    report_fatal_error("MemoryManager allocation failed: " + Err);
   DataMemory.push_back(MB);
   return (uint8_t*)MB.base();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13627.37043.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151011/20b84ffb/attachment-0001.bin>


More information about the llvm-commits mailing list