[llvm] 63838d8 - [examples] Fix SectionMemoryManager deconstruction error with MSVC.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 16 23:58:31 PDT 2021
Author: Lang Hames
Date: 2021-09-17T16:58:23+10:00
New Revision: 63838d88145feaeb839efff8f40ab1e98597e423
URL: https://github.com/llvm/llvm-project/commit/63838d88145feaeb839efff8f40ab1e98597e423
DIFF: https://github.com/llvm/llvm-project/commit/63838d88145feaeb839efff8f40ab1e98597e423.diff
LOG: [examples] Fix SectionMemoryManager deconstruction error with MSVC.
This commit fixes an order-of-initialization issue: If the default mmapper
object is destroyed while some global SectionMemoryManager is still using it
then calls to the mapper from ~SectionMemoryManager will fail. This issue was
causing failures when running the LLVM Kaleidoscope examples on windows.
Switching to a ManagedStatic solves the initialization order issue.
Patch by Justice Adams. Thanks Justice!
Reviewed By: lhames
Differential Revision: https://reviews.llvm.org/D107087
Added:
Modified:
llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
index 6690dd07d99b2..9a1fb31fe1603 100644
--- a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
@@ -13,6 +13,7 @@
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/Config/config.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Process.h"
@@ -264,10 +265,10 @@ class DefaultMMapper final : public SectionMemoryManager::MemoryMapper {
}
};
-DefaultMMapper DefaultMMapperInstance;
+ManagedStatic<DefaultMMapper> DefaultMMapperInstance;
} // namespace
SectionMemoryManager::SectionMemoryManager(MemoryMapper *MM)
- : MMapper(MM ? *MM : DefaultMMapperInstance) {}
+ : MMapper(MM ? *MM : *DefaultMMapperInstance) {}
} // namespace llvm
More information about the llvm-commits
mailing list