On Fri, May 07, 2021 at 04:41:50PM -0700, Anindya Mukherjee wrote: > On Thu, May 06, 2021 at 08:00:56AM -0600, Todd C. Miller wrote: > > On Thu, 06 May 2021 09:32:28 +0200, Sebastien Marie wrote: > > > > > We already take care of such situation with __cxa_thread_atexit_impl > > > (in libc/stdlib/thread_atexit.c), by keeping an additionnal reference > > > on object loaded (it makes ld.so aware that it is still used and so > > > dlclose() doesn't unload it). > > > > > > I used the same idiom for pthread_key_create() and used dlctl(3) in > > > the same way with the destructor address. > > > > This will set STAT_NODELETE so the DSO will never really get unloaded. > > That's not a problem for atexit() since the process is headed for > > the exit. > > > > I'm less sure about using it here since we don't have a way to > > unreference the DSO upon pthread_key_delete(). > > For sure I don't fully appreciate the complexities involved here, but is > it possible to store the shared object handle along with the destructor > when the reference count is incremented in the above patch? Then we > could use that to decrement the reference. >
It needs help from ld.so to decrement the reference and unload the DSO if the refcount is 0. It is something doable (by extending dlctl(3) command set), but it could be tricky to implement properly. I would be help full to understand why EGL is using some code path on Linux and another on OpenBSD: it would permit to use a more common/tested code path and avoid the issue at first. Thanks. -- Sebastien Marie