This patch builds on top of D8428. The idea behind this change is to separate full initialization and LLGS initialization more strongly. Because InitializeForLLGS is in the same source file (or even the same library) as Initialize(), the linker has to deal with all these extra symbols, increasing binary size. In theory it can do dead code elimination, but it doesn't always do an optimal job (as the numbers later on show). Furthermore, there is some duplicated logic with regards to checking the ref count, and making sure Debugger::Initialize() and Debugger::Terminate is called in the correct order.
This patch addresses all of these issues by introducing a class called SystemLifetimeManager which *only* deals with the interaction between the ref count, calling Debugger::Initialize / Terminate, and actually shutting down the complete set of system services. In particular, it does *not* deal with the implementation details of what system services to initialize and shutdown.
This is accomplished by introducing an abstract base class called SystemInitializer with Initialize() and Terminate() methods. A standard implementation called SystemInitializerCommon is provided in the Initialization library. The functionality contained in here is identical to the functionality which used to be in InitializeForLLGS() and TerminateLLGS().
The full initialization implemetantion is now compiled directly into source/API via source/API/SystemInitializerFull.cpp, which provides an implementation built on top of SystemInitializerCommon (this is equivalent to the functionality that used to be in lldb_private::Initialize() / lldb_private::Terminate()
This all seems rather complicated, but using this approach the binary size of llgs is reduced quite a bit. Here are some numbers:
Before Patch:
Debug 738,065,786 bytes Release 27,333,622 bytes MinSizeRel 21,818,230 bytes MinSizeRel with stripped symbols 16,364,008 bytes
After Patch:
Debug 475,575,879 bytes Release 24,120,433 bytes MinSizeRel 19,034,215 bytes MinSizeRel with stripped symbols 14,395,872 bytes
So I'm seeing an improvement of about 12% for a fully minimized binary.
Note I haven't updated the Xcode project yet. I will do that now, but I wanted to put this up first for the high level idea.
Please put this in a static function and call the singleton and have it return a reference. The Apple build system prohibits frameworks from having global initializers.
So make this: