[PATCH v3] dlfcn: Fix dlclose crash in atexit handler after thread_local destructor (BZ 33598)

Florian Weimer fw@deneb.enyo.de
Tue May 5 21:35:42 GMT 2026


* Adhemerval Zanella Netto:

> However, analyzing this a bit more I am not sure. With DL_UNMAP the
> link map is still removed from the namespace, but the pages remain
> mapped and the DSO is gone from GL(dl_ns[nsid]._ns_loaded),
> _dl_loaded_lock, and l_initfini chains. This creates an inconsistent
> state where:
>
> * This approach guarantees that _dl_fini runs all fini/fini_array
> callbacks in a single topologically-sorted pass, where DL_UNMAP
> _dl_close_worker's _dl_call_fini may run destructors for a library
> during exit, and then _dl_fini may encounter it again (or not, if
> the link map was removed).

I'm not sure the explanation in the commit message that this prevents
unmapping only is correct.  I think it does alter destructor ordering
in some cases.

We likely have applications that depend on dlclose actually running
destructors during exit.  These regressions would only concern
application exit, so hopefully they are not critical, but the change
still seems rather invasive.  My past attempts to tweak the
destruction order have surfaced lots of issues, so I think we should
avoid that if we can.

I need to think more about this.  Maybe I'm misunderstanding the
nature of this bug.


More information about the Libc-alpha mailing list