This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
ELF destructor order vs constructor order
- From: Florian Weimer <fweimer at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 18 Oct 2019 14:10:24 +0200
- Subject: ELF destructor order vs constructor order
Suppose that the constructors for object A run before the constructors
for object B. (For the following, it does not matter how A and B were
loaded.)
Should it be possible that as the result of a dlclose call (or process
termination), the destructors for A also run before the destructors for
B? Or should the destructors always run in the reverse order of
construction (assuming they happen during the same dlclose call)?
I think the answer should be that the reverse order is used.
We have a downstream report where a developer points out that they
perceive the destructor order more or less as random (in #1133521,
unfortunately not a public bug). The reason is that the C++ compiler
tends to vary its emitted symbols with optimization settings and code
changes, and the dependencies recorded during lazy binding currently end
up changing the destructor order.
I think we should disregard the dynamic dependency information and
always perform the destructor calls in reverse order of the constructor
calls (for the objects that are about to be unloaded).
Comments?
Thanks,
Florian