[PATCH] D128166: ManagedStatic: Destroy from destructor
Nicolai Hähnle via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 20 02:28:45 PDT 2022
nhaehnle created this revision.
Herald added a reviewer: deadalnix.
Herald added subscribers: bzcheeseman, ayermolo, sdasgup3, wenzhicui, wrengr, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, jvesely, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, mstorsjo, hiraditya, mgorny.
Herald added a reviewer: bollu.
Herald added a reviewer: MaskRay.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added subscribers: lldb-commits, cfe-commits, yota9, StephenFan, stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, LLDB, MLIR, LLVM.
This allows LLVM to be safely loaded and unloaded as a shared library
without leaking memory:
Consider the scenario where shared library Foo links against LLVM as
a shared library, and Foo may be loaded and unloaded multiple times
in the same process. Should Foo call llvm_shutdown or not? If it does
not, and LLVM is also loaded and unloaded multiple times, then
memory is leaked. If it does call llvm_shutdown and LLVM *isn't*
also unloaded, the state of LLVM's global statics is corrupted because
while the ManagedStatics may be re-initialized, *other* global
constructors aren't re-run.
Keep in mind that Foo itself may use ManagedStatic. If Foo is unloaded
but LLVM isn't, those statics should be destroyed.
The safe solution is to skip llvm_shutdown() altogether and destroy
managed statics from their destructor.
LLD relies on being able to call _exit() and still get some side-effects
of managed static destructors. We make this expectation much more
rG LLVM Github Monorepo
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 35267 bytes
Desc: not available
More information about the cfe-commits