[PATCH] D97780: Control lifetime of SectionMemoryManager's DefaultMMapper

Axel Naumann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 2 09:55:59 PST 2021


karies created this revision.
karies added a reviewer: lhames.
karies added a project: LLVM.
Herald added a subscriber: hiraditya.
karies requested review of this revision.
Herald added a subscriber: llvm-commits.

As the `DefaultMMapper` object is a namespace-level variable, its destruction happens unsynchronized with uses. `~SectionMemoryManager()` needs `MMapper` which might have been destructed before the call to `~SectionMemoryManager()` in cases where `~SectionMemoryManager()` is triggered by some other static destruction.

To sort this out, make the DefaultMMapper object function-local. That way its construction happens before the first use (which might be static initialization), and its destruction is sequenced after that use's static destruction. This allows the use of the default `SectionMemoryManager` by objects with static storage duration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97780

Files:
  llvm/lib/ExecutionEngine/SectionMemoryManager.cpp


Index: llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
===================================================================
--- llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
+++ llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
@@ -264,10 +264,13 @@
   }
 };
 
-DefaultMMapper DefaultMMapperInstance;
+DefaultMMapper &getDefaultMMapperInstance() {
+  static DefaultMMapper Mapper;
+  return Mapper;
+};
 } // namespace
 
 SectionMemoryManager::SectionMemoryManager(MemoryMapper *MM)
-    : MMapper(MM ? *MM : DefaultMMapperInstance) {}
+    : MMapper(MM ? *MM : getDefaultMMapperInstance()) {}
 
 } // namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97780.327492.patch
Type: text/x-patch
Size: 622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210302/0a39b672/attachment.bin>


More information about the llvm-commits mailing list