Skip to content

Commit a6f2255

Browse files
hahnjojenkins
authored andcommitted
Fix lifetime of ClingMMapper
The ClingMMapper must remain available until all ClingMemoryManagers are destructed, which is typically during shutdown of IncrementalJIT. This was not the case for the global object MMapperInstance that was introduced during the upgrade to LLVM 13 because libCling variables are destructed before running TROOT atexit handlers that shut down the JIT. In practice, it happened to work but this will change with the upgrade to LLVM 18 where we see crashes in some tests, potentially because of upstream commit llvm/llvm-project@47f5c54 See also commits e0f6c04660 ("Prevent static destruction from ending DefaultMMapper too early") and 80c14bb948 ("Extend lifetime of SectionMemoryManager::DefaultMMapper, again") for the same problem that we previously patched in our copy of LLVM.
1 parent 76f5e99 commit a6f2255

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/Interpreter/IncrementalJIT.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ namespace {
7070
}
7171
};
7272

73-
ClingMMapper MMapperInstance;
74-
7573
// A memory manager for Cling that reserves memory for code and data sections
7674
// to keep them contiguous for the emission of one module. This is required
7775
// for working exception handling support since one .eh_frame section will
@@ -133,7 +131,7 @@ namespace {
133131
AllocInfo m_RWData;
134132

135133
public:
136-
ClingMemoryManager() : Super(&MMapperInstance) {}
134+
ClingMemoryManager(ClingMMapper& MMapper) : Super(&MMapper) {}
137135

138136
uint8_t* allocateCodeSection(uintptr_t Size, unsigned Alignment,
139137
unsigned SectionID,
@@ -474,7 +472,10 @@ IncrementalJIT::IncrementalJIT(
474472
return ObjLinkingLayer;
475473
}
476474

477-
auto GetMemMgr = []() { return std::make_unique<ClingMemoryManager>(); };
475+
auto MMapper = std::make_unique<ClingMMapper>();
476+
auto GetMemMgr = [MMapper = std::move(MMapper)]() {
477+
return std::make_unique<ClingMemoryManager>(*MMapper);
478+
};
478479
auto Layer =
479480
std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
480481

0 commit comments

Comments
 (0)