[cling] teardown: correctly free frontend and retained JITLink allocations - #23045
[cling] teardown: correctly free frontend and retained JITLink allocations#23045aaronj0 wants to merge 3 commits into
Conversation
d604721 to
d4b017a
Compare
|
Can you confirm root actually calls the cling interpreter destructor? |
|
|
@smuzaffar can you check this pr in cmssw? |
d4b017a to
e5bb010
Compare
|
force updated to trigger the CI which was down previously |
Test Results 21 files 21 suites 3d 7h 37m 27s ⏱️ For more details on these failures, see this check. Results for commit 7667b6f. ♻️ This comment has been updated with latest results. |
@vgvassilev , cmssw tests passed. There are few unit test failures but they are not related to this change |
Thank you, @smuzaffar! |
e5bb010 to
7667b6f
Compare
| FrontendOpts.DisableFree = true; | ||
| // The clang driver adds -disable-free to every cc1 line. | ||
| // Interpreter::ShutDown() should free the frontend. | ||
| FrontendOpts.DisableFree = false; |
There was a problem hiding this comment.
AFAICT this is mostly an optimization where, instead of freeing, the "compiler" intentionally leaks because the OS will clean up the process anyway.
| if (!m_Retained.empty()) | ||
| InProcessMemoryManager::deallocate(std::move(m_Retained), | ||
| [](Error Err) { | ||
| consumeError(std::move(Err)); | ||
| }); |
There was a problem hiding this comment.
This may still be too early, depending on which order the shutdown sequence is running and and whether something still has a pointer to one of the compiled functions...
Based on the CppInterOp cling+ASan CI job running tests that create and destroy several interpreters per process, and LSan reports two leaks there:
In JITLink, with the upgrade to LLVM22,
EHFrameRegistrationPluginnow pushes a deregistrationWrapperFunctionCallinto each allocation'sFinalizedAllocInfo::DeallocActionsvector. Our deallocate retains the code viaFinalizedAlloc::release(), which orphans that vector's heap buffer.For the frontend:
ShutDown()leaks Sema/ASTContext through the DisableFree path and hides the pointers withllvm::BuryPointe. Its fixed buffer only holds 16 pointers, so once a process destroys a few interpreters it overflows and LSan starts reporting whole frontends, normally with a single interpreter until process exit would not hit this.