diff --git a/llvm/include/llvm-c/ExecutionEngine.h b/llvm/include/llvm-c/ExecutionEngine.h index cf3565c217ea..4e767b2e6418 100644 --- a/llvm/include/llvm-c/ExecutionEngine.h +++ b/llvm/include/llvm-c/ExecutionEngine.h @@ -171,13 +171,14 @@ void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); /*===-- Operations on memory managers -------------------------------------===*/ -typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, - uintptr_t Size, unsigned Alignment, - unsigned SectionID); -typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, - uintptr_t Size, unsigned Alignment, - unsigned SectionID, LLVMBool IsReadOnly); -typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg); +typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)( + void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, + const char *SectionName); +typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)( + void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, + const char *SectionName, LLVMBool IsReadOnly); +typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)( + void *Opaque, char **ErrMsg); typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque); /** diff --git a/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h b/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h index 02e6b19b91cf..59326875850d 100644 --- a/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h @@ -38,14 +38,16 @@ public: /// executable code. The SectionID is a unique identifier assigned by the JIT /// engine, and optionally recorded by the memory manager to access a loaded /// section. - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) = 0; - + virtual uint8_t *allocateCodeSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName) = 0; + /// Allocate a memory block of (at least) the given size suitable for data. /// The SectionID is a unique identifier assigned by the JIT engine, and /// optionally recorded by the memory manager to access a loaded section. - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) = 0; + virtual uint8_t *allocateDataSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool IsReadOnly) = 0; /// Register the EH frames with the runtime so that c++ exceptions work. virtual void registerEHFrames(StringRef SectionData); diff --git a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h index 6ee2a2aae590..fd6e41f91ffb 100644 --- a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h @@ -49,7 +49,8 @@ public: /// The value of \p Alignment must be a power of two. If \p Alignment is zero /// a default alignment of 16 will be used. virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID); + unsigned SectionID, + StringRef SectionName); /// \brief Allocates a memory block of (at least) the given size suitable for /// executable code. @@ -58,6 +59,7 @@ public: /// a default alignment of 16 will be used. virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool isReadOnly); /// \brief Update section-specific memory permissions and other attributes. diff --git a/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp b/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp index 941444578213..2d34eeabf2a9 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp @@ -351,12 +351,13 @@ public: void *Opaque); virtual ~SimpleBindingMemoryManager(); - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID); + virtual uint8_t *allocateCodeSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName); - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, - bool isReadOnly); + virtual uint8_t *allocateDataSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool isReadOnly); virtual bool finalizeMemory(std::string *ErrMsg); @@ -384,13 +385,17 @@ SimpleBindingMemoryManager::~SimpleBindingMemoryManager() { } uint8_t *SimpleBindingMemoryManager::allocateCodeSection( - uintptr_t Size, unsigned Alignment, unsigned SectionID) { - return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID); + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName) { + return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID, + SectionName.str().c_str()); } uint8_t *SimpleBindingMemoryManager::allocateDataSection( - uintptr_t Size, unsigned Alignment, unsigned SectionID, bool isReadOnly) { + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool isReadOnly) { return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID, + SectionName.str().c_str(), isReadOnly); } diff --git a/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 94db2459877b..92ea13e5c4f6 100644 --- a/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp @@ -464,7 +464,7 @@ namespace { /// allocateCodeSection - Allocate memory for a code section. uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { + unsigned SectionID, StringRef SectionName) { // Grow the required block size to account for the block header Size += sizeof(*CurBlock); @@ -510,7 +510,8 @@ namespace { /// allocateDataSection - Allocate memory for a data section. uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) { + unsigned SectionID, StringRef SectionName, + bool IsReadOnly) { return (uint8_t*)DataAllocator.Allocate(Size, Alignment); } diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h index 5fb2eebd92ae..a40a9e429bed 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h @@ -35,14 +35,15 @@ public: // Functions deferred to client memory manager virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { - return ClientMM->allocateCodeSection(Size, Alignment, SectionID); + unsigned SectionID, StringRef SectionName) { + return ClientMM->allocateCodeSection(Size, Alignment, SectionID, SectionName); } virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) { + unsigned SectionID, StringRef SectionName, + bool IsReadOnly) { return ClientMM->allocateDataSection(Size, Alignment, - SectionID, IsReadOnly); + SectionID, SectionName, IsReadOnly); } virtual void registerEHFrames(StringRef SectionData) { diff --git a/llvm/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp index 5469c8374b1a..cf90e77e3895 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/SectionMemoryManager.cpp @@ -19,9 +19,10 @@ namespace llvm { uint8_t *SectionMemoryManager::allocateDataSection(uintptr_t Size, - unsigned Alignment, - unsigned SectionID, - bool IsReadOnly) { + unsigned Alignment, + unsigned SectionID, + StringRef SectionName, + bool IsReadOnly) { if (IsReadOnly) return allocateSection(RODataMem, Size, Alignment); return allocateSection(RWDataMem, Size, Alignment); @@ -29,7 +30,8 @@ uint8_t *SectionMemoryManager::allocateDataSection(uintptr_t Size, uint8_t *SectionMemoryManager::allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { + unsigned SectionID, + StringRef SectionName) { return allocateSection(CodeMem, Size, Alignment); } diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 89c04dd007b8..077442d8dfb1 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -182,8 +182,8 @@ void RuntimeDyldImpl::emitCommonSymbols(ObjectImage &Obj, SymbolTableMap &SymbolTable) { // Allocate memory for the section unsigned SectionID = Sections.size(); - uint8_t *Addr = MemMgr->allocateDataSection(TotalSize, sizeof(void*), - SectionID, false); + uint8_t *Addr = MemMgr->allocateDataSection( + TotalSize, sizeof(void*), SectionID, StringRef(), false); if (!Addr) report_fatal_error("Unable to allocate memory for common symbols!"); uint64_t Offset = 0; @@ -278,8 +278,9 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj, if (IsRequired) { Allocate = DataSize + StubBufSize; Addr = IsCode - ? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID) - : MemMgr->allocateDataSection(Allocate, Alignment, SectionID, IsReadOnly); + ? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID, Name) + : MemMgr->allocateDataSection(Allocate, Alignment, SectionID, Name, + IsReadOnly); if (!Addr) report_fatal_error("Unable to allocate section memory!"); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 6504f0e2d758..eb2a1a771d74 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -1337,8 +1337,8 @@ void RuntimeDyldELF::finalizeLoad() { // Allocate memory for the section unsigned SectionID = Sections.size(); size_t TotalSize = numGOTEntries * getGOTEntrySize(); - uint8_t *Addr = MemMgr->allocateDataSection(TotalSize, getGOTEntrySize(), - SectionID, false); + uint8_t *Addr = MemMgr->allocateDataSection( + TotalSize, getGOTEntrySize(), SectionID, ".got", false); if (!Addr) report_fatal_error("Unable to allocate memory for GOT!"); Sections.push_back(SectionEntry(".got", Addr, TotalSize, 0)); diff --git a/llvm/tools/lli/RecordingMemoryManager.cpp b/llvm/tools/lli/RecordingMemoryManager.cpp index ec55d2cd30e3..d54b8e434d08 100644 --- a/llvm/tools/lli/RecordingMemoryManager.cpp +++ b/llvm/tools/lli/RecordingMemoryManager.cpp @@ -27,7 +27,8 @@ RecordingMemoryManager::~RecordingMemoryManager() { } uint8_t *RecordingMemoryManager:: -allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) { +allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName) { // 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, but we're using mapped memory to work @@ -39,7 +40,8 @@ allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) { uint8_t *RecordingMemoryManager:: allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) { + unsigned SectionID, StringRef SectionName, + 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, but we're using mapped memory to work diff --git a/llvm/tools/lli/RecordingMemoryManager.h b/llvm/tools/lli/RecordingMemoryManager.h index b2919c39790a..05f4807d0454 100644 --- a/llvm/tools/lli/RecordingMemoryManager.h +++ b/llvm/tools/lli/RecordingMemoryManager.h @@ -50,10 +50,11 @@ public: const_code_iterator code_end() const { return AllocatedCodeMem.end(); } uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID); + unsigned SectionID, StringRef SectionName); uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly); + unsigned SectionID, StringRef SectionName, + bool IsReadOnly); void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true); diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp index 7f042d2ef242..c5c285431a4d 100644 --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -60,9 +60,10 @@ public: SmallVector DataMemory; uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID); + unsigned SectionID, StringRef SectionName); uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly); + unsigned SectionID, StringRef SectionName, + bool IsReadOnly); virtual void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true) { @@ -80,7 +81,8 @@ public: uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { + unsigned SectionID, + StringRef SectionName) { sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, 0, 0); FunctionMemory.push_back(MB); return (uint8_t*)MB.base(); @@ -89,6 +91,7 @@ uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size, uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool IsReadOnly) { sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, 0, 0); DataMemory.push_back(MB); diff --git a/llvm/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index 68ca53d4e6c2..731f7807f593 100644 --- a/llvm/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -281,11 +281,11 @@ TEST(JITMemoryManagerTest, TestManyStubs) { TEST(JITMemoryManagerTest, AllocateSection) { OwningPtr MemMgr( JITMemoryManager::CreateDefaultMemManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(257, 32, 3); - uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, false); - uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5); + uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, StringRef()); + uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, StringRef(), true); + uint8_t *code2 = MemMgr->allocateCodeSection(257, 32, 3, StringRef()); + uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, StringRef(), false); + uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5, StringRef()); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); diff --git a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp index 3b94d76d76bd..73976ab0f923 100644 --- a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -135,13 +135,17 @@ public: EndFunctionBodyCall(F, FunctionStart, FunctionEnd)); Base->endFunctionBody(F, FunctionStart, FunctionEnd); } - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) { - return Base->allocateDataSection(Size, Alignment, SectionID, IsReadOnly); + virtual uint8_t *allocateDataSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool IsReadOnly) { + return Base->allocateDataSection( + Size, Alignment, SectionID, SectionName, IsReadOnly); } - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { - return Base->allocateCodeSection(Size, Alignment, SectionID); + virtual uint8_t *allocateCodeSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName) { + return Base->allocateCodeSection( + Size, Alignment, SectionID, SectionName); } virtual bool finalizeMemory(std::string *ErrMsg) { return false; } virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index c434a7c0b25b..e4197ddced61 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -28,18 +28,20 @@ static bool didCallAllocateCodeSection; static uint8_t *roundTripAllocateCodeSection(void *object, uintptr_t size, unsigned alignment, - unsigned sectionID) { + unsigned sectionID, + const char *sectionName) { didCallAllocateCodeSection = true; return static_cast(object)->allocateCodeSection( - size, alignment, sectionID); + size, alignment, sectionID, sectionName); } static uint8_t *roundTripAllocateDataSection(void *object, uintptr_t size, unsigned alignment, unsigned sectionID, + const char *sectionName, LLVMBool isReadOnly) { return static_cast(object)->allocateDataSection( - size, alignment, sectionID, isReadOnly); + size, alignment, sectionID, sectionName, isReadOnly); } static LLVMBool roundTripFinalizeMemory(void *object, char **errMsg) { diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp index f6dbf984508a..c24346de84ee 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp @@ -19,10 +19,10 @@ namespace { TEST(MCJITMemoryManagerTest, BasicAllocations) { OwningPtr MemMgr(new SectionMemoryManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(256, 0, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(256, 0, 3); - uint8_t *data2 = MemMgr->allocateDataSection(256, 0, 4, false); + uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, ""); + uint8_t *data1 = MemMgr->allocateDataSection(256, 0, 2, "", true); + uint8_t *code2 = MemMgr->allocateCodeSection(256, 0, 3, ""); + uint8_t *data2 = MemMgr->allocateDataSection(256, 0, 4, "", false); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); @@ -52,10 +52,10 @@ TEST(MCJITMemoryManagerTest, BasicAllocations) { TEST(MCJITMemoryManagerTest, LargeAllocations) { OwningPtr MemMgr(new SectionMemoryManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(0x100000, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(0x100000, 0, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(0x100000, 0, 3); - uint8_t *data2 = MemMgr->allocateDataSection(0x100000, 0, 4, false); + uint8_t *code1 = MemMgr->allocateCodeSection(0x100000, 0, 1, ""); + uint8_t *data1 = MemMgr->allocateDataSection(0x100000, 0, 2, "", true); + uint8_t *code2 = MemMgr->allocateCodeSection(0x100000, 0, 3, ""); + uint8_t *data2 = MemMgr->allocateDataSection(0x100000, 0, 4, "", false); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); @@ -91,8 +91,8 @@ TEST(MCJITMemoryManagerTest, ManyAllocations) { for (unsigned i = 0; i < 10000; ++i) { const bool isReadOnly = i % 2 == 0; - code[i] = MemMgr->allocateCodeSection(32, 0, 1); - data[i] = MemMgr->allocateDataSection(32, 0, 2, isReadOnly); + code[i] = MemMgr->allocateCodeSection(32, 0, 1, ""); + data[i] = MemMgr->allocateDataSection(32, 0, 2, "", isReadOnly); for (unsigned j = 0; j < 32; j++) { code[i][j] = 1 + (i % 254); @@ -130,8 +130,8 @@ TEST(MCJITMemoryManagerTest, ManyVariedAllocations) { bool isReadOnly = i % 3 == 0; unsigned Align = 8 << (i % 4); - code[i] = MemMgr->allocateCodeSection(CodeSize, Align, i); - data[i] = MemMgr->allocateDataSection(DataSize, Align, i + 10000, + code[i] = MemMgr->allocateCodeSection(CodeSize, Align, i, ""); + data[i] = MemMgr->allocateDataSection(DataSize, Align, i + 10000, "", isReadOnly); for (unsigned j = 0; j < CodeSize; j++) {