diff options
author | Maksim Panchenko <maks@fb.com> | 2022-09-09 18:06:13 -0700 |
---|---|---|
committer | Maksim Panchenko <maks@fb.com> | 2022-09-16 13:39:12 -0700 |
commit | 1d5393526c29312eb51ab7dbbc082d10dfd44a5b (patch) | |
tree | d1a7757e88574f92d0cd9f01544f79fa9f538579 /bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp | |
parent | 9742c25b9894d4805e05369c50cc8e0562a3cb92 (diff) | |
download | llvm-1d5393526c29312eb51ab7dbbc082d10dfd44a5b.zip llvm-1d5393526c29312eb51ab7dbbc082d10dfd44a5b.tar.gz llvm-1d5393526c29312eb51ab7dbbc082d10dfd44a5b.tar.bz2 |
[BOLT] Change base class of ExecutableFileMemoryManager
When we derive EFMM from SectionMemoryManager, it brings into EFMM extra
functionality, such as the registry of exception handling sections,
page permission management, etc. Such functionality is of no use to
llvm-bolt and can even be detrimental (see
https://github.com/llvm/llvm-project/issues/56726).
Change the base class of ExecutableFileMemoryManager to MemoryManager,
avoid registering EH sections, and skip memory finalization.
Fixes #56726
Reviewed By: yota9
Differential Revision: https://reviews.llvm.org/D133994
Diffstat (limited to 'bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp')
-rw-r--r-- | bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp index b186e80..68695d1 100644 --- a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp +++ b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp @@ -8,6 +8,7 @@ #include "bolt/Rewrite/ExecutableFileMemoryManager.h" #include "bolt/Rewrite/RewriteInstance.h" +#include "llvm/Support/MemAlloc.h" #undef DEBUG_TYPE #define DEBUG_TYPE "efmm" @@ -20,34 +21,24 @@ namespace llvm { namespace bolt { -uint8_t *ExecutableFileMemoryManager::allocateSection(intptr_t Size, - unsigned Alignment, - unsigned SectionID, - StringRef SectionName, - bool IsCode, - bool IsReadOnly) { +uint8_t *ExecutableFileMemoryManager::allocateSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool IsCode, bool IsReadOnly) { + uint8_t *Ret = static_cast<uint8_t *>(llvm::allocate_buffer(Size, Alignment)); + AllocatedSections.push_back(AllocInfo{Ret, Size, Alignment}); + // Register a debug section as a note section. if (!ObjectsLoaded && RewriteInstance::isDebugSection(SectionName)) { - uint8_t *DataCopy = new uint8_t[Size]; BinarySection &Section = - BC.registerOrUpdateNoteSection(SectionName, DataCopy, Size, Alignment); + BC.registerOrUpdateNoteSection(SectionName, Ret, Size, Alignment); Section.setSectionID(SectionID); assert(!Section.isAllocatable() && "note sections cannot be allocatable"); - return DataCopy; + return Ret; } if (!IsCode && (SectionName == ".strtab" || SectionName == ".symtab" || SectionName == "" || SectionName.startswith(".rela."))) - return SectionMemoryManager::allocateDataSection(Size, Alignment, SectionID, - SectionName, IsReadOnly); - - uint8_t *Ret; - if (IsCode) - Ret = SectionMemoryManager::allocateCodeSection(Size, Alignment, SectionID, - SectionName); - else - Ret = SectionMemoryManager::allocateDataSection(Size, Alignment, SectionID, - SectionName, IsReadOnly); + return Ret; SmallVector<char, 256> Buf; if (ObjectsLoaded > 0) { @@ -75,19 +66,16 @@ uint8_t *ExecutableFileMemoryManager::allocateSection(intptr_t Size, dbgs() << "BOLT: allocating " << (IsCode ? "code" : (IsReadOnly ? "read-only data" : "data")) << " section : " << SectionName << " with size " << Size - << ", alignment " << Alignment << " at 0x" << Ret + << ", alignment " << Alignment << " at " << Ret << ", ID = " << SectionID << "\n"); return Ret; } -bool ExecutableFileMemoryManager::finalizeMemory(std::string *ErrMsg) { - LLVM_DEBUG(dbgs() << "BOLT: finalizeMemory()\n"); - ++ObjectsLoaded; - return SectionMemoryManager::finalizeMemory(ErrMsg); +ExecutableFileMemoryManager::~ExecutableFileMemoryManager() { + for (const AllocInfo &AI : AllocatedSections) + llvm::deallocate_buffer(AI.Address, AI.Size, AI.Alignment); } -ExecutableFileMemoryManager::~ExecutableFileMemoryManager() {} - } // namespace bolt } // namespace llvm |