You pretty surely asked yourself why LOADER_UNLOAD() doesn't have some meaningfull parameter...

What you copied here from my Win32 code is more or less a hack but surely not the original design. The original design is rather that _each_ shared library has a globale variable with a well know name. The loader writes whatever is necessary for unloading into that variable and the implementation of LOADER_UNLOAD() just uses the content of that variable. On Win32 I just happend to have the luck that any address inside the address space of the shared library can serve as unloading parameter. Usually one would need to explicitly define such a variable and set it on loading.

In this scenario you could have a source file linked to every shared library that just contains a void pointer definition. Then you could dlsym() the name of that void pointer in the load function and write the dl-handle into it.

I'd consider this both a more elegant and a more "following the original design" approach than the list you currently maintain.