ARTICLE AD BOX
A C++ program built with GCC usually calls __cxa_finalize for each shared library in reverse order of initialization, for example at program exit, to destroy global variables and function-local statics. By supplying the __dso_handle argument, this ensures for example that function-local statics are destroyed per shared library. (This is a bit surprising, since they are only destroyed in reverse order of initialization within the same library, but not across shared libraries.)
https://elixir.bootlin.com/glibc/glibc-2.42.9000/source/stdlib/cxa_finalize.c#L44
[...] GCC calls the glibc variant directly from its CRT files, from an ELF destructor. this call always passes a non-null D argument. [...]The Itanium C++ ABI also offers the option of calling __cxa_finalize(nullptr), which cleans up all globals and function-local statics. For function-local statics, this would result in a different destruction order, since they will now be destroyed in reverse order of initialization even across shared libraries.
I'm a bit worried about the two different destruction orders. Are there any cases where __cxa_finalize(nullptr) is called in practice?
39.4k13 gold badges119 silver badges190 bronze badges
Explore related questions
See similar questions with these tags.
