On Linux I have some generated C++ code from a static library that defines a global variable. A single instance of this global variable is shared between two shared libraries that refer to its symbol.
When the process shuts down and the static termination phase is run, I see that the destructor on this shared instance is run twice! Presumably once per library as each unloads.
This question is closely related to another I saw recently here: related question. This sounds like the same behavior, but there is no discussion about why it is happening.
Does anybody know the theoretical explanation behind this behavior?