This is an archive of the discontinued LLVM Phabricator instance.

CommandLine: Unregister options in the destructor
AbandonedPublic

Authored by nhaehnle on Jun 20 2022, 2:29 AM.

Details

Reviewers
None
Summary

Fix a corruption issue when LLVM is used as a shared library in a plugin
setting.

Consider the case where A depends on B depends on LLVM, where B is a
shared compiler library built on LLVM that defines command-line options
(cl::opt) because it can also be used in a non-plugin setting.

If A is loaded and unloaded multiple times, causing B to be loaded and
unloaded multiple times while LLVM *isn't* unloaded, then corruption
results without this change: as B is unloaded, its cl::opt globals
disappear but the GlobalParser still holds a (dangling) reference to
them. Furthermore, if A and B are loaded a second time, the cl::opt
globals are constructed again which fails because options of the same
name are still registered.

The straightforward fix is to remove cl::opts from the GlobalParser in
the destructor.

Diff Detail

Event Timeline

nhaehnle created this revision.Jun 20 2022, 2:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 2:29 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nhaehnle requested review of this revision.Jun 20 2022, 2:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 2:29 AM
lamb-j added a subscriber: lamb-j.Jun 20 2022, 12:46 PM
simoll added a subscriber: simoll.Jun 21 2022, 3:18 AM
nhaehnle abandoned this revision.Jul 5 2022, 2:26 AM

Abandoning this in favor of a stack of changes including D129129