Make MemoryMapper a JITRoutine member
Previously a single MemoryManager with static lifetime was shared
between all JITRoutine instances. This causes a destruction order
issue when it is destroyed at shutdown before atexit() destroys all
routines.
Note that the objectLayer member holds a reference to the memoryMapper
member, and calls it during its destruction, so the latter must be
declared first to be destroyed last.
Bug: b/216348016
Change-Id: Icd85e2687c652f45d78b9d48ed481c020e9cb6f3
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61812
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/LLVMJIT.cpp b/src/Reactor/LLVMJIT.cpp
index fb22cfe..11ca7e4 100644
--- a/src/Reactor/LLVMJIT.cpp
+++ b/src/Reactor/LLVMJIT.cpp
@@ -704,8 +704,7 @@
#if LLVM_VERSION_MAJOR >= 13
, session(std::move(*llvm::orc::SelfExecutorProcessControl::Create()))
#endif
- , objectLayer(session, []() {
- static MemoryMapper memoryMapper;
+ , objectLayer(session, [this]() {
return std::make_unique<llvm::SectionMemoryManager>(&memoryMapper);
})
, addresses(count)
@@ -810,6 +809,7 @@
private:
std::string name;
llvm::orc::ExecutionSession session;
+ MemoryMapper memoryMapper;
llvm::orc::RTDyldObjectLinkingLayer objectLayer;
std::vector<const void *> addresses;
};