SDL
SDL copied to clipboard
Unify shared library loading
This isn't an ABI issue, or even a 3.2.0 thing, but I remember this every six months, so I'm writing it down:
We have a bunch of code that loads shared libraries: X11, PulseAudio, 20 other things. Several of them roll their own loaders, others have been copy/pasted from one of these.
Some are using SDL_LoadFunction, some use dlsym.
Some use CMake to find a proper SONAME for the library, some just hardcore a library name (that might be more important for extremely scattered things like Xlib than it is for libdbus, though).
It would be nice if we could unify all this into some standard way of loading functions.
It might be worth spending a few minutes to see if the reasons we're using dlsym() are reasons to change the public API.
(Having not looked) my assumption is that some places are using dlsym because they know they're on Unix and it avoids worrying about someone turning off the SDL_loadso subsystem.
You can't turn that off anymore, it's part of the core SDL functionality.
Sure, but all that internal loading code hasn't changed since SDL 1.2. :)
Most of the places using dlsym are either Android-specific (but could switch over to SDL_LoadObject), or they are looking at RTLD_DEFAULT instead of a specific library handle. If this is widely supported and we want to offer it in SDL, we can just let SDL_LoadFunction() accept a NULL handle. That wouldn't be an ABI change.
(Although we don't actually check for NULL at the moment, so technically the API already works like this on Unix.)
BTW, RTLD_DEFAULT need not be defined as NULL, it is implementation defined as far as I recall.
Most of the places using dlsym are either Android-specific (but could switch over to SDL_LoadObject), or they are looking at RTLD_DEFAULT instead of a specific library handle. If this is widely supported and we want to offer it in SDL, we can just let SDL_LoadFunction() accept a NULL handle. That wouldn't be an ABI change.
I think that's a good idea.
Adding RTLD_DEFAULT support (search all known symbols currently in the process) isn't impossible for Windows, but it isn't trivial. I'd rather not get into it at this point in the milestone if we can avoid it.
Sure, that's fine.