Bug 30869 - Fine-tune ELF destructor ordering
Summary: Fine-tune ELF destructor ordering
Status: RESOLVED WONTFIX
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-19 06:38 UTC by Florian Weimer
Modified: 2023-10-18 14:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2023-09-19 06:38:28 UTC
The change in bug 30785 to use reverse constructor orders for destructors does not match expectations of existing applications when objects are destructed by _dl_fini.

In particular, the destructors for the main program need to run first. This may trigger additional destructor invocations if dlclose is called. After the main program, the initially loaded objects should be destroyed, potentially triggering more dlclose calls. Only after that, the remaining dlopen'ed objects should be destroyed. This way, applications have some control over destructor ordering through there dlclose calls, which seems useful.

A similar issue occurs if dlopen is called from ELF constructors: The current code schedules an object for later destruction *before* it invokes ELF constructors. This means that dlopen'ed objects from ELF constructors may be destructed first, even if the original object calling dlopen might want to close these objects by calling dlclose from its destructor.

These changes mostly apply to _dl_fini because when dlclose calls ELF destructors, explicitly dlopen'ed objects (from ELF constructors etc.) still have incremented direct-open counters, and they only become eligible for destruction if invoked ELF destructors invoke dlclose.
Comment 1 Florian Weimer 2023-09-19 11:53:32 UTC
Patches posted:

[PATCH 0/3] Fine-tune ELF destructor ordering (bug 30869)
<https://inbox.sourceware.org/libc-alpha/cover.1695113064.git.fweimer@redhat.com/>
Comment 2 Florian Weimer 2023-10-18 14:30:17 UTC
This change has been abandoned after the changes from bug 30785 have been reverted.